[zeromq-dev] hitting file descriptor using gevent
Chuck Remes
cremes.devlist at mac.com
Sun Jul 10 16:35:35 CEST 2011
On Jul 10, 2011, at 8:59 AM, Tim Cooijmans wrote:
> I boiled it down to this simulation:
> Front-end-server:
> def sendmessage(i):
> # Get context
> context = zmq.Context()
> socket = context.socket(zmq.REQ)
> socket.connect("tcp://127.0.0.1:5000")
>
> # Send message
> socket.send(str(i))
> print("Send: " + str(i))
>
> # Wait for confirmation
> socket.recv()
> print("OK: " + str(i))
>
> all = []
> for i in range(10):
> thread = gevent.spawn(sendmessage, i)
> all.append(thread)
> gevent.joinall(all)
Are you creating a new context and socket every time you send a message? If so, that's a major flaw.
My suggestion is to create only a single context (it's *extremely* rare that you need more than one) and use it to pre-allocate each socket as you spawn each thread.
e.g.
def sendmessage(socket, i):
# blah
context = zmq.Context()
for i in range(1):
socket = context.socket(zmq.REQ)
socket.connect("tcp://127.0.0.1:5000")
thread = gevent.spawn(sendmessage, socket, i)
all.append(thread)
> Which works fine as long as there are less like 70 clients. Above this the
> "frontend-server" is hitting the file descriptor limit. A possible solution
> is to push the file descriptor limit up but this doesn't seem like the right
> thing to do to me.
> What is the best way to achieve my goals? Should I abandon the REQ-XREP
> architecture?
Hitting the limit after 70 clients seems rather early. You probably need to provide a gist of *all* of the code because there might be something else going on here. Your snippet is too short to figure out the issue.
cr
More information about the zeromq-dev
mailing list