请问完成端口允许同时建立的链接个数有没有限制?如果有,是不是所有的socket模型都有这个限制?
(测试了一下,在我的计算机上最多可以同时建立2000个连接)

解决方案 »

  1.   

    How many simultaneous sockets can I have open with Winsock?
    On Win9x machines, there's a quite-low limit imposed by the kernel: 100 connections. You can increase this limit by editing the registry key HKLM\System\CurrentControlSet\Services\VxD\MSTCP\MaxConnections. On Windows 95, the key is a DWORD; on Windows 98, it's a string. I've seen some reports of instability when this value is increased to more than a few times its default value.The rest of this discussion will cover only Windows NT and Windows 2000. These systems have much higher intrinsic capabilities, and thus allow you to use many more sockets. But, the Winsock specification does not set a particular limit, so the only sure way to tell is to try it on all the Winsock stacks you plan on supporting.Beyond that vague advice, things get more complicated. The simplistic test is to just write a program that just opens sockets, to see where the program stops running: [C++ Example].The above program isn't terribly realistic. I've seen it grab more than 30,000 sockets before failing on Windows NT 4.0. Anecdotal evidence from the Winsock 2 mailing list puts the real limit much lower, typically 4,000 to 16,000 sockets, even on NT systems with hundreds of megabytes of physical memory. The difference is that the example program just grabs socket handles, but does not actually create connections with them or tie up any network stack buffers.According to people at Microsoft, the WinNT/Win2K kernel allocates sockets out of the non-paged memory pool. (That is, memory that cannot be swapped to the page file by the virtual memory subsystem.) The size of this pool is necessarily fixed, and is dependent on the amount of physical memory in the system.On Intel x86 machines, the non-paged memory pool stops growing at 1/8 the size of physical RAM, with a hard maximum of 128 megabytes. The hard limit is 256 megabytes on Windows 2000. Thus for NT 4, the size of the non-paged pool stops increasing once the machine has 1 GB of RAM. On Win2K, you hit the wall at 2 GB.The amount of data associated with each socket varies depending on how that socket's used, but the minimum size is around 2 KB. Overlapped I/O buffers also eat into the non-paged pool, in blocks of 4 KB. (4 KB is the x86's memory management unit's page size.) Thus a simplistic application that's regularly sending and receiving on a socket will tie up at least 10 KB of non-pageable memory.Assuming that simple case of 10 KB of data per connection, the theoretical maximum number of sockets on NT 4.0 is about 12,800s, and on Win2K 25,600.I have seen reports of a 64 MB Windows NT 4.0 machine hitting the wall at 1,500 connections, a 128 MB machine at around 4,000 connections, and a 192 MB machine maxing out at 4,700 connections. It would appear that on these machines, each connection is using between 4 KB and 6 KB. The discrepancy between these numbers and the 10 KB number above is probably due to the fact that in these servers, not all connections were sending and receiving all the time. The idle connections will only be using about 2 KB each.So, adjusting our "average" size down to 6 KB per socket, NT 4.0 could handle about 21,800 sockets and Win2K about 43,700 sockets. The largest value I've seen reported is 16,000 sockets on Windows NT 4.0.There's one more complication to keep in mind: your server program will not be the only thing running on the machine. If nothing else, there will be core OS services running. These other programs will be competing with yours for space in the non-paged memory pool.
      

  2.   

    一个应用程序最多可同时使用2000个左右的内核对象,socket也算内核对象,所以你测出来是2000,但正式使用时一定无法同时使用2000个,因为不可能不使用别的内核对象。
      

  3.   

    我用异步消息驱动 WSAasyncSelect方式可以达到轻松达到5000连接,并且都是可用连接!因此超过2000应该是可以的,我的系统250M 1G Windows 2000 Pro
      

  4.   

    完成端口的优点是可以充分发挥多处理器的优点,在单处理器上使用效果并非很好,因此在单处理器,Windows窗体程序中使用异步消息驱动应该是最好的选择。多处理器时用完成端口,如果不嫌麻烦,单处理器可以用重叠模型。强烈反对使用阻塞方式,同非阻塞相比,阻塞方式效率很低,Select方式的效率我的测试表明很低。另外还是事件模型,如果程序没有消息循环,用事件模型是个好的选择,但是如果存在消息循环,用事件模型就不合适!
    MFC的CSocket是一个简单低效的东西相信所有做服务器程序的人都不会采用!CAsyncSocket效率要好些,但是封装十分差,我看不如用API自己写一个类,相比下TServerSocket的效率和封装都很好,但是没有源码,不能移植到VC上。他的效率很高,如果打算做一个高负荷的程序TServerSocket是最好的选择,不过如果选择和这个类,也就选择了Borland C++.TTCPServer很象CSocket,效率不是很好。我不推荐用。TPowerSocket的性能是最差的,而且BUG奇多,强烈反对使用。Indy组件的稳定性不错。但是效率一般,特别是阻塞方式效率较差。VBSocket控件不是一个能用的选择,适用范围很有限。因此我不相信有人会在C++环境下使用这个OCX控件
      

  5.   

    大家有没有什么好的工具可以测试服务器的SOCKET负载???
      

  6.   

    我的程序好像只能接受1000个连接,我的代码是这样的
    for (int i=0;i<1000;i++) {
    sClient=socket(PF_INET, SOCK_STREAM, 0);
    if (connect(sClient,(sockaddr*)&server,sizeof(server))==SOCKET_ERROR)
    {
    DWORD D=GetLastError();
    printf("connect failed!");
    printf("%d",D);
    return 0;
    }

    printf("%d\n",i);
    }在多久报错,说什么服务器拒绝连接
    我用得iocp,w2000 pro