惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
博客园_首页
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
雷峰网
雷峰网
D
Docker
博客园 - 司徒正美
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
U
Unit 42
J
Java Code Geeks
A
About on SuperTechFans
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security Affairs
I
Intezer
Cisco Talos Blog
Cisco Talos Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog RSS Feed
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
T
Threatpost
H
Hacker News: Front Page
G
Google Developers Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
L
Lohrmann on Cybersecurity
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
S
Secure Thoughts
GbyAI
GbyAI
NISL@THU
NISL@THU
S
Security @ Cisco Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Webroot Blog
Webroot Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - calmzeal

微软更新导致的IIS7设置默认主页无效 【原创】Superset在windows下的安装配置 解决 Linux error while loading shared libraries: cannot open shared object file: No such file or directory Google Review中Zlib.Portable报错的一种排查解决方案 sql行转列 VS2010发布.NET2.0网站,出现“未预编译文件* 因此不能请求该文件”的解决办法 在 64 位版本的 Windows 上IIS ASP NET不支持JET4 问题 wse [Web 开发] 定制IE下载对话框的按钮(打开/保存) 【IE信息栏问题】本地html文件js被IE阻止的一些解决方法 分享一个js Tree - dTree SqlPlus Set常用设置 OleDB Transaction ORA-01000: maximum open cursors exceeded 超出打开游标的最大数 【转】神呀~~,给我个"本地数据库的替换方案"吧! 【CLR Via C#笔记】操作符重载 C#单件模式 【CLR Via C#笔记】 类型对象 【CLR Via C#笔记】 值类型与拆装箱、参数传递 [转] CSS完美兼容IE6/IE7/FF的通用方法
记录一次服务器CPU 100%的解决过程
calmzeal · 2017-03-15 · via 博客园 - calmzeal

 昨天客户反馈业务系统很慢,而且偶尔报错。

查看nginx日志:

[root@s2 nginx]# tail log/error.log

2017/03/14 12:54:46 [error] 17042#17042: *9305256418 upstream timed out (110: Connection timed out) while reading response header from upstream

看来是请求超时了。再查看nginx.conf配置,读取时间已经设置得比较长了。

location ^~ /api/faqs
{
    proxy_pass http://api_faqs;
        proxy_redirect default;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_connect_timeout 10;
    proxy_send_timeout 10;
    proxy_read_timeout 120;
}

看来问题在后面的应用服务器,这里的接口后面是有三个.Net系统在服务,分布在两台windows服务器上。

其中一台服务器上有两个w3wp进程负责处理该接口数据,另外一台有一个进程处理。发现前者cpu使用已经100%,后者cpu使用也高达80%.

而且对应的.Net进程内存占用高达两个G。

奈何dotTrace和dotMemory已经过了试用期,只能自己看了。

使用事件查看器查看每秒请求数 Request/Sec.(在asp.net application 4里面),单w3wp进程发现请求实际上每秒约200多个,这个水平是低于平时的。

看来已经受cpu影响,请求处理能力大幅下降了。

查看数据库服务器,top 一下,mysql cpu 使用780%+(8核32g,相当于cpu使用也是100%了)。

看来是数据库问题,查top sql,qps。直接用sqlyog查看进程状态就行。

发现果然是该接口同时有几十个连接,在查询数据。

对看到的sql 做索引和查询优化后,单条sql执行时间已经是0ms。这时候数据库的cpu压力小了点,但是 应用服务器还是 100%。

最后只能分析代码了,因为该接口是需要一次性返回大量数据。

用redis和.Net Cache做了两级缓存,感觉是缓存没有命中,多次请求数据库了。

偷摸暂停接口功能,复制同样功能的接口,打上全流程日志查看,发现单次请求测试接口其实正常。

问题可能在高并发上,从代码看有几个地方有问题,最后加锁解决。