Thread: Poll

  1. #1
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034

    Smile Poll

    Hey, so on Windows XP the concurrent socket limit is 1024? Seems kind of low, but that's because Windows XP only has access to select() right? Whereas Windows Vista has WSAPoll(), which is just a copy of Unix poll(). I've ran more than 10000 sockets using Unix poll().

    Using Boost::Asio I get this error after 20 minutes, about 1000 sockets:

    The descriptor does not fit into the select call's fd_set
    Afterwhich I start getting this error:

    An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full
    I was thinking maybe I could run Linux in virtual box from within Windows, but would it truly be Linux, or is it just redirecting to Windows API/SDK? It will probably still be using Winsock select() in the background instead of Linux poll()?

    Thanks for any information,
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    wa wa waaaaa?

    I don't know about your system but my system lets me open 230k+ sockets, the limit you speak of is in Boost, not XP.
    Last edited by abachler; 08-11-2009 at 06:19 PM.

  3. #3
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by abachler View Post
    wa wa waaaaa?

    I don't know about your system but my system lets me open 230k+ sockets, the limit you speak of is in Boost, not XP.
    230k concurrent sockets? As in.. 230,000 open sockets at the same time? Wouldn't that be amazing. Especially since I believe the max ports is 65k, and each tcp/ip socket uses its own port.

    Even if the limit in XP probably isn't 1024, I'd love to know how you get around fd_set, in Boost or otherwise.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by abachler View Post
    wa wa waaaaa?

    I don't know about your system but my system lets me open 230k+ sockets, the limit you speak of is in Boost, not XP.
    Did you read his original post? Especially:
    about 1000 sockets:

    Quote:
    The descriptor does not fit into the select call's fd_set
    1) Something is going wrong with fd_set
    2) Around 1000 sockets. I'm betting it's at 1024 sockets. Nice, round number.

    Now, the first barrier with select() is that there's a limit of 64 sockets, at least so says the winsock.h header. Many people say you can raise that limit merely by defining FD_SETSIZE at your will, before including the header, with no adverse side effects. This is what I suspect boost is doing.

    After looking at the source files, close, but not quite. Dae, you want to look at boost/asio/detail/win_fd_set_adapter.hpp, you should see the following line:
    Code:
    enum { win_fd_set_size = 1024 };
    (Hmm... 1024. ;-) )
    Anywho, there's a class in there that essentially creates a fd_set with a limit of 1024, but does it without redefining FD_SETSIZE. (Slightly slick, I might add.)

    Anywho, as of boost's implementation, it looks like you're limited to 1024 SOCKETs. You might be able to get around this with threading, & could probably even re-integrate that with boost. (And if you do, consider sending it boost's way...)

    Especially since I believe the max ports is 65k, and each tcp/ip socket uses its own port.
    Yes, but a TCP socket is made unique by the key of (source_ip, source_port, dest_ip, dest_port), so you should be able to get well above 65k sockets, memory/system allowing.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Dae View Post
    230k concurrent sockets? As in.. 230,000 open sockets at the same time? Wouldn't that be amazing. Especially since I believe the max ports is 65k, and each tcp/ip socket uses its own port.
    This is wrong in more than one way.

    1. The source port of an outgoing connection need not be unique. It merely need be unique to the level of other connections to the same destination IP and port. So two outgoing connections can both originate from the same port as long as they are connecting to different destinations. (In practice, the network stack will try to assign unique ports to each outgoing connection, but if it runs out that doesn't mean it can't create more connections).

    2. For a listening socket, the port is clearly always the same for each connection. Every client who connects to a web server connects to it on port 80, for instance.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Thanks for the information Cactus_Hugger & brewbuck.

    Granted I've read even the best servers money can buy become unstable after 20k-50k+ clients. I think I can handle 1k-5k on personal computer and 10k-20k on dedicated server.

    I wanted to dev it for Linux but prefer XP. VirtualBox will just send socket requests (from poll()) back to Winsock correct? I figure that's how it works, but who knows. So I'd have to boot Linux normally? Which I could do on a secondary computer or via network, but it's less preferable.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  7. #7
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by Dae View Post
    230k concurrent sockets? As in.. 230,000 open sockets at the same time? Wouldn't that be amazing. Especially since I believe the max ports is 65k, and each tcp/ip socket uses its own port.
    except you forget that you can open multiple incoming sockets for the same port, which is generally what a SERVER does. Why, other than poor design, would the client open even more than 2? And as i stated the 1024 is a limit of Boost, not XP.

    Even if the limit in XP probably isn't 1024, I'd love to know how you get around fd_set, in Boost or otherwise.
    I guess my IDE has magical text editing abilities that are beyond those of your IDE.

    Code:
    //  WinSock.h
    
    #ifndef FD_SETSIZE
    #define FD_SETSIZE      262144
    #endif /* FD_SETSIZE */
    or for the faint of heart who dont like makign permanent changes to default headers, -

    Code:
    #define FD_SETSIZE      262144
    #include <windows.h>
    since winsock.h is included by windows.h

    Granted I've read even the best servers money can buy become unstable after 20k-50k+ clients. I think I can handle 1k-5k on personal computer and 10k-20k on dedicated server.
    That sounds more like a bandwidth capacity issue than a limitation of the software; assuming you have the entire network at your disposal, even a gigabit eithernet will saturate at around 20k connections that are using 5Kbytes/s (50Kbps).
    Last edited by abachler; 08-12-2009 at 01:43 AM.

  8. #8
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    I understand what you're saying, thanks abachler. I ran across that macro after my reply. It seems to work, even when there's warnings it may cause undefined behavior. Unfortunately, my patched tcpip.sys is going BSOD on me (since they capped applications to 10 connections at a time after SP1). That seems to be the only real thing holding my XP back atm.

    Since FFD_SETSIZE has to be defined before including windows or winsock, Boost doesn't really have any guaranteed control over it. So it's really just my fault for not knowing about it, or I guess Boost could have provided a method of changing it, and throw an error explaining it had to be before including windows. That would have been convenient.

    SpeedGuide.net :: Windows XP SP2 tcpip.sys connection limit patch

    What I might do is just install SP1. Ideas?
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  9. #9
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    except you forget that you can open multiple incoming sockets for the same port, which is generally what a SERVER does. Why, other than poor design, would the client open even more than 2? And as i stated the 1024 is a limit of Boost, not XP.
    Except you posted no code, so the most I could tell was that maybe you were creating 200k sockets. Did you actually run all 200k of them through a select? Did you do anything else with them? Source code, so that others might verify said results?

    But select() is a crappy method to run a server off of. If you really have that many sockets, you should be using something like poll() or some windows equivalent of epoll(). (Which I think can be done with events, WaitForMultiple, and threads.) select() & the code to use it end up being O(n^2) (check all your sockets, each with a call to FD_ISSET), which is why things like poll and epoll have come about.

    I'm a little surprised boost uses select(), actually...
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  10. #10
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by Cactus_Hugger View Post
    Except you posted no code, so the most I could tell was that maybe you were creating 200k sockets.
    handled individually all 200k+ sockets operate normally. Using select it is possible to have at least 32k sockets in a single fd_set. It fails with 64k, but I did not test numbers larger than 32k.

    Code:
    	for(int x = 0;x<FD_SETSIZE;x++){
    		SocketSet.fd_array[x] = socket(AF_INET , SOCK_STREAM , IPPROTO_TCP);
    		 
    		if(SocketSet.fd_array[x] == INVALID_SOCKET){
    			printf("Failure at socket#%d\n" , x);
    			fdsetsize = x;
    			x = FD_SETSIZE;
    			}
    		}
    	
    	SocketSet.fd_count = fdsetsize;
    	timeval Time;
    	Time.tv_sec = 5;
    	Time.tv_usec = 0;
    
    	err = select( 0 , &SocketSet , NULL , NULL , &Time);
    but i agree select is a poor method for workign with large numbers of sockets. WSAAsyncSelect or WSAEventSelect are the preferred methods.
    Last edited by abachler; 08-12-2009 at 08:07 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Poll - Terrorism & Torture
    By Kybo_Ren in forum A Brief History of Cprogramming.com
    Replies: 38
    Last Post: 12-04-2006, 02:08 PM
  2. Hungarian Notation POLL
    By maxhavoc in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 06-21-2004, 10:52 AM
  3. Today on Cprogramming....When Polls go bad?
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-25-2002, 01:41 PM
  4. Poll this Poll that
    By ski6ski in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 09-28-2001, 04:19 AM