`

Nginx:worker_processes、worker_connections设置

 
阅读更多

worker_processes与worker_connections 设置好合适大小,可以提示nginx处理性能,非常重要。

 

写道
一般一个进程足够了,你可以把连接数设得很大。(worker_processes: 1,worker_connections: 10,000)
如果有SSL、gzip这些比较消耗CPU的工作,而且是多核CPU的话,可以设为和CPU的数量一样。(worker_processes: CPU核心数)
或者要处理很多很多的小文件,而且文件总大小比内存大很多的时候,也可以把进程数增加,以充分利用IO带宽(主要似乎是IO操作有block)

 

worker_processes,工作进程数
  • 1.默认:worker_processes: 1
  • 2.调大:worker_processes: CPU核心数,(双核4线程,可以设置为4)
worker_connections,单个工作进程可以允许同时建立外部连接的数量

数字越大,能同时处理的连接越多

  • 1.默认:worker_connections: 1024
  • 2.调大:worker_connections: 100000,(调大到10万连接)
worker_connections解析
  • 1.connections不是随便设置的,而是与两个指标有重要关联,一是内存,二是操作系统级别的“进程最大可打开文件数”。
  • 2.内存:每个连接数分别对应一个read_event、一个write_event事件,一个连接数大概占用232字节,2个事件总占用96字节,那么一个连接总共占用328字节,通过数学公式可以算出100000个连接数大概会占用 31M = 100000 * 328 / 1024 / 1024,当然这只是nginx启动时,connections连接数所占用的nginx。
  • 3.进程最大可打开文件数:进程最大可打开文件数受限于操作系统,可通过 ulimit -n 命令查询,以前是1024,现在是65535,
    nginx提供了worker_rlimit_nofile指令,这是除了ulimit的一种设置可用的描述符的方式。 该指令与使用ulimit对用户的设置是同样的效果。此指令的值将覆盖ulimit的值,如:worker_rlimit_nofile 20960;
    设置ulimits:ulimit -SHn 65535
写道
worker_processes 2;
worker_rlimit_nofile 65535;
#pid logs/nginx.pid;
events {
worker_connections 65535;
}

 

通过 ps -elf | grep nginx 找到 nginx 的worker进程ID
通过 cat /proc/31613/limits 查看,其中2291是worker进程ID,请注意其中的Max open files

在这里插入图片描述

从上面的分析可以看出nginx占用内存小,处理性能高,通过提高服务器的配置,Nginx可以应对更大的连接数

 

 

 

 

分享到:
评论

相关推荐

    Nginx worker_connections配置太低导致500错误案例

    最近一次安全培训,需要用到安全攻防平台,结果30几个人登录上去直接爆出500错误。不知道什么原因,后来找来SSH登录用户,密码,逐步排查,发现了Nginx... 您可能感兴趣的文章:Nginx中worker connections问题的解决方法

    nginx:使用Ansible设置Nginx服务器

    Nginx的 设置具有配置域名的nginx服务HTTPS。 要求 基于apt的软件包管理器和systemd ... nginx_worker_processes auto nginx_pid /run/nginx.pid nginx_worker_connections 768 nginx_sendfile on

    Nginx配置文件详细说明

    worker_processes 1; #全局错误日志及PID文件 error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; #工作模式及连接数上限 events { use epoll; #epoll是多路复用IO(I/O Multiplexing)中的一种...

    lua-nginx-openresty-redis 详细案例源码

    nginx 并发数问题思考:worker_connections,worker_processes与 max clients 如何在工作中提高Ngixn服务器性能?达到高效 并发 = 同步/异步/阻塞/非阻塞/进程/线程 The Complete NGINX Cookbook 如何改进 NGINX ...

    ansible-role-nginx

    nginx_worker_processes: 1 nginx_pid: /var/run/nginx.pid nginx_access_log: /var/log/nginx/access.log nginx_error_log: /var/log/nginx/error.log nginx_worker_connections: 1024 您可以在剧本中覆盖...

    nginx优化 使用Google的开源TCMalloc库

    worker_processes 8; error_log /web/logs/nginx_error.log crit; pid logs/nginx.pid; google_perftools_profiles /tmp/tcmalloc/; events{ use epoll; worker_connections 65535; } 6:测试和运行 # /usr/...

    ansible-role-nginx-proxy:安装Nginx用作前端代理

    nginx_proxy_worker_processes :工作进程数,默认为1 nginx_proxy_worker_connections :工人连接数,默认1024 nginx_proxy_buffers :代理缓冲区的数量和大小(可选) nginx_dynamic_proxy_resolvers :如果...

    嵌入Python脚本的Nginx模块ngx_python.zip

    worker_processes 4; events {  worker_connections 1024; } http {  include mime.types;  default_type application/octet-stream;  keepalive_timeout 65;  server {  listen 80;  ...

    nginx_response_codes:来自 nginx 服务器的响应代码的指标!

    nginx_response_codes #开发中; 不使用! 来自 nginx 服务器的响应代码的指标!... worker_connections 1024 ; } http { response_codes on; server { root /www/data; location / { } } }

    nginx.conf

    worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events {  worker_connections 1024; } http {  include /etc/nginx/mime.types;  default_type application/...

    linux下nginx安装及使用

    本文主要讲解centos6.9版本的nginx的安装与配置! # 使用yum安装 ...worker_processes:工作进程个数,可配置多个 worker_connections:单个进程最大连接数 server:每一个server相当于一个代理服务器 list

    服务器端nginx配置文件

    worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime....

    利用nginx反向代理tomcat服务器(非常详细,又不懂的可以m我)

    worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types;...

    presentation:不同课程的介绍。 使用“ AsciiDoc”和“ Asciidoctor Reveal.js”生成“ HTML”

    worker_processes 1; error_log $PROJECT_PATH/.deploy/error.log; pid $PROJECT_PATH/.deploy/nginx.pid; events { worker_connections 10; } http { access_log $PROJECT_PATH/.deploy/access.log;

    nginx_monitoring:Nginx监控

    Worker_Processes 支持的最大连接数取决于配置 Nginx服务状态 图形和屏幕: “请求统计信息”图 “连接状态”图 文件描述符 触发条件: Nginx服务状态 工作进程处理配置错误 请阅读安装文件

    nginx-restrict-access-module:Nginx模块使用远程主机的主机名来限制对服务器位置的访问

    Nginx限制访问模块一个基于Nginx访问模块的模块,用于使用远程主机的主机...worker_processes 1;worker_rlimit_core 500M;working_directory /tmp;debug_points abort;events { worker_connections 1024; #use kqueue;

    Nginx中worker connections问题的解决方法

    查看日志,有一个[warn]: 3660#0: 20000 worker_connections are more than open file resource limit: ...所以,当你修改提高了配置文件中的worker_connections值,然后重启nginx,你就会在日志里发现,最前面我们讲

    经典nginx配置文件nginx.conf文件(注释通俗理解nginx节点)

    2、节点有user、worker_processes、error_log、pid、worker_rlimit_nofile、worker_connections、multi_accept、use、include、default_type、client_header_buffer_size、upstream、proxy_pass、proxy_set_header等...

Global site tag (gtag.js) - Google Analytics