Long poll with high traffic site

Let's say I have a script that does a long poll on the server to check if the user has any new messages. Server side will be something like this

while counter < 5
    if something_changed
        push_changes_to_client
        break
    else
        counter++
        sleep 5

      

Which checks the database 5 times and each time if there is no change, it waits 5 seconds before the next check, which results in a maximum execution time of about 25 seconds.

What happens when a client quickly moves from one page to another? I suppose the server script keeps running even after the client navigates to another page where it sends another change request.

Does this mean that when a lot of people are moving around the site quickly (less than the maximum execution of 25 seconds on each page), the server should keep running all scripts that try to respond to the page that doesn't work "No?" Wouldn't that cause the server to use the entire thread of the thread pool pretty quickly?

+2


source to share


1 answer


In a thread-per-connection model with synchronous sleep calls, this can indeed bind a large number of threads. However, if "sleep" simply schedules the callback and returns, then the logarithm of the thread pool can be avoided.



+4


source







All Articles