swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.42k stars 3.16k forks source link

Handling C1000k client connections #2165

Closed jobs-git closed 5 years ago

jobs-git commented 5 years ago

I just use simple swoole_http_server hello word with 250 workers. By far 1 ip can handle only 65536 concurrent client, so whenever we exceed this limit we will then get socket connection errors. So how do we configure swoole to handle this C1000k clients as claimed in the documentations.

I used wrk to test for C1000k /wrk http://127.0.0.1:9501 -c 1000000 -t 1000 -d 5

matyhtf commented 5 years ago

The local port of a single machine is only 65,535. This is a client limitation, please use multiple machines as clients.

ghost commented 5 years ago

@jobs-git

a little explanation...

TCP/IP reserves two bytes for PORT, which gives 16 bit, aka 65.535 maximum.

On localhost, you are limited to one IP with 65.535 possible ports (two bytes).

That's why you cannot benchmark this in a useful way.

In real, the situation is another one - your server gots thousands or theoretical millions of connections from several IPs. Again, every IP has a PORT field two bytes wide. So, for your server there is no problem to address a port between 0 - 65534 on the client side, because every connected IP is only one time connected to your server (mostly, depends on your stuff) with that one port.

But, if you are benchmarking - as every benchmark you are doing here - you are limited to localhost, that's why you cannot exceed 65.535 ports on the one and only underlying IP.

As matyhtf said, you can do all your benchmarking stuff with several machines - but not with one. Thats often a case in several of your questions and situations...

So, to explain in short: 1 client machine ~64k connections, 2 client machines ~ 2 x 64k, and so on - till you reach the ressources limit on server side.