https://blog.csdn.net/cnskylee/article/details/127645806

众所周知,Nginx一款体积小巧,但是性能强大的软负载,主要被用作后端服务和应用的反向代理和负载均衡。

Nginx的编译可以配置很多参数,但是默认情况下是不会开启线程池(社区版从1.7.11开始引入线程池)的。因此无论是master进程,还是worker进程的线程数都是1,如下所示:

# ps -ef| grep nginx
root 8304 8232 0 09:33 pts/1 00:00:00 grep --color=auto nginx
root 16365 21060 1 Oct28 ? 02:04:32 nginx: worker process
root 16366 21060 2 Oct28 ? 02:48:07 nginx: worker process
root 16367 21060 2 Oct28 ? 02:21:11 nginx: worker process
root 16368 21060 3 Oct28 ? 03:55:30 nginx: worker process
root 21060 1 0 Jul31 ? 00:00:00 nginx: master process /data/nginx/sbin/nginx

# ps -efL| grep 21060| grep -v grep| wc -l
5
# ps -efL| grep 16365| grep -v grep| wc -l
1
# ps -efL| grep 16366| grep -v grep| wc -l
1
# ps -efL| grep 16367| grep -v grep| wc -l
1
# ps -efL| grep 16368| grep -v grep| wc -l
1

现在我们在编译的时候,增加--with-threads参数,然后在nginx.conf中配置aio threads后,再来看看master进程和worker进程的默认线程数,默认的线程池的线程数为32个。

# ./configure --prefix=/data/nginx --with-threads
# make
# make install
# ps -ef| grep nginx| grep -v grep
root 4155 1 0 09:10 ? 00:00:00 nginx: master process ../sbin/nginx
root 4156 4155 0 09:10 ? 00:00:00 nginx: worker process
root 4157 4155 0 09:10 ? 00:00:00 nginx: worker process
root 4158 4155 0 09:10 ? 00:00:00 nginx: worker process
root 4159 4155 0 09:10 ? 00:00:00 nginx: worker process

# ps -efL| grep 4156| grep -v grep| wc -l
33
# ps -efL| grep 4157| grep -v grep| wc -l
33
# ps -efL| grep 4158| grep -v grep| wc -l
33
# ps -efL| grep 4159| grep -v grep| wc -l
33
# ps -efL| grep 4155| grep -v grep| wc -l
133

现在,我们再来研究下自定义线程池(一个CPU内核最大不要超过50个线程,我的测试虚拟机是4核),尝试修改线程池的线程数为120(一个核配置30个线程)试试。

----nginx.conf配置片段
----它定义了一个名为default的线程池,其中包含 120 个工作线程和 1024 个任务的任务队列的最大长度。如果任务队列过载,NGINX 会拒绝请求并记录此错误

# in the 'main' context
thread_pool default threads=120 max_queue=1024;

# in the 'http', 'server', or 'location' context
aio threads=default;

# ps -ef| grep nginx| grep -v grep
root 4155 1 0 09:10 ? 00:00:00 nginx: master process ../sbin/nginx
root 8711 4155 2 09:47 ? 00:00:00 nginx: worker process
root 8712 4155 2 09:47 ? 00:00:00 nginx: worker process
root 8713 4155 2 09:47 ? 00:00:00 nginx: worker process
root 8714 4155 3 09:47 ? 00:00:00 nginx: worker process

# ps -efL| grep 4155| grep -v grep| wc -l
485
# ps -efL| grep 8711| grep -v grep| wc -l
121
# ps -efL| grep 8712| grep -v grep| wc -l
121
# ps -efL| grep 8713| grep -v grep| wc -l
121
# ps -efL| grep 8714| grep -v grep| wc -l
121

使用apache jmeter进行性能压测,线程组配置:

HTTP请求配置:

吞吐量压测数据(5次):

参考:

https://www.nginx.com/blog/thread-pools-boost-performance-9x/
————————————————
版权声明:本文为CSDN博主「cnskylee」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/cnskylee/article/details/127645806

【Nginx】优化,增加线程的更多相关文章

  1. 2.Nginx优化

    [教程主题]:Nginx优化 [课程录制]: 创E [主要内容] Nginx 优化 nginx介绍 Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx,它的发音为"engine ...

  2. Nginx优化(十七)

    [教程主题]:Nginx优化 [课程录制]: 创E [主要内容] Nginx 优化 nginx介绍 Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx,它的发音为“engine X”,是 ...

  3. nginx优化

    此文章非原创,出自鸟哥之手~ http://blog.chinaunix.net/uid-25266990-id-2985541.html 改排版改得多,当然红色部分要注意下,用得较多 ------- ...

  4. Nginx优化具体,应对高并发

     nginx指令中的优化(配置文件) worker_processes 8; nginx进程数,建议依照cpu数目来指定.一般为它的倍数. worker_cpu_affinity 00000001 ...

  5. Nginx优化use参数epoll,kqueue,rtsig,eventport,poll

    转自:http://blog.sina.com.cn/s/blog_5eaf88f10100gkrq.html Nginx use参数分析对比 下图对比了poll select epoll和kqueu ...

  6. nginx优化php-fpm优化 压力测试达到每分150万访问量webbench网站压力

    webbench最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好,安装使用也特别方便. 1.适用系统:Linux 2.编译安装:引用wget http: ...

  7. NGINX: 优化 use 参数

    转自:http://blog.sina.com.cn/s/blog_5eaf88f10100gkrq.html Nginx use参数分析对比 下图对比了poll select epoll和kqueu ...

  8. nginx优化配置大全

    由于面试被问到nginx优化做过哪些 后来发现,其实做过的也不少,忘了的更不少,因此写个博客记录一下(里面有一些内容来源于其他作者). 配置文件样例为生产环境样例. 1.nginx基本优化 安装方式有 ...

  9. 高并发下的 Nginx 优化与负载均衡

    高并发下的 Nginx 优化   英文原文:Optimizing Nginx for High Traffic Loads 过去谈过一些关于Nginx的常见问题; 其中有一些是关于如何优化Nginx. ...

  10. 高并发下的Nginx优化

    高并发下的Nginx优化 2014-08-08 13:30 mood Nginx    过去谈过一些关于Nginx的常见问题; 其中有一些是关于如何优化Nginx. 很多Nginx新用户是从Apach ...

随机推荐

  1. cs231n__4.2 神经网络 Neural networks

    CS231n 学习笔记 4.2 神经网络 Neural networks 之前我们已经使用了 很多线性分类函数 现在我们不用单变换的: 我们首先有线性层,然后有这个非线性计算,继而在顶层再加入另一个线 ...

  2. JavaScript:箭头函数:省略写法

    之所以把箭头函数拎出来,是因为它不仅仅是声明函数的一种方式,它还是函数式编程的重要根基,它使得函数的使用更加的灵活,同时,它的语法,也相对于function声明的函数更加灵活和复杂. 箭头函数的省略写 ...

  3. 3、mysql着重号解决关键字冲突

    1.着重号(`  `): 使用着重号(` `)将字段名或表名括起来解决冲突:保证表中的字段.表名等没有和保留字.数据库系统名或常用方法名冲突

  4. [深度学习] Pytorch模型转换为onnx模型笔记

    本文主要介绍将pytorch模型准确导出为可用的onnx模型.以方便OpenCV Dnn,NCNN,MNN,TensorRT等框架调用.所有代码见:Python-Study-Notes 文章目录 1 ...

  5. 《Effective C++》关于const,define等总结

    (将每一条item的总结和自己的理解给记录下来,以后有需要的话可以再回头参阅这些资料,不懂的再翻书温故.) Item 02:尽量以const ,enum,inline替换#define #define ...

  6. 初始化一个GCP项目并用gcloud访问操作

    1 简介 谷歌云GCP(Google Cloud Platform)是由Google提供的云平台,还是为用户提供了许多免费的产品,还是可以尝试一下的.对于学习或者小项目,都可以使用. 2 创建一个新项 ...

  7. GIT安装步骤记录以及Git 常用命令,忽略文件,推送本地代码到仓库示例以及报错解决

    下载 下载地址 git-scm.com 或 gitforwindows.org 安装(凡是下面没有给出图片的,都按默认选项就行) 选择安装组件 调整你的 path 环境变量 第一种是仅从 Git Ba ...

  8. angular配置多个系统 配置动态路由,缩短模块初次加载时间,快速打开界面,优化用户访问体验

    1.配置一个文件,返回系统名称 2.配置routes-routing.module.ts 引入文件 const system = 服务.getsystem() const allROUTES: {UR ...

  9. 腾讯出品小程序自动化测试框架【Minium】系列(四)API详解(上)

    写在前面 不知道是不是因为之前出过书的原因,在写教程之类的文章,会潜意识有自带目录和章节的感觉在里面,有点说不出的感觉吧. 上篇文章我们介绍了关于元素定位的使用方法,这篇文章将为大家分享关于Miniu ...

  10. Unity_UIWidgets新手入门

    Unity_UIWidgets新手入门 Hello Everyone!好久没见了,有没有有些想念小黑呢?什么?这么想?哈哈哈哈哈哈,不过我也知道你是想了解新的知识了,才不是想我嘞. 好了,好歹也半年没 ...