nginx 进程模型
nginx
it书童
2020-12-11 22:26:57
0赞
0踩
1387阅读
0评论
nginx 的进程分为:
-
master 主进程
-
worker 工作进程
master 负责管理,worker 是具体干活的,master 还会负责监控 worker 进程
默认只有1个workder进程
$ ps -ef | grep nginx
root 13374 1 0 13:02 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 13375 13374 0 13:02 ? 00:00:00 nginx: worker process
在配置文件中可以修改
worker_processes 2;
$ sudo systemctl reload nginx
$ ps -ef | grep nginx
root 13374 1 0 13:02 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 13597 13374 0 13:13 ? 00:00:00 nginx: worker process
nginx 13598 13374 0 13:13 ? 00:00:00 nginx: worker process
多进程的优点:各进程完全独立,各自占用独立的内存,互不影响
如,master fork 了 3 个 worker,此时有一个 client,3个work去抢名为 accept_mutex 的锁,谁抢到就由谁处理
模型如下:
那么如果有很多的 client, worker1 正在处理的 client1 阻塞了,worker1 是否会在那里傻傻地等待?
当然不会!
nginx 为何性能如此强劲,在于 nginx 使用 epoll 模型,当一个 worker 处理 client 时,如果 client1 阻塞,就会切去处理 client2,依次类推
这种异步非阻塞,多路复用机制使得 nginx 只需要几个 worker 就可以处理数十万乃至数百万的并发
worker 的推荐配置值:
events {
use epoll; # 默认使用 epoll
worker_connections 10240; # 每个 worker 允许连接的客户端的最大连接数
}
- 上一篇: centos 安装 nginx
- 下一篇: nginx 主配置详解

关于我
一个文科出身的程序员,追求做个有趣的人,传播有价值的知识,微信公众号主要分享读书思考心得,不会有代码类文章,非程序员的同学请放心订阅
转载须注明出处:https://www.itshutong.com/articles/942
精品付费
个人开发者通过payjs接入微信支付
5029
0
这一次,真正掌握composer
2764
0
相关推荐
nginx 配置动静分离
1192
0
nginx 之初窥门径
1206
0
nginx 重写规则
1347
0
nginx 实现负载均衡
1215
0
nginx 基础知识
1259
0
nginx 按天切割日志
1376
0
nginx 如何实现if嵌套
1663
0
nginx实现负载均衡
1085
0
nginx日志格式以及关闭对静态资源的日志记录
1482
0
nginx 主配置详解
1029
0
nginx 解决跨域问题
1212
0
upstream 指令参数 max_conns
1712
0
upstream 指令参数 slow_start
1687
0
负载均衡之一致性hash算法
1172
0
负载均衡之url_hash与least_conn
1274
0