nginx的:它的多线程,但使用多个进程? [英] nginx : Its Multithreaded but uses multiple processes?

查看:218
本文介绍了nginx的:它的多线程,但使用多个进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解什么让Nginx的这么快,我有几个问题。

I'm trying to understand what makes Nginx so fast, and I have a few questions.

据我了解,无论是阿帕奇产生一个新的进程来满足每个请求或产生一个新的线程来满足每个请求。因为每个新线程共享虚拟地址空间中的内存使用情况保持爬升如果有若干在未来的并发请求的

As I understand it, Apache either spawns a new process to serve each request OR spawns a new thread to serve each request. Since each new thread shares virtual address space the memory usage keeps climbs if there are a number of concurrent requests coming in.

Nginx是由具有只是一个听的过程(主),用一个执行线程和2或3(数是可配置)工作进程解决这个问题。这个主进程/线程运行事件循环。有效地等待任何传入的请求。当一个请求到达它给出了请求,工作进程中的一个。

Nginx solves this by having just one listening process(Master), with a single execution thread AND 2 or 3(number is configurable) worker processes. This Master process/thread is running an event loop. Effectively waiting for any incoming request. When a request comes in it gives that request to one of the worker processes.

请纠正我,如果我的上述认识是不正确

Please correct me if my above understanding is not correct

如果上面是正确的,那么我有几个问题:

If the above is correct, then I have a few questions:

1)是不是工作进程将产生多个线程,要遇到同样的问题阿帕奇?

1.) Isn't the worker process going to spawn multiple threads and going to run into the same problem as apache ?

2。)或者是nginx的快,因为它的基于事件的架构采用非阻塞-I​​O骨子里。也许工作进程派生里面做的非阻塞-I​​O线程,是吗?

2.) Or is nginx fast because its event based architecture uses nonblocking-IO underneath it all. Maybe the worker process spawns threads which do only non-blocking-IO, is that it ?

3。)什么究竟是基于事件的架构,可真有人把它简化为soemone像我这样的理解。难道它只是属于无阻塞-IO还是其他什么东西呢?

3.) What "exactly" is "event based architecture", can someone really simplify it, for soemone like me to understand. Does it just pertain to non-blocking-io or something else as well ?

C10K ,我想通过它的参考,但我不认为其对基于事件的牌坊。它似乎多为非阻塞IO。

I got a reference of c10k, I am trying to go through it, but I don't think its about event based arch. it seems more for nonblocking IO.

推荐答案

这不是从概念的角度来看非常复杂。我会尽量清楚,但我必须做一些简化。

It's not very complicated from a conceptual point of view. I'll try to be clear but I have to do some simplification.

基于事件的服务器(如 nginx的的lighttpd )使用包装围绕一个事件的监控系统。例如。 lighttpd的使用了libevent 以抽象的更先进的高速事件监测系统(见的 libev 也)。

The event based servers (like nginx and lighttpd) use a wrapper around an event monitoring system. For example. lighttpd uses libevent to abstract the more advanced high-speed event monitoring system (see libev also).

服务器跟踪所有使用一个简单的状态机的每个连接的无阻塞连接它(写入和读取)的。事件监控系统会通知服务器进程当有新的数据资料,或当它可以写入更多的数据。这就像一个选择()类固醇,如果你知道套接字编程。服务器进程然后只需将使用一些先进的功能所要求的文件如的sendfile()在可能的情况或打开使用通信套接字请求到CGI进程(此套接字将是监测与事件监控系统,如其它的网络连接。)

The server keeps track of all the non blocking connections it has (both writing and reading) using a simple state machine for each connection. The event monitoring system notifies the server process when there is new data available or when it can write more data. It's like a select() on steroids, if you know socket programming. The server process then simply sends the requested file using some advanced function like sendfile() where possible or turns the request to a CGI process using a socket for communication (this socket will be monitored with the event monitoring system like the other network connections.)

链接作为很多关于nginx的的内部大量信息,以防万一。我希望它能帮助。

This link as a lot of great information about the internals of nginx, just in case. I hope it helps.

这篇关于nginx的:它的多线程,但使用多个进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆