PHP <--> Java daemon
Moderator: General Moderators
PHP <--> Java daemon
I have a PHP site that does a lot of intensive math operations for each request.
PHP was taking 300-500 msec per request.
My current solution: a Java daemon running in the background that PHP connects to over a socket.
This seems ideal; the socket overhead is minimal and I get the best of both worlds: Java's raw power and
PHP's page-serving speed. Now we average 60 msec per request.
My question: Is this wrong?
...I mean, I'm starting to shift more and more functionality into the Java daemon (e.g, database access stuff) because it is faster and more enjoyable for me to develop in. However, I haven't tested this in live deployment with any kind of load. Is there a fatal flaw in this type of setup?
Another question: Any suggested resources?
Thanks!
PHP was taking 300-500 msec per request.
My current solution: a Java daemon running in the background that PHP connects to over a socket.
This seems ideal; the socket overhead is minimal and I get the best of both worlds: Java's raw power and
PHP's page-serving speed. Now we average 60 msec per request.
My question: Is this wrong?
...I mean, I'm starting to shift more and more functionality into the Java daemon (e.g, database access stuff) because it is faster and more enjoyable for me to develop in. However, I haven't tested this in live deployment with any kind of load. Is there a fatal flaw in this type of setup?
Another question: Any suggested resources?
Thanks!
- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
Well, I've heard that Java is a dog at serving web pages.
...but I see your point; if the java daemon is so great, why not shift the entire app into it? In other words, have PHP send the POST parameters over the socket and get back HTML? Seems ridiculous, but I don't fully get why it is a bad idea (besides aesthetics.)
I guess I also don't understand why Java sucks at serving web pages.
...but I see your point; if the java daemon is so great, why not shift the entire app into it? In other words, have PHP send the POST parameters over the socket and get back HTML? Seems ridiculous, but I don't fully get why it is a bad idea (besides aesthetics.)
I guess I also don't understand why Java sucks at serving web pages.
- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
Java websites are always slow. There are no large, successful websites written in Java that I am aware of.I meant, why don't you just install Tomcat or Resin and write the whole website in java? From what you've said, I don't see any reason to use php in your case.
Why is it so slow? I wish I knew
Hosting a Java website costs about twice as much as a PHP site. It's a much more complicated system.And what do you mean by java being "expensive"? It's open source, just like php.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
The JVM uses a lot of memory. You generally need better equipped servers. All in all I say just use Java though. It seems silly to use PHP purely for the purpose of taking the requests then relaying to Java.brighama wrote:Java websites are always slow. There are no large, successful websites written in Java that I am aware of.I meant, why don't you just install Tomcat or Resin and write the whole website in java? From what you've said, I don't see any reason to use php in your case.
Why is it so slow? I wish I knew
Hosting a Java website costs about twice as much as a PHP site. It's a much more complicated system.And what do you mean by java being "expensive"? It's open source, just like php.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
The perception that Java = Slow largely stems from poorly written Java Applets and GUI applications, where initializing the runtime environment is painfully slow and the developers did not optimize properly to improve application response.
In a web context, these issues are mostly moot, due to the fact that the Java server is persistent, and web applications (in comparison to traditional apps) due not need to be blazing fast to give the perception of performance. My main problem with deploying Java based apps is that shared hosts don't support them! (as opposed to PHP, which is nearly universal) and that you have to compile your classes (which means somewhat slower development). Java is a pretty nice language with a very extensive standard library.
In a web context, these issues are mostly moot, due to the fact that the Java server is persistent, and web applications (in comparison to traditional apps) due not need to be blazing fast to give the perception of performance. My main problem with deploying Java based apps is that shared hosts don't support them! (as opposed to PHP, which is nearly universal) and that you have to compile your classes (which means somewhat slower development). Java is a pretty nice language with a very extensive standard library.