如何Nginx的处理HTTP请求? [英] How does Nginx handle HTTP requests?

查看:178
本文介绍了如何Nginx的处理HTTP请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解线程驱动的Apache使用:每个连接打开一个线程,当发送的响应,该线程被关闭,释放其他线程的资源)

I understand thread driven that Apache uses: every connection opens up a thread and when the response is sent, the thread is closed, releasing the resources for other threads).

但我没有得到事件驱动的设计,Nginx的使用。我读过有关事件驱动设计的一些基本..但我不明白这是怎么使用nginx的处理Web请求。

But I don't get the event driven design that Nginx uses. I've read some basics about event driven design .. but I don't understand how this is used by nginx to handle web requests.

在那里我可以阅读和理解Nginx的是如何处理的这么一个事件驱动的方式,我得到为什么它是更好的连接,而不是仅仅接受了基于事件的设计比线程驱动设计要好。

Where can i read and understand how Nginx is handling the connections in an event driven way so I get why it's better, rather than just accepting that event-based design is better than thread-driven design.

推荐答案

Nginx的使用反应堆格局。基本上,它是单线程的(但可以派生多个进程,利用多个内核)。对于OS的主事件循环等待信号一个准备的事件 - 例如该数据可从一个插座读取,在该点它被读入缓冲区并进行处理。单个线程可以非常有效地服务于数万同时连接(螺纹每次连接模型将失败在此,因为巨大的上下文切换开销,以及大的内存消耗,因为每个线程需要它自己的堆栈)

Nginx uses the Reactor pattern. Basically, it's single-threaded (but can fork several processes to utilize multiple cores). The main event loop waits for the OS to signal a readiness event - e.g. that data is available to read from a socket, at which point it is read into a buffer and processed. The single thread can very efficiently serve tens of thousands of simultaneous connections (the thread-per-connection model would fail at this because of the huge context-switching overhead, as well as the large memory consumption, as each thread needs its own stack).

这篇关于如何Nginx的处理HTTP请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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