点赞
评论
收藏
分享
举报
Ngnix性能数据采集造成服务耗时波动
发表于2020-05-31 16:29

浏览 1.9k

1、现象:

    某些服务请求响应时间有规律性波动,每分钟存在波动,在响应图上体现为明显的柱状。

image.png

2、分析过程:

    部署架构为两层nignxnginx(接入层)->nginx(路由层)然后是服务层各应用集群:

·       1)如下图所示,curl在服务器上调用也存在同样的问题,如下图所示,正常情况下3ms,但波动时>5s,因此调用存在nginx及后端。

image.png

·       2)Curl单独调用服务层接口没有问题,因此确定问题出现在nginx

·       3)绕过接入层nginx,直接调用路由层nginx地址仍然出现,因此定位故障在路由层。

·       4)路由层nginx,会在服务注册时候,定期进行relaod,从而影响性能,但通过检查linux的状态,没有发生过定期规律性的restart/reload

image.png

·       5)发现路由层nginx有每分钟的定时任务。

·       6)关闭监控采集程序后问题解决。

image.png

3、根源分析:

    PaaS监控组件Prometheus,会定时调用nginx监控模块,采集性能指标,用于性能分析、展现、告警。nginx指标提供模块,采用的是 prometheus-lua,在采集程序访问时候,该字典会被加锁,造成nginx的线程等待。因此在指标量越大,访问量越多,越受影响PaaS监控组件Prometheus每分钟调用linux的这个监控模块,会阻塞linux的服务,导致响应规律性的波动,并且由于该省访问量大,集群规模大,因此受到的影响更高。通过将prometheus-lua切换为nginxvts模块问题解决。

 

Please keep in mind that all metrics stored by this library are kept in a single shared dictionary (lua_shared_dict). While exposing metrics the module has to list all dictionary keys, which has serious performance implications for dictionaries with large number of keys (in this case this means large number of metrics OR metrics with high label cardinality). Listing the keys has to lock the dictionary, which blocks all threads that try to access it (i.e. potentially all nginx worker threads).

There is no elegant solution to this issue (besides keeping metrics in a separate storage system external to nginx), so for latency-critical servers you might want to keep the number of metrics (and distinct metric label values) to a minimum.

已修改于2023-03-09 02:05
本作品系原创
创作不易,留下一份鼓励
陈友行

暂无个人介绍

关注



写下您的评论
发表评论
全部评论(1)

按点赞数排序

按时间排序

全是实战干货呀,👍🏻👍🏻👍🏻
赞同

0

回复举报

发表于2020-05-31 21:51



回复0学0
回复
关于作者
陈友行
这家伙很懒还未留下介绍~
5
文章
0
问答
24
粉丝
相关文章
原文链接:https://juejin.im/post/5d81906c518825300作者:哆啦A梦的猜想 链接:https://juejin.im/post/5d81906c518825300a3ec7ca安装安装依赖安装nginx之前,确保系统已经安装gcc、openssl-devel、pcre-devel和zlib-devel软件库gcc可以通过光盘直接选择安装openssl-devel、zlib-devel可以通过光盘直接选择安装,https时使用pcre-devel安装pcre库是为了使nginx支持HTTPRewrite模块下载nginx下载地址:http://nginx.org/en/download.html。编译安装通过上面的下载页下载最新的稳定版#wgethttp://nginx.org/download/nginx-1.8.0.tar.gz #tarxzvfnginx-1.8.0.tar.gz #cdnginx-1.8.0 #./configure--prefix=/opt/X_nginx/ngi
点赞 4
浏览 1.8k
感谢您参加> Ø3月11日用Unit实现应用的动态配置Ø 3月18日Unit的负载均衡配置Ø 3月25日Unit架构设计Ø 4月01日Unit源代码解读
点赞 1
浏览 1.2k
作者:运维研习社原文链接:https://xie.infoq.cn/article/977414e8a6a01dac35e0dfb29 gperftools是google_perftools,google开发的一款非常使用的工具集,主要包括性能优异的mallocfree内存分配器tcmalloc、基于tcmalloc的堆内存检测和内存泄露分析工具heap-profiler、heap-checker、基于tcmalloc实现的程序CPU性能检测工具cpu-profiler。在nginx中,可以通过--with-google_perftools_module编译参数启用这个性能分析模块如图,添加编译参数,重新编译nginx该模块依赖于gpreftools库,所以在编译之前,需要先编译安装gperftools,在64位系统下,需要先安装libunwindlibunwind安装:从https://github.com/libunwind/libunwind/releases或http://download.savannah.gnu.
点赞 0
浏览 1.1k