Jump to content

While Loop server load


naifwonder

Recommended Posts

Before posing my question, I think that some background information is necessary. I am looking into methods to create a web-based chat system. Right now, my options are polling, or a comet system (long polling, long-lived connections, etc). I have found several comet solutions that look promising, but implementing them is no walk in the park. So far, ape-project.org looks to be the most promising comet solution.

 

The easier option to implement is the polling system. I was thinking that I would use javascript to request a php page, which would then run a while loop until new data is found. The while loop would expire after 30 seconds or so (or some arbitrary time to prevent "dead" connections from running if user leaves the site). If there is any data to "push" to the client, it would be sent, and the while loop would be ended. Immediately after the client receives and processes the newly received information, it would request the same page again, once again activating the while loop. This would go on until the user logs out.

 

My inquiry is this..

 

Just how intensive on the server is the polling method? I can't seem to find any good information regarding how apache would handle many concurrent while loops running in this manner. Does it use up threads on the server at a quick pace, greatly limiting the scalability of such an approach?

Link to comment
Share on other sites

It sounds like you'll basically need one active apache process for each client.  The limit there is your server's memory, and also apache's limit on number of concurrent threads (which you can increase if you have enough memory).  CPU time won't be an issue if you sleep a little during your while loop between checks.

 

Each while loop will occupy one apache thread if that's what you're wondering.

 

If you instead open a new connection every n seconds for each client, the bottleneck will be the work done for setting up and shutting down each connection.  With a powerful server and good coding (ie few or no database accesses on each request, most data in memcache, and a cacher like xcache), I have a feeling that this will scale better.  There's no way to tell for sure other than to try it.

Link to comment
Share on other sites

Thank you for the informative reply. It seems that a constant opening and reopening (polling) creates too much of a bottleneck (as you had pointed out). The opening and closing of connections if extremely strenuous on the server. Right now, the option I am considering is sending a request for a php page, holding it with a while loop with 1 second sleep breaks in it, connecting that php file via sockets to a server, and communicating through that. The php file will be contained in an iframe for cross-crowser compatibility reasons. I was looking into Apache MPM, and that looks like it might be able to solve the threading issue. Where as apache normally holds one thread for connections, apache mpm seems to free up a threads (I'm still looking into this). I'm pretty much just rebuilding my own comet server.. it seems easier than figuring out these pre-built solutions that are built on framework on top of framework, very few of which I am familiar with.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.