[plt-scheme] How many sockets can be open?

From: Erich Rast (erich at snafu.de)
Date: Mon Jul 23 04:41:00 EDT 2007


My custom client-server protocol now works as it should, but only for  
around up to 110 open socket connections. If I connect more clients  
to on the same machine, DrScheme goes havoc. More  
specifically, at 118 connections it complains the following when  
trying to save the source file while the connections are open:

open-output-file: cannot open output file: "/Users/privat/SOL/ 
Schemebox/transmitter-test.scm" (Too many open files; errno=24)

  === context ===
/Applications/PLT Scheme v370.6/collects/framework/private/frame.ss: 
1187:12: file-menu:save-callback method in ...ork/private/frame.ss: 
/Applications/PLT Scheme v370.6/collects/mred/private/wxmenu.ss:55:23
/Applications/PLT Scheme v370.6/collects/mred/private/mrtop.ss: 
155:27: on-subwindow-char method in frame%

At 120 simultaneously open connections, the garbage collector starts  
to shuffle practically without stopping and DrScheme becomes and  
remains more or less unresponsible. In pure MZScheme, basically the  
same happens. The GC just doesn't seem to stop.

In OS X activity monitor (a GUI for ps), DrScheme shows 99-100% CPU  
load but only around 160MB physical memory and 550MB virtual memory.  
My machine has 2GB memory and I don't have other applications open.  
Fortunately, my Mac has two cores, so it doesn't lock up.

Here is what my implementation does: It starts a server using run- 
server to listen on port 8712, each client connects to Clients and server use the built-in reader and start  
a listen-loop on the input port, using read to block the thread. Open  
input and output ports are stored in a data structure by the server.  
In my test, each client sends one command and receives one reply,  
which it ignores:

  (define (test-load)
     (let loop ((i 120)
                (client (make-transmitter "some client" ""  
8712 'tcp))
                (connections '()))
       (let ((c (transmitter-connect client)))
         (connection-send c (make-command 'rand) (lambda (n) (void)))
         (if (> i 0)
           (loop (- i 1) (make-transmitter "some client" ""  
8712 'tcp) (cons c connections))

Works fine for i=100, not at all for i=120. Sometimes under this load  
client or server also receive illegal input, sometimes connections  
time out with errno=60. Even when (test-load) is finished, the GC  
stays active and DrScheme remains unresponsive. In summary, it looks  
very much like a low memory condition, but DrScheme should have much  
more memory available and the virtual memory doesn't start to shuffle.

Around 100 maximum simultaneous connections seems to be a rather low  
number. Does anyone have an idea what may cause this? Is it the  
threads, the readers, or the socket connections themselves? Is it an  
OS issue?

Mac OS X 10.4.10, 2GB RAM, dual core iMac / DrScheme 370.6- 
svn17jul2007 [3m]

Best regards,


Posted on the users mailing list.