nginx学习随笔–worker_processes
简单介绍worker_processes的使用:
- nginx英文文档原文
Syntax: worker_processes number | auto;
Default: worker_processes 1;
Context: main Defines the number of worker processes. The optimal value depends on many factors including (but not limited to) the number of CPU cores, the number of hard disk drives that store data, and load pattern. When one is in doubt, setting it to the number of available CPU cores would be a good start (the value “auto” will try to autodetect it). The auto parameter is supported starting from versions 1.3.8 and 1.2.5.
中文翻译:
决定工作进程的数量。
最佳值取决于很多因素包括(但不限于)CPU核数,存储数据的硬盘驱动器数量,以及负载模式。当有一个因素不确定,开始时最好把这个值设置成CPU核数(当值为 auto 时,nginx会自己决定工作进程数量)。
配置经验分享:
- 一般设置为1就足够了,可以把连接数设置的很大,比如65535。
- 如果有SSL,gzip等比较消耗CPU资源的工作,而且CPU是多核的话,可以把值设置为和CPU核数一样。
- 如果有很多静态文件而且它们的总大小超过内存大小,那么可以增加工作进程来充分利用I/O带宽。
- 如果要开多个工作进程,最好是CPU核数的1~2倍。正常情况下,不要太多,因为工作进程太多会影响nginx主进程调度。