Pieter, I have two use cases: 1) short-living threads within my application (under 10 milliseconds) 2) threads that are initiated and managed by an outside application which calls my code. My code is executed also in a few milliseconds timeframe
in either case the I have a few msec to connect and publish a message. If when I tried to open a socket within those few milliseconds, JeroMQ crashed with the following stack trace after ~90,000 calls. Exception in thread "Transaction1461542403" *zmq.ZError$IOException*:* java.io.IOException*: Unable to establish loopback connection Tue Aug 13 13:45:13 PDT 2013 at zmq.Signaler.make_fdpair(* Signaler.java:87*) Tue Aug 13 13:45:13 PDT 2013 at zmq.Signaler.<init>(*Signaler.java:48*) Tue Aug 13 13:45:13 PDT 2013 at zmq.Mailbox.<init>(*Mailbox.java:55*) Tue Aug 13 13:45:13 PDT 2013 at zmq.SocketBase.<init>(* SocketBase.java:92*) Tue Aug 13 13:45:13 PDT 2013 at zmq.XPub.<init>(*XPub.java:89*) Tue Aug 13 13:45:13 PDT 2013 at zmq.Pub.<init>(*Pub.java:35*) Tue Aug 13 13:45:13 PDT 2013 at zmq.SocketBase.create(* SocketBase.java:119*) Tue Aug 13 13:45:13 PDT 2013 at zmq.Ctx.create_socket(*Ctx.java:304*) Tue Aug 13 13:45:13 PDT 2013 at org.jeromq.ZMQ$Socket.<init>(* ZMQ.java:238*) Tue Aug 13 13:45:13 PDT 2013 at org.jeromq.ZMQ$Context.socket(* ZMQ.java:193*) ..... ..... At the moment I solved the problem by implementing a connection pool with a number of connected sockets. Once my code needs to publish a message, I grab one socket from the pool, publish and return the socket back to the pool. So far it seems to be working well, but I'm not sure whether it is the correct and best approach or not. Thx > Hi Michael. > 1. How long is "short-lived"? > 2. Are you saying JeroMQ is crashing when you do this? > -Pieter > On Wed, Aug 14, 2013 at 5:23 PM, Michael Keselman <[email protected]> wrote: > According to the Guide, sockets are not threadsafe and shouldn't be shared > among threads. My application creates multiple short-living threads and > needs to publishing messages from each one. My novice approach was to have a > shared context and create a new socket in each thread. What is a recommended > design for such environment? > > Thx > > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev >
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
