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

170 lines
No EOL
7.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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>3</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">3</h1>
<div class="content-html" id="leanote-content"><h2>HAProxy Nbproc配置</h2><p>刚开始对HAProxy进行压力测试的时候我们发现增加了SSL之后CPU使用率一下子就飙升但此时的每秒请求数却很低。通过<a href="http://www.tecmint.com/12-top-command-examples-in-linux/" data-mce-href="http://www.tecmint.com/12-top-command-examples-in-linux/">top命令</a>排查之后发现HAProxy只使用了1个CPU内核而我们的机器上还有15个空闲的内核。</p><p>通过Google发现HAProxy有一个设置可以使其充分利用多核。这个配置称为<code>nbproc</code>,详情及其具体配置可以参照这篇文章:</p><p><a href="http://blog.onefellow.com/post/82478335338/haproxy-mapping-process-to-cpu-core-for-maximum">http://blog.onefellow.com/post/82478335338/haproxy-mapping-process-to-cpu-core-for-maximum</a></p><p>这项配置调优使得后面的压力测试能够继续因为让HAProxy能够充分利用多核才能继续后续压力测试集中的各种混合场景。</p><h2>使用AB进行压力测试</h2><p>从这里开始正式进入压力测试环节,以后将不再赘述我们的度量数据和期望达到的指标。</p><p>刚开始我们的唯一目标是通过分析前面描述的ab命令参数变化找到性能拐点。&nbsp;</p><p><img id="__LEANOTE_D_IMG_1505975248438" src="3_files/59c3ceadd01cce1c4d00002d.png" alt="" width="550" data-mce-src="/api/file/getImage?fileId=59c3ceadd01cce1c4d00002d"></p><p>上表是我们进行了多次压力测试之后的结果数据。为了获得这样的结果我们进行了超过500次测试从数据上可以明显看出每次测试结果都有多项数据有变动。</p><h2>单客户端问题</h2><p>随着压力的逐渐增加我们发现施压客户端成了瓶颈。从Apache bench文档来看它在发起请求时只使用单核并且没有设置可以利用多核提升其性能。</p><p>为了能够提升客户端性能我们使用了Linux平台上的一个工具叫做<a href="http://www.shakthimaan.com/posts/2014/11/27/gnu-parallel/news.html" data-mce-href="http://www.shakthimaan.com/posts/2014/11/27/gnu-parallel/news.html">Parallel</a>。如果其名称一样该工具能够并行命令以充分利用CPU核心。这也是我们所期望的。以下是使用Parallel运行多个ab客户端的示例命令</p><pre id="leanote_ace_1505975287236_0" class="brush:sh ace-tomorrow">cat hosts.txt | parallel 'ab -S -p post_smaller.txt -T
application/json -n 100000 -c 3000 {}'
sachinm@ip-192-168-0-124:~$ cat hosts.txt
http://test.haproxy.in:80/ping
http://test.haproxy.in:80/ping
http://test.haproxy.in:80/ping</pre><p>上述命令可以并行运行3个ab客户端同时访问相同的URL。这样能够帮我我们解决客户端性能瓶颈。</p><h2>服务端的Sleep和Times参数</h2><p>前面我们提到了一些通过Ganglia收集的数据这里先来讨论下如何模拟这些数据的产生。</p><ol><li>发送和接收数据包数量。该数据可以通过POST请求中发送一些数据来模拟。该方式也能帮助提升带宽和收发字节数两项Ganglia数据项。</li><li>TCP连接建立数。为了模拟该数据着实让我们花了好多时间。试想如果一个请求响应时间是1秒需要大约每秒700k个请求才能达到我们预订的场景。这个数据在生产环境中很容易达到但是在我们的测试场景中却几乎不可能产生。</li></ol><p>这时候读者可能会问那么你们是怎么实现的呢我们在POST请求参数中引入了sleep参数可以通过该参数让服务端休眠特定毫秒之后再返回响应数据。这样能够模拟生产环境中的耗时请求。所以我们设置了休眠20分钟这样每秒请求数达到583个左右的时候就能够维持700k个连接数的水位。</p><p>除此之外我们还在向HAProxy发起POST请求的时候引入了另一个参数times。该参数可以指定服务端在关闭TCP连接之前响应数据的重复次数。这样能够帮助我们模拟产生更多的数据量。</p><p><br data-mce-bogus="1"></p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>