Docs/linux基础/优化Haproxy/4.html
2022-10-18 16:59:37 +08:00

169 lines
No EOL
9.1 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>4</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">4</h1>
<div class="content-html" id="leanote-content"><h2>Apache Bench遇到的问题</h2><p>虽然通过Apache Bench我们获取了很多结果数据但同时也遇到了很多问题。这里不会说明所有遇到的问题因为这不是本文的终点而且后面将会介绍新的压测客户端。</p><p>我们对从Apache Bench获取到了不错的结果数据但是每次获取一个点数据时TCP连接数这个要求总是难以达到。不知道为何Apache Bench无法正确处理前面提到的sleep参数同时也还是没法满足我们对容量的需求。</p><p>前面提到了我们在单台施压机上通过Parallel工具并行执行多个ab客户端但这种方式无法跨多台施压机。当时还没有发现<a href="https://github.com/grondo/pdsh" data-mce-href="https://github.com/grondo/pdsh">pdsh</a>这个工具,也算是一个遗憾。</p><p>同时之前的数据我们还缺少超时数据。在HAProxy上我们会有一些默认的超时设置但是ab客户端和后端服务完全忽略了这些配置。对此我们花了大量时间进行这方面的研究试图修正压力测试的方案。</p><p>前面提到过拐点图,但是随着各种问题的出现,目标有所偏移。但是,为了获取有意义的结论,必须重新聚焦于此。</p><p>通过Apache Bench我们获得了拐点但是TCP连接数一直没有上升。这些数据基于5到6台施压机上运行的大约40到45个ab客户端获得但是TCP连接数一直没能够达到期望的量级。理论上随着sleep参数值的上升TCP连接数应该会上升但是事实上却没有效果。</p><h2>引入Vegeta</h2><p>基于使用Apache Bench所遇到的问题我继续搜索其他功能更为强大、更易扩容的压力测试工具最终找到了<a href="https://github.com/tsenart/vegeta" data-mce-href="https://github.com/tsenart/vegeta">Vegeta</a></p><p>从我个人经验来看Vegeta相比于Apache Bench非常易扩容并且提供了更多的功能。在我们的压力测试场景中一个Vegeta客户端可以产生相当于15个Apache Bench客户端的吞吐量。</p><p>下面会介绍使用Vegeta获取到的压力测试结果。</p><h2>使用Vegeta进行压力测试</h2><p>首先来看下单个Vegeta客户端的使用命令。有趣的是其中用来向后端服务器施压的命令参数叫做<code>attack</code>&nbsp;:p</p><pre id="leanote_ace_1505975378362_0" class="brush:sh ace-tomorrow" data-mce-style="line-height: 1.5; font-size: 14px; height: 63px;">echo "POST https://test.haproxy.in:443/ping" | vegeta -cpus=
32 attack -duration=10m -header="sleep:30000" -body=
post_smaller.txt -rate=2000 -workers=500 | tee reports.bin | vegeta report</pre><p>这里我们简单了解下Vegeta提供的一些参数细节</p><ol><li><code>-cpus=32</code>定义客户端使用的内核数量。为了能够达到需要的压力值我们将施压机配置调整撑了32核64GB内存。仔细观察结果数据会发现实际压力并不大配置调整的主要目的是为了能够支撑大量状态为后端服务器休眠的连接。</li><li><code>-duration=10m</code>,该参数顾名思义,如果没有指定执行时间,测试将永久运行。</li><li><code>-rate=2000</code>,每秒钟请求数。</li></ol><p><img id="__LEANOTE_D_IMG_1505975405565" src="4_files/59c3ceadd01cce1c4d000030.png" alt="" width="550" data-mce-src="/api/file/getImage?fileId=59c3ceadd01cce1c4d000030"></p><p>从上图可以看出我们仅仅使用一台4核机器就达到了每秒32k个请求。这个结果比之前得出的拐点图有更高的性能这里针对非SSL请求的拐点在31.5k。</p><p>下面是更多压力测试的数据:</p><p><img id="__LEANOTE_D_IMG_1505975405566" src="4_files/59c3ceadd01cce1c4d000032.png" alt="" width="550" data-mce-src="/api/file/getImage?fileId=59c3ceadd01cce1c4d000032"></p><p>对于SSL连接来说每秒请求数16k也不算差了。由于更换了新的客户端整个压力测试过程都需要从头开始但是从整体来看结果都优于ab客户端的结果。&nbsp;<img id="__LEANOTE_D_IMG_1505975425862" src="4_files/59c3ceadd01cce1c4d00002f.png" alt="" width="550" data-mce-src="/api/file/getImage?fileId=59c3ceadd01cce1c4d00002f"></p><p>随着CPU内核数的增加在相同压力下响应延迟都有所降低直到压力达到CPU性能极限。</p><p>但是我们发现当CPU内核数从8增加到16的时候每秒请求数没有太多的增长。不过如果我们最终决定在生产环境使用8核机器也不可能将所有核心都分配给HAProxy而不被其他任何进程占用。因此我们决定使用6核心进行一些测试验证是否可以接受性能结果。&nbsp;</p><p><img id="__LEANOTE_D_IMG_1505975425863" src="4_files/59c3ceadd01cce1c4d000033.png" alt="" width="550" data-mce-src="/api/file/getImage?fileId=59c3ceadd01cce1c4d000033"></p><p>也不差吧。</p><h2>引入sleep参数</h2><p>目前为止我们对于压力测试的结果非常满意。然而现在场景没有模拟真实生产环境场景直到引入了sleep参数。</p><pre id="leanote_ace_1505975458341_0" class="brush:sh ace-tomorrow" data-mce-style="line-height: 1.5; font-size: 14px; height: 63px;">echo "POST https://test.haproxy.in:443/ping" | vegeta
-cpus=32 attack -duration=10m -header="sleep:1000"
-body=post_smaller.txt-rate=2000 -workers=500 | tee reports.bin | vegeta report</pre><p>上述命令设置了1000毫秒的休眠时间会让服务端应用随机休眠0到1000毫秒。因此上述命令的平均延迟是≥ 500ms。</p><p>&nbsp;<img id="__LEANOTE_D_IMG_1505975471693" src="4_files/59c3ceadd01cce1c4d000031.png" alt="" width="550" data-mce-src="/api/file/getImage?fileId=59c3ceadd01cce1c4d000031"></p><p>最后一个单元格中的数字分别表示:</p><pre>TCP连接建立数包发送数包接收数<br></pre></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>