2013-07-18 21:44
浏览 22

如何通过Java Web服务获得Nginx的优势

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.


  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 ?

图片转代码服务由CSDN问答提供 功能建议

在过去几年中,我将Apache httpd服务器用于我的服务器。

据我了解 - 使用Nginx的最大优势是Apache为每个HTTP请求打开一个不同的线程 - 这可能会非常快速地加载我的服务器,而Nginx使用其他一些技术(事件驱动)以便从我的 服务器的内存和硬件。


我正在构建一个我期望的新Web服务 为了拥有大量的HTTP流量,所以我决定使用Nginx。

作为一名优秀的Java程序员,我比Java更喜欢Java,但在我的情况下使用它有一个概念问题:< / p>

在所有帖子中,我发现在其上使用Java的方法是使用Nginx + Tomcat(或其他JavaServer)+ Java包装应用程序 - 所以,如果我理解正确的话 - 我不会得到Nginx的优势,因为Tomcat将为每个请求打开一个新线程,以便使用Java Web服务。


  1. 我是否理解正确?
  2. 使用Nginx和PHP确实打开了一个新流程 每个请求但不是新线程?
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongying6659 2013-07-19 00:57

    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.

    解决 无用
    打赏 举报
  • dtrj21373 2013-07-19 08:31
    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.
    解决 无用
    打赏 举报

相关推荐 更多相似问题