Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a sane architecture for a multi-user network server? (How much overhead does pipes-concurrency introduce?) [closed]

I currently have it so that there is one thread handling the accept loop, one main thread for doing all the stateful logic stuff, and then 2 threads per connected client. One client thread is handling the input pipeline and using pipes-concurrency to send messages to the main logic thread. The other client thread is handling the output pipeline, getting messages from the main logic thread and sending them to the client.

My reasoning for doing it this way is that the main logic thread can use worker threads to do pure computations on an immutable state, then do all the state changes at once and loop back around with the new state. That way I can make use of multiple CPUs without having to worry about the problems of concurrent state modifications.

Is the overhead of STM/pipes-concurrency small enough that this is a reasonable approach when I will end up with a couple thousand connected clients sending two or three messages per second each?

like image 329
user3261399 Avatar asked Feb 11 '14 01:02

user3261399


1 Answers

Haskell green threads are cheap enough that I would definitely recommend the approach of 2 threads per client. Without seeing details, I can't comment on whether STM will be a bottleneck or not, but that's going to depend on your implementation. STM can definitely handle that level of workload, assuming it's used correctly.

like image 82
Michael Snoyman Avatar answered Oct 15 '22 22:10

Michael Snoyman