Hi,
PHP might work faster on simple tests because it has a very large,
powerfull library already compiled as native code, so even it is basically
an interpreter, all native-code functions are faster than equivalent
java bytecode.
But the interpreted (PHP's language) libraries you might need to provide
to build will be almost sure slower than java bytecode...
Other advantages of java vs. PHP:
- More powerfull object-oriented language,
- Java better for large projects.
- Lots of libraries,
- Performance can be improved by using faster JVMs
or faster servlet engines.
- Have not working for long with PHP but I dont remember it
keeping session state. (even considering the fact it can run as
plain CGI)
- Limited number of databases supported.
Database calls are very much database-dependent, changing database
used might be a lot of pain..
Improvments to servlets on Linux..
- Use a JIT compiler, IBM has a new one,
follow links at http://alphaworks.ibm.com
Also the Kaffe JVM from http://www.kaffe.org might help.
- !!! Try to measure the performance with the JSDK's provided servlet
engine. Dont know about jserv1.0b5, but mine jserv0.9.11 was much slower
than JSDK's engine...
Don't know if it was due to missconfigurations, but anyway JSDK's
servlet engine is pretty fast to be used as a ... refference.
- Printing dates in Java may require a lot of CPU resources.
On some of my tests I found that printing dates may take most %
from processing a HTTP request. Try to instantiate a DateFormat
and re-use it to print more than one Date.
(DateFormat.format(Date) call)
Otherwise Date.toString(), each time it is called,
creates locally a TimeZone and DateFormat instance
then tell it to format(this). This is expensive.
------------------
Bye,
Cezar.
On Sat, 10 Jul 1999, Alvin, lau wrote:
> hi,
>
> I wrote a page with php and servlet and tried to compare their performance. I tried
>all the methods (using connection pool, even cache the whole page), to improve to
>the performance of servlet, but it still slower than php. I read a lot of articals
>about servlet, and they all say that servlet is faster than cgi. Can anyone tell me
>why?
>
> ps:I cannot post the source code here, exceeds 300 lines.
> check out my page for more detail.
>http://achilles.stachanov.com/~alvin/lab/phpvsservlet/ ( I put all the source code
>there).
>
> result (tested with suse linux 6.1, blackdown jdk1.1.7, jserv 1.0b5, mysql, mm jdbc
>driver , php3 and jmeter(random delay with gaussian distribution, average delay=300,
>dalay deviation=100.0)):
> 1, just display a date:
> php->average 175 ms, servlet->average 178 ms
>
> 2, Get data from mysql and format a new page:
> php->average 175 ms, servlet->average 241 ms
> (why average time of php does change?????)
>
> 3, Using Connectionpool,
> servlet->average 232 ms
> servlet (Use StringBuffer first, and then pw.println(buffer.toString())->average 220
>ms
> servlet (cache the whole page) -> servlet 185
>
> 4, change the no of threads in JMeter to 20,
> php->average 190 ms, servlet->average 546 ms .....Why?????
>
> What wrong? Anyone did this type of test before? Is it the problem of jdk, jserv
>or.....? How can I improve the preformance?
> If I have to use linux, is that mean I better use php? Php is easy to use and runs
>faster.
>
> alvin
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html