[zeromq-dev] Controlling thread affinity in a DEALER socket

Andy Ballingall TF ballingall at thefoundry.co.uk
Fri Dec 21 11:40:37 CET 2012


> How you dole out requests to threads depends on your needs. In my case I pass the message frames to the thread pool in a task object and handle the addressing issues in the code, so the inproc socket is only used for sending the response back. I suppose you could use the inproc socket to send the message to the worker thread, but I don't see how that could work with a thread pool since the thread that gets sent a message could already be processing another task.

On the subject of worker threads, the zmq guide actually has a very
elegant example of a router which only delivers work to worker threads
which are free, and it would be straightforward to modify this pattern
to deal with a number of clusters of workers, each cluster of which
does a specific type of request.

http://zguide.zeromq.org/page:all#A-Load-Balancing-Message-Broker

It takes a while to get your head around the zmq message envelope
manipulations that are going on, but well worth spending the time to
get your head around it. I've used this as the basis of a
load-balanced mechanism with a load of back-end workers and it works
very well.

Andy

>
> Peter
>
>
> -----Original Message-----
> From: zeromq-dev-bounces at lists.zeromq.org [mailto:zeromq-dev-bounces at lists.zeromq.org] On Behalf Of Brad Taylor
> Sent: Thursday, December 20, 2012 3:22 PM
> To: ZeroMQ development list
> Subject: [zeromq-dev] Controlling thread affinity in a DEALER socket
>
> In reviewing the guide, the multi-threaded patterns uses a proxy that has a DEALER socket for dealing the message to a worker.  We have a requirement to handle particular messages to particular threads.  That is the message can only be handled by a given thread.  Is there a simple pattern or technique, that would let us decide which backend socket to "deal" the message to?
>
> In the bigger picture we want a multi threaded server, that listens on a single port.  There will be n-number of worker threads, where each worker thread can service requests for a given resource.  The resource is identifiable as part of the message.  We want to use the overall request-reply pattern.  That is the client issues a request, the server receives the message and passes the request to a specific worker thread, based upon message content.  The worker thread does the work and sends a reply to the client.  Thus we get parallelism in carrying out the work.  We have looke at some of the patterns.  However the "sockets are not thread-safe" statement worries us.
>
> Any thoughts or guidance would be appreciated.
>
> Thank  you
>
> Brad Taylor
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev



--
Andy Ballingall
Senior Software Engineer

The Foundry
6th Floor, The Communications Building,
48, Leicester Square,
London, WC2H 7LT, UK
Tel: +44 (0)20 7968 6828 - Fax: +44 (0)20 7930 8906
Web: http://www.thefoundry.co.uk/

The Foundry Visionmongers Ltd.
Registered in England and Wales No: 4642027



More information about the zeromq-dev mailing list