algorithmicCoder
algorithmicCoder

Reputation: 6799

Is long polling more resource efficient than classical polling?

Why is it more efficient for me to hold an http connection open until content comes and then re-open the connection than to simply open a connection periodically?

Ofcourse the latter scenario is perhaps more hit or miss but I am asking purely from a resource efficiency point of view.

Upvotes: 0

Views: 334

Answers (2)

mechanicker
mechanicker

Reputation: 986

By keeping a connection open, you are blocking resources but not incurring the overhead of periodic tearing down connections and setting up connections. Setting & closing a socket connection is lot more expensive underneath the function call. Sending the close intent to the connection end point, freeing the kernel resources and memory associated with it. For opening the connection, the same in reverse happens. For allocating kernel resources, there may be serialized calls (depends on kernel implementation) which can affect the overall system performance. Last but not the least, the hit-n-miss approach is not a deterministic model.

Upvotes: 2

seand
seand

Reputation: 5296

Let's say you have a thread blocked on a socket waiting for a response. (As in comet). During that time, the thread isn't scheduled by the kernel and other things on the machine can run. However if you're polling the thread is busy with brief wait periods. This also adds latency because you won't know of a need to do something until the poll occurs.

Upvotes: 1

Related Questions