JSP vs mod_php and mod_perl
      By Scott Ferguson
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Servlets and Filters
Portlets
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Feature Overview
Release Notes
Change Logs
Migrate from 2.1
Benchmarks
Features FAQ

JSP Benchmark
XSLT Benchmark
JSP vs mod_php and mod_perl
XSLT Benchmark
Benchmarks
Features FAQ

JSP and Servlets can outperform mod_perl and mod_php. Java's outdated reputation for performance problems is no longer deserved. Fast servlet engines like Resin and fast JDK's like IBM's 1.1.8 JDK now make Java the language of choice for web applications.

Java has always been more maintainable than Perl or PHP scripts. With JSP, Java also becomes easy for web page design. Where Java has had trouble in the past is performance. That unfortunate perception is now obsolete. Java servers can now outperform the leading contenders for web site design.

Note: The benchmark has been rerun with an additional "Loop" benchmark. Also, several reviewers have suggested ways to improve the performance of Perl and PHP.

  1. New Benchmark Comparison
  2. Benchmark Description
    1. File
    2. Servlet
    3. Hello
    4. Loop
    5. Big
    6. DB
    7. Cache
  3. Old Data
  4. Web Content Engines
  5. Configuration
  6. Discussion
  7. Conclusion

New Benchmark Comparison
All results are in operations per second. The results are sorted by Hello performance.

Single Client
EngineFileServletHelloLoopBigDBCache
Resin/IBM 5715505583683131/268603
Resin/Apache/IBM 5053733863665122/202382
Resin/IIS 7303483643246----
mod_perl/Apache 497n/a322117498--
ASP/IIS 727n/a3171.531----
mod_php/Apache 504n/a3081336130--
Resin JS/Apache/IBM 484n/a254166133/118376

The following table shows four HTTP clients and HTTP/1.1 keepalive. The fourth keepalive request closes the connection.

Four Clients with Four Keepalive
EngineFileServletHelloLoopBigDBCache
Resin/IBM 1455118715534696176/3671561
Resin/Apache/IBM 8805645753891135/237586
Resin/IIS 16194174223548----
mod_perl/Apache 801n/a385119793--
ASP/IIS 1654n/a3851.480----
mod_php/Apache 869n/a3421344141--

Benchmark Description
Each engine was tested against seven benchmarks.

File

The file benchmark is just a small (311 byte) static file. It tests the web server's maximum static page rate.

Servlet

The servlet benchmark is a trivial "Hello, World" servlet. It measures the servlet engine overhead. In other words, no matter how efficient you make your servlet code, you will never get better performance than this number.

Hello

A trivial "Hello, World" page. It measures the JSP (or Perl or PHP) overhead. No matter how efficient you make your servlet code, you will never get better performance than this number.

Loop

Just prints lots of "Hello, World" in a loop. The resulting output is about 64k. The results, especially in comparison with "Big", give a very rough comparison of the execution performance.

Big

Somewhat misnamed, this is just a large almost-static page. It's about 64k. The page doesn't do much processing, so this just tests the ability to push bytes back to the client.

DB

A simple database query. The page prints the results from two small SQL selects. It gives an indication of database performance.

For the new Java benchmark, the first number uses the org.gjt MySql driver. The second number uses an experimental Caucho driver, available on request. So the two numbers gives a good idea of how important JDBC drivers are to the performance.

Cache

Same as DB, but the page sets the Expires header 15 seconds in the future.

Old Data

The new version of the benchmark is incomplete. It leaves out several servlet engines. FYI, here's the old data. All results are in operations per second. The results are sorted by Hello performance.

Benchmark comparison
EngineFileServletHelloBigDBCache
Resin/IBM 61555751096143572
Resin/JDK1.2 4514004266675420
Resin/Apache/IBM 4883463704992388
Orion/JDK1.2 433165319617864
mod_php/Apache 497n/a25846104104
mod_perl/Apache 488n/a324829898
ServletExec/Apache/IBM 4758791--5252
Tomcat/IBM 1148983184444
CGI perl/Apache 488n/a592566
JRun/Apache/JDK1.2 4716133--2222
Tomcat/JDK1.2 335533112121

Web Content Engines

  • Resin 1.1 b2 (internal web server)
  • Orion 0.7.6b (internal web server)
  • Tomcat (internal web server)
  • Resin 1.1 b2/Apache 1.3.9
  • mod_php 4.0b2
  • mod_perl 1.21
  • JRun 2.3.3/Apache 1.3.9
  • ServletExec 2.2/Apache 1.3.9
  • CGI using Perl

Configuration

The server is a 266 Mhz Pentium II running RedHat 6.0 with 64 meg of ram. The client is a 300 Mhz Celeron also running RedHat 6.0 with 32 meg. The two machines are connected with a 100bT ethernet connection.

The client is a simple C program acting as a browser. It sends requests, including typical header fields, and retrieves the results. The results are hashed and compared to an expected value.

Before each test, the client sends and discards a single request. This takes care of startup costs. In the test, 1000 requests were sent sequentially; the client waited for the request to complete before sending another request. Each test was repeated three times and the median result chosen.

Apache configurations used Apache 1.3.9. All modules were compiled with DSO support.

Where possible, the benchmark used the IBM 1.1.8 JDK. When the servlet engine didn't work with the IBM JDK, the Blackdown 1.2 was substituted instead. For example, Orion needs JDK 1.2 and JRun spun using the IBM JDK.

Database benchmarks used Mysql using the mm.mysql JDBC driver.

Discussion
First, these benchmarks are 'toy' benchmarks. To fully compare Resin to other servlet engines or Perl or PHP, you need to write your full application in both languages and compare the two. These benchmarks are only a starting point and should be taken with a grain of skepticism.

This benchmark didn't include a full application for two reasons. First, we're somewhat crunched for time. Second, what would be a representative benchmark? The home page of slashdot? Also, should be application be written as most people would write it, or the most maintainable, or the fastest hacked up version the best programmers can come up with? So a full application would raise more questions than it answered.

For example, compare the "Big" numbers with the "Loop" numbers. They both send the same amount of data back to the client, but the performance is difference is large. Based on this information alone, an evil benchmarker could tweak the benchmark to the benefit of any engine.

Based on this benchmark, the Perl and PHP database drivers are faster than the JDBC driver. This appears to be a JDBC implementation issue, not anything intrinsic to Java. The internal Caucho prototype JDBC driver gives much faster results, even faster than Perl and PHP. Since real projects can't use internal JDBC prototypes, the DB performance difference may matter to some projects.

Also, the 'Big' benchmark also gives the advantage to Perl. It may be interesting to note that changing the benchmark slightly makes Resin faster than Perl. If the benchmark is a simple for loop printing 1024 lines, with the same output size, Resin is faster than Perl. The benchmarks will be updated in a few weeks including the new loop test.

So is Resin or PHP or Perl faster? It really depends on your application. As a first cut, it's probably best to assume they have about the same performance unless you can benchmark your specific application. A difference of only 30% in a toy benchmark should be interpreted as having little or no difference.

These results are primarly important because previous servlet engines were much slower than PHP or Perl. With Resin, servlet performance is now about the same. Projects should use other considerations, like maintainability or ease of implementation to decide between the languages.

Conclusion
JSP can approach static page performance. A perception still exists that Java is a great programming environment but hobbled by performance. The perception is no longer valid.

The near-static performance means that many sites, who never considered JSP or servlets because of performance, can now take advantage of the Java platform's reliability and ease of programming benefits.


XSLT Benchmark
Benchmarks
Features FAQ
Copyright © 1998-2005 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.