tags:

views:

261

answers:

4

The typical socket code for Perl goes like this:

bind(Server, sockaddr_in($port, INADDR_ANY))    || die "bind: $!";
listen(Server,SOMAXCONN)       || die "listen: $!";

As described in this page the actual maximum allowed is somewhere around 5. That's way too low! I'm using a unix domain file socket and expecting very high throughput. Is there any way to increase the maximum queue length?

+1  A: 

CentOS linux and MAC OS X report the limit as being 128. These limits work for high throughput web servers etc. therefore you should be OK. You just need use something like IO::Poll to monitor the sockets you have data on, and the socket that you are listening on.

Beano
+2  A: 

From the document you give, it sounds like the limitation is not Perl's but instead the operating system. That said, have you tried tweaking it and setting it higher than 5? The publication you link to was written in 1996 - a lot has changed in Perl and operating systems since then.

Also, you may want to look into IO::Socket (and IO::Socket::UNIX) if you want a more object-oriented interface to Perl sockets.

Chris Simmons
+2  A: 

The queue is the number of outstanding non-accept()ed connections. Are you sure you will have a large number of pending connections? That's not the number of active or in-use connections. Presumably you are passing off accepted connections as quickly as possible to a worker and not handling them in your accepting loop.

Your accept() handler should be a very short operation that takes a new connection and passes it to your connection handler(s). It then goes back and tries to accept() more connections. You only need a queue deep enough to accommodate the time it takes to go though this loop.

caskey
+2  A: 

Perl's Socket module makes available the constants from your platform's socket.h, so Perl will let you specify as deep a backlog as, say, a C program could. Consider:

$ perl -MSocket -le 'print SOMAXCONN'
128
Greg Bacon