by DanWaterworth · 13y ago · 0 comments
Haskell programs are generally thread-safe by construction. It's very easy to overlook thread-safety in foreign libraries, but this isn't just a problem in Haskell, multi-threaded code is the default is a number of realms.
I now try to avoid ZMQ where I can. Modern libraries should be thread-safe.
It's still young, but it grew out of some frustrations with using ZeroMQ in large-scale deployments.
You might argue that in this case having two sockets, a PUSH and a PULL might have been better, but the nature of the communication was very much between two processes and I didn't want to weaken that.
Coordination can be expensive and certainly, actors or some sort of channel-based model (which is my preference), have their place, but when you have light-weight communication and coordination primitives, it's not a given.
That would force me into an asynchronous style, but in my case, I was able to convey intent much better using threads.
And 0mq is for inter-process communication. While you are running a server with many threads in one process, you usually don't need it.
Since you have Haskell and Actors, but worrying thread-safety of some other libraries. You can consider a single-threaded/multi-process deploy.
By setting the thread pool to 1, Actors in a single process can still handle tens of thousands of concurrent connections, while there is surely no thread-safety problem.