Asaf Nevo
Asaf Nevo

Reputation: 11688

How to get Ngnix advantages with Java webservice

Along the last years i used Apache httpd server for my servers.

As i understand it - the biggest advantage in using Nginx is that Apache opens a different Thread for each HTTP request - which might load my server very quickly, while Nginx uses some other technique (Event driven) in order to take the maximum out of my server's memory and hardware.

So far so good.

I'm building a new web service which i expect to have lots of HTTP traffic so i've decided to use Nginx.

As a good Java programmer i like Java more than PHP but i have a concept problem using it in my case:

In all the post I've found that the way to use Java on it is to wrap the application with Nginx + Tomcat (or other JavaServer) + Java - so, if i understand correctly - i will not get the Nginx advantage since the Tomcat will open a new thread for each request in order to use the Java web service.

Questions:

  1. Did i understand it correctly?
  2. Does using Nginx with PHP does open a new process for each request but not a new thread ?

Upvotes: 0

Views: 325

Answers (2)

TroyCheng
TroyCheng

Reputation: 571

  1. You understand it correctly. In this case, nginx plays as a reverse proxy, tomcat works as an application server. IN most of time, the bottleneck appeared in application level: application server of application itself.
  2. PHP use process not thread to execute requests, each request needs a php-cgi process to deal with, only when this request finished, the process would be released to deal with other request. For php-fpm, it usually pre-fork many child processes, like a pool, and we need to calculate the size of this pool according to the real QPS and stat of machine.

Upvotes: 1

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42899

Yes you got it correctly, what you're doing here is putting an extra layer above the tomcat, so you'll not get the advantage, the only advantage that you'll get is serving assets ( images and static files ) without passing them to the apache, which might give a slight advantage.

Why php is has this advantage: because when using nginx instead of running php as a module of apache (mod_php) we install a separate server php-fcgi or php-fpm, so it's independent of apache's method of spawning workers or threads or whatever.

Upvotes: 0

Related Questions