服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

dirtysea 发表于 2021-11-22 11:38:17

wrk,ab,locust,Jmeter 压测结果比较

<h2 id="背景:" style="margin-top: 10px; margin-bottom: 10px; font-size: 21px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">背景:</h2><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">项目需要对一批接口进行压测,要求是接口的QPS(Quest Per Second每秒请求数)达到6万以上<br>由于楼主一直使用的压力测试工具是jmeter,但是jmeter单台电脑无法达到6万的QPS,于是使用网传比较好用的其他性能工具进行压测比较,选出一款符合要求的工具进行压测。</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">压测机器:Linux 4核8G<br>由于不同的性能工具压测时消耗的系统资源不一样,防止系统资源造成的干扰,测试时服务器只运行压测工具,且非本机压本机。</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">示例接口,post请求,请求body可为空<br>POST&nbsp;<a href="https://api.midukanshu.com/logstash/userbehavior/report" rel="nofollow" target="_blank" style="color: rgb(0, 0, 0);">https://api.midukanshu.com/logstash/userbehavior/report</a><br>返回:<br>{"code":0,"message":"成功","currentTime":1543386393,"data":[]}</p><h2 id="一、    Wrk" style="margin-top: 10px; margin-bottom: 10px; font-size: 21px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">一、 Wrk</h2><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">wrk是一款现代化的HTTP性能测试工具,即使运行在单核CPU上也能产生显著的压力。最大的优点是它支持多线程,这样更容易发挥多核 CPU 的能力,从而更容易测试出系统的极限能力。</p><h3 id="安装" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">安装</h3><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">git clone&nbsp;<a href="https://github.com/wg/wrk.git" rel="nofollow" target="_blank" style="color: rgb(0, 0, 0);">https://github.com/wg/wrk.git</a><br>cd wrk/<br>make</p><h3 id="查看版本" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">查看版本</h3><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">./wrk -v</p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/3d9daaad-9401-48a7-9f71-5a9fa3955dbb.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img src="https://testerhome.com/uploads/photo/2018/3d9daaad-9401-48a7-9f71-5a9fa3955dbb.png!large" alt="" width="350px" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><h3 id="参数说明" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">参数说明</h3><pre class="highlight java" style="margin: 10px auto; overflow: auto; color: rgb(0, 0, 0); font-size: 15px;"><code class="hljs" style="padding: 5px; background: rgb(245, 245, 245); display: block; font-family: &quot;Courier New&quot;, sans-serif; border: 1px solid rgb(204, 204, 204); border-radius: 3px; overflow-x: auto;">-c:总的连接数(每个线程处理的连接数=总连接数/线程数)
-d:测试的持续时间,如<span class="hljs-number">2</span>s(<span class="hljs-number">2</span>second),<span class="hljs-number">2</span>m(<span class="hljs-number">2</span>minute),<span class="hljs-number">2</span>h(hour),默认为s
-t:需要执行的线程总数,默认为<span class="hljs-number">2</span>,一般线程数不宜过多. 核数的<span class="hljs-number">2</span>到<span class="hljs-number">4</span>倍足够了. 多了反而因为线程切换过多造成效率降低
-s:执行Lua脚本,这里写lua脚本的路径和名称,后面会给出案例
-H:需要添加的头信息,注意header的语法,举例,-H “token: abcdef”
—timeout:超时的时间
—latency:显示延迟统计信息
</code></pre><h3 id="返回结果" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">返回结果</h3><pre class="highlight java" style="margin: 10px auto; overflow: auto; color: rgb(0, 0, 0); font-size: 15px;"><code class="hljs" style="padding: 5px; background: rgb(245, 245, 245); display: block; font-family: &quot;Courier New&quot;, sans-serif; border: 1px solid rgb(204, 204, 204); border-radius: 3px; overflow-x: auto;">Latency:响应时间
Req/Sec:每个线程每秒钟的执行的连接数
Avg:平均
Max:最大
Stdev:标准差
+/- Stdev: 正负一个标准差占比
Requests/sec:每秒请求数(也就是QPS),等于总请求数/测试总耗时
Latency Distribution,如果命名中添加了—latency就会出现相关信息
</code></pre><h3 id="运行" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">运行</h3><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">./wrk -t 5 -c 300 -d 60 --latency&nbsp;<a href="https://api.midukanshu.com/logstash/userbehavior/create" rel="nofollow" target="_blank" style="color: rgb(0, 0, 0);">https://api.midukanshu.com/logstash/userbehavior/create</a></p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/4dabe261-8ad5-4efe-86da-a6c18bc9e507.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img title="" src="https://testerhome.com/uploads/photo/2018/4dabe261-8ad5-4efe-86da-a6c18bc9e507.png!large" alt="" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><br>300个连接数跑60秒:Request/sec(每秒请求数):3322.48</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">./wrk -t 5 -c 500 -d 60 --latency&nbsp;<a href="https://api.midukanshu.com/logstash/userbehavior/create" rel="nofollow" target="_blank" style="color: rgb(0, 0, 0);">https://api.midukanshu.com/logstash/userbehavior/create</a></p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/218dc7e7-8b64-43b1-96c1-9eccc9aeedf0.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img title="" src="https://testerhome.com/uploads/photo/2018/218dc7e7-8b64-43b1-96c1-9eccc9aeedf0.png!large" alt="" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><br>500个连接数跑60秒:Request/sec(每秒请求数):3321.67</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">可见连接数从300加到500,QPS没有明显变化,就没有再往上加的必要了,再加也只会花更多的时间去坐线程的切换,QPS不一定上升,而且300个连接数时CPU已经跑满,后面会有截图说明</p><blockquote style="margin-top: 10px; margin-bottom: 10px; padding: 10px 60px 5px; background-image: url(&quot;images/comment.gif&quot;); background-position: 25px 0px; background-size: initial; background-repeat: no-repeat; background-attachment: initial; background-origin: initial; background-clip: initial; border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(226, 223, 223); border-image: initial; color: rgb(51, 51, 51); min-height: 35px; line-height: 1.6em; font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><p style="margin: 10px auto;">如果post请求的body不为空则指定lua文件进行读取,示例如下:<br>./wrk -t 5 -c 300 -d 60 --script=post.lua --latency&nbsp;<a href="https://api.midukanshu.com/logstash/userbehavior/create" rel="nofollow" target="_blank" style="color: rgb(0, 0, 0);">https://api.midukanshu.com/logstash/userbehavior/create</a><br>post.lua文件内容<br>wrk.method = "POST"<br>wrk.body = ""<br>wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"</p></blockquote><h2 id="二、    Apache Benchmark" style="margin-top: 10px; margin-bottom: 10px; font-size: 21px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">二、 Apache Benchmark</h2><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">Apache Benchmark简称 ab,是apache自带的压力测试工具</p><h3 id="安装:" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">安装:</h3><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">sudo yum install httpd-tools</p><h3 id="查看版本:" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">查看版本:</h3><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">ab -V</p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/a31e569c-7645-4eb1-b176-913f9d5afbf9.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img src="https://testerhome.com/uploads/photo/2018/a31e569c-7645-4eb1-b176-913f9d5afbf9.png!large" alt="" width="500px" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><h3 id="参数说明" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">参数说明</h3><pre class="highlight java" style="margin: 10px auto; overflow: auto; color: rgb(0, 0, 0); font-size: 15px;"><code class="hljs" style="padding: 5px; background: rgb(245, 245, 245); display: block; font-family: &quot;Courier New&quot;, sans-serif; border: 1px solid rgb(204, 204, 204); border-radius: 3px; overflow-x: auto;">-n 表示请求总数(与-t参数可任选其一)
-c 表示并发数
-t 标识请求时间
-p:模拟post请求,文件格式为gid=<span class="hljs-number">2</span>&amp;status=<span class="hljs-number">1</span>,配合-T使用
-T:post数据所使用的Content-Type头信息,如-T <span class="hljs-string" style="color: rgb(163, 21, 21);">'application/x-www-form-urlencoded'</span>
</code></pre><h3 id="返回结果" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">返回结果</h3><pre class="highlight java" style="margin: 10px auto; overflow: auto; color: rgb(0, 0, 0); font-size: 15px;"><code class="hljs" style="padding: 5px; background: rgb(245, 245, 245); display: block; font-family: &quot;Courier New&quot;, sans-serif; border: 1px solid rgb(204, 204, 204); border-radius: 3px; overflow-x: auto;">Server Software:      nginx/<span class="hljs-number">1.13</span>.<span class="hljs-number">6</span>   #测试服务器的名字
Server Hostname:      api.midukanshu.com#请求的URL主机名
Server Port:            <span class="hljs-number">443</span>             #web服务器监听的端口

Document Path:          /logstash/userbehavior/create  #请求的URL中的根绝对路径
Document Length:      <span class="hljs-number">0</span> bytes       #HTTP响应数据的正文长度

Concurrency Level:      <span class="hljs-number">300</span>        # 并发用户数,这是我们设置的参数之一
Time taken <span class="hljs-keyword" style="color: rgb(0, 0, 255);">for</span> tests:   <span class="hljs-number">22.895</span> seconds   #所有这些请求被处理完成所花费的总时间
Complete requests:      <span class="hljs-number">50000</span>       # 总请求数量,这是我们设置的参数之一
Failed requests:         <span class="hljs-number">99</span>        # 表示失败的请求数量,这里的失败是指请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况
Write errors:         <span class="hljs-number">0</span>
Total transferred:      <span class="hljs-number">96200</span> bytes    #所有请求的响应数据长度总和。包括每个HTTP响应数据的头信息和正文数据的长度
HTML transferred:       <span class="hljs-number">79900</span> bytes    # 所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度
Requests per second:    <span class="hljs-number">2183.91</span> [#/sec] (mean) #吞吐率,计算公式:Complete requests/Time taken <span class="hljs-keyword" style="color: rgb(0, 0, 255);">for</span> tests总请求数/处理完成这些请求数所花费的时间
Time per request:       <span class="hljs-number">137.368</span> (mean)   # 用户平均请求等待时间,计算公式:Time token <span class="hljs-keyword" style="color: rgb(0, 0, 255);">for</span> tests/(Complete requests/Concurrency Level)。处理完成所有请求数所花费的时间/(总请求数/并发用户数)
Time per request:       <span class="hljs-number">0.458</span> (mean, across all concurrent requests) #服务器平均请求等待时间,计算公式:Time taken <span class="hljs-keyword" style="color: rgb(0, 0, 255);">for</span> tests/Complete requests,正好是吞吐率的倒数。也可以这么统计:Time per request/Concurrency Level
Transfer rate:          <span class="hljs-number">652.50</span> received#表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Time taken <span class="hljs-keyword" style="color: rgb(0, 0, 255);">for</span> tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。
</code></pre><h3 id="运行" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">运行</h3><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">ab -c 300 -t 60&nbsp;<a href="https://api.midukanshu.com/logstash/userbehavior/create" rel="nofollow" target="_blank" style="color: rgb(0, 0, 0);">https://api.midukanshu.com/logstash/userbehavior/create</a></p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/d667892f-1504-4edb-a5e7-a7ecf013d362.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img src="https://testerhome.com/uploads/photo/2018/d667892f-1504-4edb-a5e7-a7ecf013d362.png!large" alt="" width="500px" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">300线程跑60秒:Requests per second=2301.68</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">ab -c 500 -t 60&nbsp;<a href="https://api.midukanshu.com/logstash/userbehavior/create" rel="nofollow" target="_blank" style="color: rgb(0, 0, 0);">https://api.midukanshu.com/logstash/userbehavior/create</a></p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/b40e8178-4650-47c9-9bdb-d9933309c77d.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img src="https://testerhome.com/uploads/photo/2018/b40e8178-4650-47c9-9bdb-d9933309c77d.png!large" alt="" width="500px" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">500线程跑60秒:Requests per second=2279.27</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">可见线程数加到500,还不如300的了,所以有时候线程数不是加的越高越好,更根据服务器的配置,CPU,IO,带宽等的消耗设置合理的线程数<br>细心的读者可能看出,我虽然设置了-t参数为60s,但实际只运行了20多秒,因为ab跑满50000个request就自己停了,想跑够60s可以使用-n参数</p><blockquote style="margin-top: 10px; margin-bottom: 10px; padding: 10px 60px 5px; background-image: url(&quot;images/comment.gif&quot;); background-position: 25px 0px; background-size: initial; background-repeat: no-repeat; background-attachment: initial; background-origin: initial; background-clip: initial; border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(226, 223, 223); border-image: initial; color: rgb(51, 51, 51); min-height: 35px; line-height: 1.6em; font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><p style="margin: 10px auto;">如果post请求的body不为空则指定文件进行读取,示例如下:<br>ab -n 100 -c 10 -p 'post.txt' -T 'application/x-www-form-urlencoded' '<a href="http://test.api.com/ttk/auth/info/" rel="nofollow" target="_blank" style="color: rgb(0, 0, 0);">http://test.api.com/ttk/auth/info/</a>'<br>post.txt文件内容<br>devices=4&amp;status=1</p></blockquote><h2 id="三、    Locust" style="margin-top: 10px; margin-bottom: 10px; font-size: 21px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">三、 Locust</h2><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">Locust是一个Python编写的分布式的性能测试工具</p><h3 id="安装" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">安装</h3><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">安装python pip<br>sudo yum -y install python-pip<br>通过Python自带的pip安装locust<br>pip install locustio</p><h3 id="查看版本:" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">查看版本:</h3><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">locust –version</p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/0574ecaa-c061-4118-8290-6f51782cff10.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img src="https://testerhome.com/uploads/photo/2018/0574ecaa-c061-4118-8290-6f51782cff10.png!large" alt="" width="500px" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><h3 id="参数说明" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">参数说明</h3><pre class="highlight java" style="margin: 10px auto; overflow: auto; color: rgb(0, 0, 0); font-size: 15px;"><code class="hljs" style="padding: 5px; background: rgb(245, 245, 245); display: block; font-family: &quot;Courier New&quot;, sans-serif; border: 1px solid rgb(204, 204, 204); border-radius: 3px; overflow-x: auto;">--host指定被测试的主机,采用以格式:http:<span class="hljs-comment" style="color: rgb(0, 128, 0);">//192.168.21.25</span>
-f指定运行 Locust 性能测试文件,默认为: locustfile.py
–-no-web    no-web 模式运行测试,需要 -c 和 -r 配合使用
-c指定并发用户数,作用于 –no-web 模式。
-r指定每秒启动的用户数,作用于 –no-web 模式。
-t设置运行时间, 例如: (<span class="hljs-number">300</span>s, <span class="hljs-number">20</span>m, <span class="hljs-number">3</span>h, <span class="hljs-number">1</span>h30m). 作用于 –no-web 模式。
</code></pre><h3 id="返回结果" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">返回结果</h3><pre class="highlight java" style="margin: 10px auto; overflow: auto; color: rgb(0, 0, 0); font-size: 15px;"><code class="hljs" style="padding: 5px; background: rgb(245, 245, 245); display: block; font-family: &quot;Courier New&quot;, sans-serif; border: 1px solid rgb(204, 204, 204); border-radius: 3px; overflow-x: auto;">Name:请求方式,请求路径;
reqs:当前请求的数量;
fails:当前请求失败的数量;
Avg:所有请求的平均响应时间,毫秒;
Min:请求的最小的服务器响应时间,毫秒;
Max:请求的最大服务器响应时间,毫秒;
Median:中间值,单位毫秒;
req/s:每秒钟请求的个数。
Total:各接口的汇总信息
</code></pre><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">运行:<br>Locust_demo.py文件内容</p><pre class="highlight java" style="margin: 10px auto; overflow: auto; color: rgb(0, 0, 0); font-size: 15px;"><code class="hljs" style="padding: 5px; background: rgb(245, 245, 245); display: block; font-family: &quot;Courier New&quot;, sans-serif; border: 1px solid rgb(204, 204, 204); border-radius: 3px; overflow-x: auto;"># coding=utf-<span class="hljs-number">8</span>
from locust <span class="hljs-keyword" style="color: rgb(0, 0, 255);">import</span> HttpLocust, TaskSet, <span class="hljs-function">task
class <span class="hljs-title" style="color: rgb(163, 21, 21);">UserBehavior</span><span class="hljs-params">(TaskSet)</span>:

    @<span class="hljs-title" style="color: rgb(163, 21, 21);">task</span><span class="hljs-params">(<span class="hljs-number">1</span>)</span>
    def <span class="hljs-title" style="color: rgb(163, 21, 21);">profile</span><span class="hljs-params">(self)</span>:
      self.client.<span class="hljs-title" style="color: rgb(163, 21, 21);">post</span><span class="hljs-params">(<span class="hljs-string" style="color: rgb(163, 21, 21);">"/logstash/userbehavior/report"</span>, {})</span>

class <span class="hljs-title" style="color: rgb(163, 21, 21);">WebsiteUser</span><span class="hljs-params">(HttpLocust)</span>:
    task_set </span>= UserBehavior
    min_wait = <span class="hljs-number">0</span>
    max_wait = <span class="hljs-number">0</span>
</code></pre><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">locust -f locust_demo.py --host=<a href="https://api.midukanshu.com/" rel="nofollow" target="_blank" style="color: rgb(0, 0, 0);">https://api.midukanshu.com</a>&nbsp;--no-web -c 300 -t 60s</p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/4cfdbde9-0a42-4797-9fd7-c262f62fed8e.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img title="" src="https://testerhome.com/uploads/photo/2018/4cfdbde9-0a42-4797-9fd7-c262f62fed8e.png!large" alt="" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><br>300线程跑60秒:Req/s=730.10</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">locust -f locust_demo.py --host=<a href="https://api.midukanshu.com/" rel="nofollow" target="_blank" style="color: rgb(0, 0, 0);">https://api.midukanshu.com</a>&nbsp;--no-web -c 500 -t 60s</p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/acce4762-f6e9-4964-bd2f-8cbf2dfed94f.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img title="" src="https://testerhome.com/uploads/photo/2018/acce4762-f6e9-4964-bd2f-8cbf2dfed94f.png!large" alt="" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><br>500线程跑60秒:Req/s=741.50</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><h2 id="四、    Jmeter" style="margin-top: 10px; margin-bottom: 10px; font-size: 21px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">四、 Jmeter</h2><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">Apache JMeter是Apache组织开发的基于Java的压力测试工具</p><h3 id="安装" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">安装</h3><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">安装jdk:yum -y list java<br>yum install -y java-1.8.0-openjdk-devel.x86_64<br>配置Java环境变量后执行java -version</p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/c0dccae3-666d-440a-9ddb-a84b658886d8.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img src="https://testerhome.com/uploads/photo/2018/c0dccae3-666d-440a-9ddb-a84b658886d8.png!large" alt="" width="500px" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">下载:apache-jmeter-3.2.tgz<br>然后解压到当前传的目录<br>tar zxvf apache-jmeter-3.2.tgz jmeter</p><h3 id="查看版本:" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">查看版本:</h3><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">见jmeter主目录</p><h3 id="参数说明:" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">参数说明:</h3><pre class="highlight java" style="margin: 10px auto; overflow: auto; color: rgb(0, 0, 0); font-size: 15px;"><code class="hljs" style="padding: 5px; background: rgb(245, 245, 245); display: block; font-family: &quot;Courier New&quot;, sans-serif; border: 1px solid rgb(204, 204, 204); border-radius: 3px; overflow-x: auto;">-n : 非GUI 模式执行JMeter
-t : 执行测试文件所在的位置及文件名
-r : 远程将所有agent启动,用在分布式测试场景下,不是分布式测试只是单点就不需要-r
-l : 指定生成测试结果的保存文件, jtl 文件格式
-e : 测试结束后,生成测试报告
-o : 指定测试报告的存放位置
</code></pre><h3 id="返回结果:" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">返回结果:</h3><pre class="highlight java" style="margin: 10px auto; overflow: auto; color: rgb(0, 0, 0); font-size: 15px;"><code class="hljs" style="padding: 5px; background: rgb(245, 245, 245); display: block; font-family: &quot;Courier New&quot;, sans-serif; border: 1px solid rgb(204, 204, 204); border-radius: 3px; overflow-x: auto;">Avg:所有请求的平均响应时间,毫秒;
Min:请求的最小的服务器响应时间,毫秒;
Max:请求的最大服务器响应时间,毫秒;
Err:请求错误个数,错误百分率;
Active:激活的线程数,当Active=<span class="hljs-number">0</span>,则说明运行中的线程数为<span class="hljs-number">0</span>,则压测结束。
Started:启动的线程数
Finished:完成的线程数
</code></pre><h3 id="运行脚本:" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">运行脚本:</h3><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">./jmeter.sh -n -t ./jmx/userbehavior_report.jmx<br>300个线程跑60秒:</p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/f6c05d47-7262-411f-b248-4646bb4321cb.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img title="" src="https://testerhome.com/uploads/photo/2018/f6c05d47-7262-411f-b248-4646bb4321cb.png!large" alt="" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">Summary + 398526 in 00:00:18 =21959.8/s<br>Summary = 1018846 in 00:01:04 =15904.6/s<br>Summary =表示总共运行1分04秒,请求了1018846个接口,这1分04秒内的QPS=15904.6/s<br>Summary +表示统计最近18秒,请求了398526个接口,即00:00:46到00:01:04期间的18秒,QPS=21959.8/s<br>500个线程跑60秒:<br>到这差不多了,500线程跑出来也没300的QPS高,就不放图了</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">总结:<br>300线程跑60秒, 对比各压测工具的 QPS:<br>Wrk=3322.48/s<br>Ab=2301.68/s<br>Locust= 730.10/s<br>Jmeter=21959.8/s<br>我曾以为的压测结果是:wrk &gt; ab &gt; locust &gt; jmeter<br>实际结果是:jmeter &gt; wrk &gt; ab &gt; locust</p><h2 id="五、资源消耗对比" style="margin-top: 10px; margin-bottom: 10px; font-size: 21px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">五、资源消耗对比</h2><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">Top参数解释:</p><pre class="highlight java" style="margin: 10px auto; overflow: auto; color: rgb(0, 0, 0); font-size: 15px;"><code class="hljs" style="padding: 5px; background: rgb(245, 245, 245); display: block; font-family: &quot;Courier New&quot;, sans-serif; border: 1px solid rgb(204, 204, 204); border-radius: 3px; overflow-x: auto;">cpu状态
<span class="hljs-number">6.7</span>% us — 用户空间占用CPU的百分比。
<span class="hljs-number">0.4</span>% sy — 内核空间占用CPU的百分比。
<span class="hljs-number">0.0</span>% ni — 改变过优先级的进程占用CPU的百分比
<span class="hljs-number">92.9</span>% id — 空闲CPU百分比
<span class="hljs-number">0.0</span>% wa — IO等待占用CPU的百分比
<span class="hljs-number">0.0</span>% hi — 硬中断(Hardware IRQ)占用CPU的百分比
<span class="hljs-number">0.0</span>% si — 软中断(Software Interrupts)占用CPU的百分比
内存状态
<span class="hljs-number">8306544</span>k total — 物理内存总量(<span class="hljs-number">8</span>GB)
<span class="hljs-number">7775876</span>k used — 使用中的内存总量(<span class="hljs-number">7.7</span>GB)
<span class="hljs-number">530668</span>k free — 空闲内存总量(<span class="hljs-number">530</span>M)
<span class="hljs-number">79236</span>k buffers — 缓存的内存量 (<span class="hljs-number">79</span>M)
各进程(任务)的状态监控
PID — 进程id
USER — 进程所有者
PR — 进程优先级
NI — nice值。负值表示高优先级,正值表示低优先级
VIRT — 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
RES — 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
SHR — 共享内存大小,单位kb
S — 进程状态。D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程
%CPU — 上次更新到现在的CPU时间占用百分比
%MEM — 进程使用的物理内存百分比
TIME+ — 进程使用的CPU时间总计,单位<span class="hljs-number">1</span>/<span class="hljs-number">100</span>秒
COMMAND — 进程名称(命令名/命令行)
</code></pre><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">在top基本视图中,按键盘数字“1”,可监控每个逻辑CPU的状况:<br>可看出压测服务器有4个逻辑CPU</p><div class="fluidbox-wrap" style="color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><a class="zoom-image fluidbox" href="https://testerhome.com/uploads/photo/2018/9132d801-2a64-4d47-8ad1-8c7dd9868285.png!large" data-action="zoom" style="color: rgb(0, 0, 0);"><img title="" src="https://testerhome.com/uploads/photo/2018/9132d801-2a64-4d47-8ad1-8c7dd9868285.png!large" alt="" style="border-width: 0px; border-style: initial; max-width: 650px; height: auto;"></a><div class="fluidbox-ghost">&nbsp;</div></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">&nbsp;</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">300线程跑60秒CPU消耗如图:<br>Wrk=377.1%<br>Ab=99.7%<br>Locust= 100%<br>Jmeter=396.4%<br>如果服务器是多核CPU可能在下方看到有些进程CPU占用超过100%,这种一般是该进程使用了多核。<br>可以看出wrk和jmeter都超过100%,且jmeter的396/4=99%,即使用了服务器99%的性能,<br>在压力测试过程中,最好时刻留意哪些资源成为了瓶颈,比如:CPU 是不是跑满了,IO 是不是跑满了<br>查看0.0 wa这里,IO等待所占用的CPU时间的百分比,高过30%时IO压力高。</p><h2 id="比较结果:" style="margin-top: 10px; margin-bottom: 10px; font-size: 21px; line-height: 1.5; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">比较结果:</h2><div class="table-wrapper" style="overflow-x: auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><table class="table table-bordered table-striped" style="border-spacing: 0px; word-break: break-word;"><tbody><tr><th style="padding: 8px 14px; background-color: rgb(250, 250, 250); border: 1px solid rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">工具</th><th style="padding: 8px 14px; background-color: rgb(250, 250, 250); border: 1px solid rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">wrk</th><th style="padding: 8px 14px; background-color: rgb(250, 250, 250); border: 1px solid rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">ab</th><th style="padding: 8px 14px; background-color: rgb(250, 250, 250); border: 1px solid rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">locust</th><th style="padding: 8px 14px; background-color: rgb(250, 250, 250); border: 1px solid rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">jmeter</th></tr><tr><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">安装</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">简单</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">简单</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">依赖python</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">依赖jdk</td></tr><tr><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">场景压测</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">不支持</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">不支持</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">支持</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">支持</td></tr><tr><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">UI界面</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">无</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">无</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">有</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">有</td></tr><tr><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">脚本录制</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">无</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">无</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">无</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">利用本地ProxyServer或badboy</td></tr><tr><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">资源监控</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">无</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">无</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">无</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">通过JMeterPlugins插件和ServerAgent实现</td></tr><tr><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">报告分析</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">无</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">无</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">无</td><td style="padding: 8px 14px; border-color: rgb(192, 192, 192); border-collapse: collapse; min-width: 50px;">生成HTML报告</td></tr></tbody></table></div><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">虽然jmeter提供UI界面,但是其压测脚本也依赖UI界面,导致其无法在Linux服务器上直接编辑写脚本,只有编写好脚本后再传到Linux服务器。<br>关于对于压测工具的选择</p><blockquote style="margin-top: 10px; margin-bottom: 10px; padding: 10px 60px 5px; background-image: url(&quot;images/comment.gif&quot;); background-position: 25px 0px; background-size: initial; background-repeat: no-repeat; background-attachment: initial; background-origin: initial; background-clip: initial; border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(226, 223, 223); border-image: initial; color: rgb(51, 51, 51); min-height: 35px; line-height: 1.6em; font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><p style="margin: 10px auto;">如果你想做场景的压测,而不是单个接口的压测<br>可使用jmeter或locust,支持接口串联,接口body参数化,思考时间等复杂场景<br>如果你压测要求的并发比较高,需要使用分布式压测<br>可使用jmeter或locust<br>如果你关注接口的返回,多维度压测报告统计<br>jmeter,jmeter,jmeter<br>如果想尽快编写接口,只关注接口的发送,造成的QPS和错误率<br>可使用wrk或ab<br>实践中也可以选择自己熟悉的压测工具</p></blockquote><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">由于单台4核8G服务器对待测接口最高能造成2万的QPS,还是距离我需要的6万还有一定距离,这时候可以使用Jmeter的分布式压测</p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;"><br></p><p style="margin: 10px auto; color: rgb(0, 0, 0); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px;">来源:https://www.cnblogs.com/grizz/p/11570801.html</p><p></p>
页: [1]
查看完整版本: wrk,ab,locust,Jmeter 压测结果比较