ratchetphp / Ratchet

Asynchronous WebSocket server
http://socketo.me
MIT License
6.28k stars 743 forks source link

Concurrent connections #34

Closed krnlde closed 12 years ago

krnlde commented 12 years ago

I wonder how many concurrent connections Ratchet can handle, since it relies on the Webserver (e.g. Apache) and its underlying and limited number of threads. Does it mean if I have 100 threads the server would block any further connections?

Greets, krnl

igorw commented 12 years ago

No, Ratchet doesn't run in a request/response cycle. You start it from the command line and it provides its own TCP server written in PHP. @cboden will have to give you exact numbers, but it can handle quite a lot.

mikealmond commented 12 years ago

I believe @cboden has done tests where he had over 500 simultaneous connections sending a varying payload ranging from 2kb to 256kb without issue. Another test succeeded with over 2000 connections sending small chunks of data.

Also, Ratchet (server) doesn't run through Apache, it has to be run as it's own process.

krnlde commented 12 years ago

Sounds good to me, thanks guys! But not having a Webserver around it would probably mean the $_SERVER variable is undefined or just filled partially - which is not quite an issue but needs to be considered anyways.

I haven't worked with Ratchet yet, but your answers convinced me to test it :) Thanks

cboden commented 12 years ago

The numbers @mikelamond gave are correct, however those number were not pushing the limits. I haven't stress tested Ratchet to the point of failure yet. The number of connections you can have open is limited by the operating system. ulimit is the script you can call to see the limit or increase it.

PHP (and thus Ratchet) can not be threaded. Ratchet runs as an event loop like Nginx. Once Apache and Nginx support HTTP/1.1 I plan on looking into running Ratchet through them, instead of the current process where Ratchet handles clients directly.

Running Ratchet is different from most PHP web pages you've created. Every connection is handled in the same running script. You can not use global variables like $_SESSION, as client A and client B share the same script.