views:

166

answers:

2

if i write the comet push with php but use this code on a java server via quercus, will that solve the one process per request problem that apache had and scale well with lot of users using my chat?

+2  A: 

Yes, Quercus solves the one process per request Apache bottleneck. However, you need to understand the possible bottlenecks of the JVM. In my opinion, though, you should write the service or app in C/C++ using something like libevent, in Erlang, in Google Go, or simply as a Java servlet simply for portability's sake.

David Titarenco
please read my comment on cletus answer. i really have to know if this will work and that the server will not hang up with a lot of users chatting.
weng
Replied on cletus' question!
David Titarenco
A: 

Well, Quercus runs on the (J)VM so it can run with other code that can start threads. But why do you need threads to do chat? You simply set the timeout on a vanilla PHP request to 0 (no timeout) and wait for there to be something to send back to the user.

That something else will be in response to someone else's request (ie A says "hello" which interrupts B's wait for something to happen). That doesn't require multithreading.

Also you could keep using Apache/PHP and do the above and instead connect to a Java (or other) service via something like XML RPC, which could wait forever. That server could do run multiple threads or do whatever it needs to.

cletus
i read about that if you implement comet with apache, then if you got 5000 users, apache would create 5000 active processes that consume a lot of memory and cpu. imagine what will happen with your web server if you got 100 000 of users chatting at the same time. and then someone said that with java (the language and the server) even if you got 100 000 users chatting, the processes to the users who are not sending anything will be "at sleep", and only active processes consume cpu and ram. correct me if im wrong, and it would be helpful if you could elaborate this concept for me.
weng
so i wonder, if i use my php comet code in a java server with quercus (which i sucessfully have implemented) will this solve this apache process problem and put the inactive processes at sleep?
weng
@noname: comet processes are open connections and executing code, regardless of language. Now you can argue the overhead is lower in Java bytecode. I can't say if that's the case or not or if it is to what degree. But those open connections will consume resources and fundamentally there's no difference in terms of sleeping processes. PHP can do a blocking operation and sleep just like Java can. Also, are you really going to have 100,000 users? Why not build for the problems you'll actually have rather than those you wish you had?
cletus
this is what i read: "From what I have read here so far is that php is not the best option because it is run as a one process per request instead off thread." it seemed to me from other info that Java solves this problem somehow. is it because of java creates a thread per request? and how does this help the webserver technically? is there any article for me to fully understand the comet issues. i just heard java server is better than apache but dont quite understand why. so i implemented the php code in glassfish. do you think that will solve whatever problem that would emerged with apache?
weng
@noname: The process vs thread thing is a valid point. But even one thread per connection doesn't scale. Check out Grizzly (a Java NIO-based HTTP listener) for more on that. You can also use PHP for the pages and something else for the chat backend, which is what I'd advise over Quercus.
cletus
@noname and cletus: cletus is right. I learned this the hard way. One process/thread/worker (JVM or not) per connection is silly (whether the threads are pooled or not), and I guarantee it will supersaturate your resources sooner or later. Like I said in my answer, I STRONGLY urge you to write the service via a scalable platform. PHP is not that platform. IMO, neither is Quercus.
David Titarenco
so i cant have a chat function with php? i have to write it in java? but like u said, if the one process/thread/worker (JVM or not) per connection is the problem, how could java help me with this?
weng
The idea is that you can write a custom servlet who's memory footprint per connection (whether it's threaded or not) is much much much smaller than what native PHP or even Quercus can achieve.
David Titarenco