Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've planned to create a website that'll be pretty heavy on dynamic content, and want to know what would be the wisest choice for part of my webstack.

Right now I'm trying to decide whether I should develop upon nginx, using PHP to deliver the dynamic content, or use nginx as a proxy to Tomcat and use servlets to deliver the dynamic content.

I have a good amount of experience with Java, JSP, and servlets, so that's a plus right off the bat. Also, since it is a compiled language, it will execute faster than PHP (it is implied here that Java is around 37x faster than PHP) , and will create the web pages faster.

I have no experience with PHP, however i'm under the impression that it is easy to pick up. It's slower than Java, but since the client will only be communicating with nginx, I'm thinking that serving the dynamically created web pages to the client will be faster this way.

Considering these things, i'd like to know:

  1. Are my assumptions correct?
  2. Where does the bottleneck occur: creating pages or serving them back to the client?
  3. Will proxying Tomcat with nginx give me any of nginx performance benefits if I'm going to be using Tomcat to generate the dynamic content (keeping in mind my site is going to be heavy in this aspect)?

I don't mind learning PHP if, in the end, its going to give me the best performance. I just want to know what would be the best choice from that standpoint.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Are my assumptions correct?

Not quite, setting up nginx infront of Tomcat would be pretty much the same as setting up nginx with PHP running though CGI using the nginx "default" php-fpm.

You'd make use of nginx's excellent static-content capabilities while just forwarding and returning dynamic content from your Tomcat.

Where does the bottleneck occur: creating pages or serving them back to the client?

Compared to just running Tomcat: probably nowhere, if anything you'll be relieving Tomcat to do the Java-part while nginx handles everything else. Give or take the extra time it takes nginx to request and serve the page from Tomcat.

Will proxying Tomcat with nginx give me any of nginx performance benefits if I'm going to be using Tomcat to generate the dynamic content?

Yes.

Also, since it is a compiled language, it will execute faster than PHP (it is implied here that Java is around 37x faster than PHP)

Don't believe everything you read on the internet ;)

Altough a interpreted language will most likely always fall short in performance of compiled code an Opcode-cache usually comes to the rescue and puts the code in a semi-compiled state which tends to speed things up immensely.

Not to the extent of compiled code, but close enough.

share|improve this answer

When it comes to choosing between Java and PHP, you need to remember the following:

  • They are both excellent languages
  • Lots and LOTS of excellent, high-performance web applications have been created using these languages
  • They both have excellent developer communities

Asking which one will perform better is impossible to answer unless you create the same application with both languages and then deploy and test them both. This is of course far too expensive and time-consuming for 99.9999% of teams.

When you are faced with this type of choice, here are some questions that you may want to ask instead of "which language performs better":

  • Which language and framework makes my development team the most productive?
  • Which type of application is the easiest for my deployment team to monitor, deploy and maintain?

If the answer is PHP, then it is foolish in my opinion to try to write the application in another language for an anticipated performance gain. However, if your team (even if it's just you) is far more comfortable with Java, then it's probably a good idea to devote your time to doing what you know as well as you can.

HTH!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.