Complete port overlapping IO model server, store and manage tens of thousands of Socket handles

xiaoxiao2021-03-06  42

How to store and manage tens of thousands of Socket handles in the server of the port overlapping I / O model

-------------------------------------------------- -------------

Link table, or have hash linked list, hehe ..

-------------------------------------------------- -------------

It is impossible to establish hundreds of thousands of connections.

4.8 - How Many Simultaneous Sockets Can i Have Open with Winsock?

On Windows 95 derivatives, 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 / Me, 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.

On Windows NT derivatives, anecdotal evidence puts the limit somewhere in the 1000s of connections neighborhood if you use overlapped I / O. (Other I / O strategies hit their own performance limits on Windows before you get to thousands of simultaneous connections.) The specific Limit is Dependent On How Much Physical Memory Your Server Has, And How busy The Connections Are:

The Memory Factor: According to Microsoft, the WinNT and successor kernels allocate sockets out of the non-paged memory pool (That is, memory that can not 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 memory, with a hard maximum of 128 megabytes for Windows NT 4.0 , And 256 megabytes for Windows 2000. Thus for nt 4 Factor: The Amount of Data Associated With 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, 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 22,000 sockets and Win2K about 44,000 sockets. The largest value I've seen reported is 16,000 sockets on Windows NT 4.0. This lower actual Value Is Probably Partially Due to the Fact That The Entire Non-Paged Memory Pool Isn't Available To a Single P ...................

-------------------------------------------------- -------------

To achieve efficient, you can use TCP and UDP, and users who support UDP let him use UDP. Also consider distributed structures, like EMULE and BT, do not put too much work on the server

-------------------------------------------------- -------------

<< NetWork Programming for Microsoft Windows 2nd >> has a technical statistics, using IOCP:

Attempted / Connected: 50,000 / 49,997

Memory used (KB): 242, 272

Non-Paged Pool: 148,192

CPU USAGE: 55-65%

Threads: 2

THROUGHPUT (Send / Receive Bytes Per Second): 4,326,946 / 4,326,496

(The Server Was a Pentium 4 1.7 GHz Xeon with 768 MB Memory)

So it is possible to accept tens of thousands of connections, but to stabilize it depends on your server performance and robustness. If you want to handle more connections, you may have to mention the cluster or UDP mentioned in front of the front.

Perhaps ACE is a choice, but there is no deep understanding: P

-------------------------------------------------- -------------

Online game server, 1 server can also accept hundreds of thousands of connections

The cluster has the following ideas

1. Different functions are implemented in different servers, such as database operations, and gaming programs.

2, the player file uses the same database, but the player can enter different servers, players with the same server can communicate, different servers do not

3, each server is a separate area, data and games are different

I have never heard of cluster game servers who really do load balancing.

转载请注明原文地址:https://www.9cbs.com/read-55012.html

New Post(0)