How many connections can accept a 'binded' socket?

Discussion in 'Python' started by billiejoex, Mar 20, 2007.

  1. billiejoex

    billiejoex Guest

    Hi,
    I'm writing a small asyncore-based server application serving a lot of
    clients. When I have to handle more than 1021 client simoultaneously
    the 'binded' socket object raises an error:

    [...]
    connections: 1018
    connections: 1019
    connections: 1020
    connections: 1021
    Traceback (most recent call last):
    File "asyncore_client.py", line 31, in <module>
    File "asyncore.py", line 191, in loop
    File "asyncore.py", line 138, in poll
    File "asyncore.py", line 80, in write
    File "asyncore.py", line 76, in write
    File "asyncore.py", line 395, in handle_write_event
    File "asyncore_client.py", line 24, in handle_connect
    File "asyncore_client.py", line 9, in __init__
    File "asyncore.py", line 257, in create_socket
    File "socket.py", line 156, in __init__
    socket.error: (24, 'Too many open files')

    I just wanna know: is there a way to know how many connections can
    accept a 'binded' socket BEFORE getting such error? Maybe
    socket.SOMAXCONN could help me?

    Thanks in advance.
     
    billiejoex, Mar 20, 2007
    #1
    1. Advertising

  2. billiejoex a écrit :
    > Hi,
    > I'm writing a small asyncore-based server application serving a lot of
    > clients. When I have to handle more than 1021 client simoultaneously
    > the 'binded' socket object raises an error:
    >
    > [...]
    > connections: 1018
    > connections: 1019
    > connections: 1020
    > connections: 1021
    > Traceback (most recent call last):
    > File "asyncore_client.py", line 31, in <module>
    > File "asyncore.py", line 191, in loop
    > File "asyncore.py", line 138, in poll
    > File "asyncore.py", line 80, in write
    > File "asyncore.py", line 76, in write
    > File "asyncore.py", line 395, in handle_write_event
    > File "asyncore_client.py", line 24, in handle_connect
    > File "asyncore_client.py", line 9, in __init__
    > File "asyncore.py", line 257, in create_socket
    > File "socket.py", line 156, in __init__
    > socket.error: (24, 'Too many open files')
    >
    > I just wanna know: is there a way to know how many connections can
    > accept a 'binded' socket BEFORE getting such error? Maybe
    > socket.SOMAXCONN could help me?


    Here you get out of file descriptors, I dont think SOMAXCONN would help.

    Under Linux (maybe Unix), there is ulimit -n nnn to setup the maximum
    number of files descriptors. I don't know its upper limit (maybe a
    kernel compile time information).
     
    Laurent Pointal, Mar 20, 2007
    #2
    1. Advertising

  3. Laurent Pointal <> wrote:

    > billiejoex a écrit :
    > > Hi,
    > > I'm writing a small asyncore-based server application serving a lot of
    > > clients. When I have to handle more than 1021 client simoultaneously
    > > the 'binded' socket object raises an error:
    > >
    > > [...]
    > > connections: 1018
    > > connections: 1019
    > > connections: 1020
    > > connections: 1021
    > > Traceback (most recent call last):
    > > File "asyncore_client.py", line 31, in <module>
    > > File "asyncore.py", line 191, in loop
    > > File "asyncore.py", line 138, in poll
    > > File "asyncore.py", line 80, in write
    > > File "asyncore.py", line 76, in write
    > > File "asyncore.py", line 395, in handle_write_event
    > > File "asyncore_client.py", line 24, in handle_connect
    > > File "asyncore_client.py", line 9, in __init__
    > > File "asyncore.py", line 257, in create_socket
    > > File "socket.py", line 156, in __init__
    > > socket.error: (24, 'Too many open files')
    > >
    > > I just wanna know: is there a way to know how many connections can
    > > accept a 'binded' socket BEFORE getting such error? Maybe
    > > socket.SOMAXCONN could help me?

    >
    > Here you get out of file descriptors, I dont think SOMAXCONN would help.
    >
    > Under Linux (maybe Unix), there is ulimit -n nnn to setup the maximum
    > number of files descriptors. I don't know its upper limit (maybe a
    > kernel compile time information).


    A shell command

    ulimit -Hn

    should report on the hard-limit of the number of open file descriptors;
    just ulimit -n should report on the current soft-limit.

    If you're going to pass the fd's to select, as asyncore does by default,
    a separate limit of 1024 is unfortunately likely to apply anyway; so,
    once that ulimit is raised, you may want to pass argument use_poll as
    true to asyncore.loop. The performance of poll with a huge number of
    sockets may however not be all that shiny. Better mechanisms, such as
    epoll or kqueue, I believe, are not available for asyncore, even if your
    OS supports them; to serve thousands of open sockets with good
    performance, you may need to switch to Twisted (which offers many more
    implementations of the abstract Reactor interface -- you don't _have_ to
    use Twisted's higher layers if you don't want to).


    Alex
     
    Alex Martelli, Mar 20, 2007
    #3
  4. billiejoex

    John Nagle Guest

    billiejoex wrote:
    > Hi,
    > I'm writing a small asyncore-based server application serving a lot of
    > clients. When I have to handle more than 1021 client simoultaneously
    > the 'binded' socket object raises an error:


    When you ask questions like this, please specify what
    operating system you're using. Thanks.

    John Nagle
     
    John Nagle, Mar 20, 2007
    #4
  5. billiejoex

    billiejoex Guest

    On 20 Mar, 17:44, John Nagle <> wrote:
    > When you ask questions like this, please specify what
    > operating system you're using. Thanks.


    That was a Linux Ubuntu 6.10. I submitted a bug report on sourceforge:
    http://sourceforge.net/tracker/index.php?func=detail&aid=1685000&group_id=5470&atid=105470


    Alex Martelli wrote:
    > A shell command
    > ulimit -Hn
    > should report on the hard-limit of the number of open file descriptors;
    > just ulimit -n should report on the current soft-limit.


    Thank you, I'll try it.
     
    billiejoex, Mar 21, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eli Sidwell
    Replies:
    7
    Views:
    2,730
    Gavin Williams
    Jun 24, 2004
  2. Replies:
    2
    Views:
    6,356
  3. Can styles be binded to a datasource?

    , Feb 1, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    115
  4. Lee Skillen
    Replies:
    1
    Views:
    205
  5. Eli Sidwell
    Replies:
    1
    Views:
    132
    John Bokma
    Jun 10, 2004
Loading...

Share This Page