Ravindra Josyula
Ravindra Josyula

Reputation: 121

ZeroMQ and Multithreading

ZeroMQ Guide has good example of using ZeroMQ for inprocess multithreading (inproc transport). However, the example shows a trivial message payload which is a string. Thus the cost of serilization and de-serilization is small.

However, take an example of a large business domain object. This domain object can be serilized to its XML representation. So how can ZeroMQ be performant for multithreading if for communicating with each thread means that the domin object has to be serilized in one thread, sent to inproc worker thread, to be de-serilized and act upon the message payload. Won't the cost of serilization and de-serilization negate any performance gains of message passing?

I understand the benefit of this construct, since it is possible to scale across cpu's, across nodes, across networks, etc in future. But i am confused on the whole "multithreading using ZeroMQ" concept.

Another method can be to have the domain objects stored in cache and just pass the identity to the worker threads, which will fetch the actual domain object from the cache. Is this what is intended?

Any use case or best pratices would be welcome.

Upvotes: 4

Views: 758

Answers (1)

Trevor Bernard
Trevor Bernard

Reputation: 992

ØMQ is great at moving data around both in and out of process, but not for marshalling data to/from binary representation.

Won't the cost of serilization and de-serilization negate any performance gains of message passing?

Effectively with message passing, you've turned a synchronous process into a parallel one. The key benefit isn't the speed at which you can transfer messages but that you are now doing work in parallel.

Upvotes: 2

Related Questions