[zeromq-dev] Socket usage question

Matt Haberman mhaberman at msmnet.com
Wed Aug 24 16:09:41 CEST 2011


So I am assuming that in general, the best practice for communicating with 0MQ via a multi-threaded application is to maintain a fixed number of sockets (perhaps equal to the CPU core count) instead of creating a socket for each thread? I am trying to maximize throughput.



Thanks,

Matt





1000 iterations creating and destroying 1000 sockets? Use Environment.ProcessorCount in your loop and send msgcount\ Environment.ProcessorCount messages in each task.



Alternatively you can use TPL Parallel.For.



To simulate load use the cloud. I had 5 clients sending to 1 server at 269K messages per second with the CPU  never exceeding 30% the network card was saturated though.



Even on my I7 laptop to my mac book I get excellent through put.



Currently you have thread context switching issues. You can verify this using performance counters if they will even load which I doubt.



Gary Davidson | Chief Software Architect | interclick



Gary.Davidson at interclick.com<http://lists.zeromq.org/mailman/listinfo/zeromq-dev>

P 561 300 2764  |  C 954 790 0715  |  F 561 300 2765

4800 T-Rex Avenue Suite 120 Boca Raton, FL 33431

www.interclick.com    NASDAQ: ICLK



-----Original Message-----

From: zeromq-dev-bounces at lists.zeromq.org<http://lists.zeromq.org/mailman/listinfo/zeromq-dev> [mailto:zeromq-dev-bounces at lists.zeromq.org<http://lists.zeromq.org/mailman/listinfo/zeromq-dev>] On Behalf Of Matt Haberman

Sent: Tuesday, August 23, 2011 10:10 PM

To: zeromq-dev at lists.zeromq.org<http://lists.zeromq.org/mailman/listinfo/zeromq-dev>

Subject: [zeromq-dev] Socket usage question



I am trying simulate load on a process created with 0MQ (CLZMQ2 binding) and have a question about when to create sockets. My application is listening for requests using an XREP socket. I wrote a little console app to simulate concurrent clients that looks like:



public class Client

{

    Context context;



    public Client()

    {

        context = new Context(1);

    }

    public void SendRequest()

    {

        for (int i = 1; i <= 1000; i++)

        {

            Task t = new Task(

                () =>

                {

                    Socket r = context.Socket(SocketType.REQ);



                    r.Connect("tcp://localhost:5559"<tcp://localhost:5559%22>);

                    r.Send("Hello", Encoding.Unicode);

                    string reply = r.Recv(Encoding.Unicode);

                    Console.WriteLine("Received reply {0}", reply);

                    r.Dispose();

                }

            );

            t.Start();

            Thread.Sleep(100);

        }

    }

}

Frequently, when i run the console app my entire machine freezes and is unresponsive. Is there something wrong with this approach?



Thanks,

Matt

_______________________________________________

zeromq-dev mailing list

zeromq-dev at lists.zeromq.org<http://lists.zeromq.org/mailman/listinfo/zeromq-dev>

http://lists.zeromq.org/mailman/listinfo/zeromq-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110824/2c0fb690/attachment.htm>


More information about the zeromq-dev mailing list