Tolgay Toklar
Tolgay Toklar

Reputation: 33

What is the optimum polling duration limit for Socket.io?

I'm using Socket.io on a project and would use XHR polling, but I have a limit of 6 concurrent connections. Therefore, after opening 5 tabs, Socket.io starts to hang.

If I set the polling duration to 0 seconds (20 is the default), the limit no longer affects the application but Firebug shows that there's a request every second.

If I use a 0 second limit, how this affect my server and users?

Upvotes: 0

Views: 2315

Answers (1)

hexacyanide
hexacyanide

Reputation: 91669

When you set a duration, you are using XHR long-polling. This duration instructs the server on how long to keep a HTTP request open when it does not have any data to send. If the server does have data to send, the data is sent instantly and the connection is closed. The client then creates a new connection and the cycle continues.

When you set the duration to zero, you are effectively telling the server to use short-polling, which if the client asks the server for data, the server will instantly respond with an empty response, or with the data.

The influences that short-polling will have on the client and server are that the client will not receive messages instantly as long-polling would allow, but it consumes less resources because the HTTP request is not kept open. This also means that you probably won't hit your concurrent connection limit, because the connections end immediately.

Upvotes: 3

Related Questions