Search code examples
phpasp.netajaxlong-polling

Queue up Requests in one thread for long polling


I'm new to it but I really like the idea of long polling.
After reading about it I would implement it like so:

  1. Client requests Server (AJAX)
  2. Server is polling DB for change
  3. When change is recognized or after Time-out Server respond

My problem with this is, that for every request a thread is started on the server plus every thread polls the DB.

Wouldn't it be more effective to run one single Thread on the Server that accepts all incoming Requests? like so:

  1. Client requests Server (AJAX)
  2. Server adds the Request to a queue (no response)
  3. Worker-Thread polls DB for changes related to all requests in queue
  4. When changes are recognized server returns the result for corresponding request

Advantage of this is, that the DB is polled much less and all requests are handled in one thread (less Memory consumption)

My Question:
Is this possible / are there Implementations or Frameworks for that?
(Our Project hasn't started jet so it doesn't matter whether we use PHP or ASP.NET for this)

TIA for your suggestions =)


Solution

  • check node.js and non blocking IO