测试方法
<p class="shortdesc">购买DRDS实例后,您可以参照本文对实例性能进行性能测试。</p>
<section class="section" id="pwp__section_zpf_21v_ywb"><h2 class="doc-tairway">测试环境</h2>
<p class="p">所有测试均在华东/华南地域的可用区完成。</p>
</section>
<section class="section" id="pwp__section_m4d_f1v_ywb"><h2 class="doc-tairway">测试工具</h2>
<p class="p">SysBench是一个跨平台且支持多线程的模块化基准测试工具,用于评估系统在运行高负载的数据库时相关核心参数的性能表现。它目的是为了绕过复杂的数据库基准设置,甚至在没有安装数据库的前提下,快速了解数据库系统的性能。</p>
<p class="p"><strong class="ph b">安装方法</strong></p>
<p class="p">测试使用的是 SysBench 1.0 版本,安装命令如下,详细安装方法请参考 SysBench 官方文档。</p>
<div class="p">
<pre class="pre codeblock" id="pwp__codeblock_bkn_m1v_ywb"><code>git clone https://github.com/akopytov/sysbench.git
git checkout 1.0
yum -y install make automake libtool pkgconfig libaio-devel
yum -y install mariadb-devel
./autogen.sh
./configure
make -j
make install
</code></pre>
</div>
<p class="p">安装完毕后,所有自带压测脚本都在 /usr/local/share/sysbench 目录下,DRDS 性能测试将使用该目录下的脚本。除此之外,也可以在源码目录
sysbench/sysbench/tests/db 下找到对应的压测脚本。</p>
</section>
<section class="section" id="pwp__section_syb_q1v_ywb"><h2 class="doc-tairway">测试命令及参数</h2>
<p class="p"><strong class="ph b">测试命令</strong></p>
<p class="p">使用 Sysbench 进行压测,通常分为三个步骤:</p>
<ol class="ol" id="pwp__ol_lqm_51v_ywb">
<li class="li">
<p class="p">prepare,准备数据</p>
</li>
<li class="li">
<p class="p">run,运行测试模型</p>
</li>
<li class="li">
<p class="p">cleanup,清理测试数据</p>
</li>
</ol>
<p class="p">通常仅需准备一次数据,在此数据基础上测试各种模型即可。</p>
<p class="p"><strong class="ph b">常用参数</strong></p>
<p class="p">Sysbench 中常用的参数如下:</p>
<table class="table" id="pwp__table_ycc_2v5_ywb"><caption></caption><colgroup><col><col><col></colgroup><thead class="thead">
<tr class="row">
<th class="entry" id="pwp__table_ycc_2v5_ywb__entry__1">
<p class="p">序号</p>
</th>
<th class="entry" id="pwp__table_ycc_2v5_ywb__entry__2">
<p class="p">参数</p>
</th>
<th class="entry" id="pwp__table_ycc_2v5_ywb__entry__3">
<p class="p">说明</p>
</th>
</tr>
</thead><tbody class="tbody">
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">1</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">oltp-tables-count=1</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">表数量。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">2</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">oltp-table-size=10000000</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">每个表产生的记录行数。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">3</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">oltp-read-only=off</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">是否生成只读SQL。默认 off,如果设置为 on,则 oltp 模型不会生成 update、delete、insert 的
SQL 语句。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">4</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">oltp-skip-trx=[on|off]</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">省略 BEGIN / COMMIT 语句。默认是 off。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">5</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">rand-init=on</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">是否随机初始化数据。如果不随机化那么初始好的数据每行内容除了主键不同外其他完全相同。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">6</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">num-threads=12</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">并发线程数。即模拟的客户端并发连接数。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">7</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">report-interval=10</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">表示每 10s 输出一次性能数据。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">8</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">max-requests=0</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">压力测试产生请求的总数。如果以下面的 max-time 来记,这个值设为 0 即可。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">9</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">max-time=120</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">测试的持续时间。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">10</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">oltp_auto_inc=off</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">id 是否为自增列。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">11</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">oltp_secondary=on</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">id 是否为主键。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__1 ">
<p class="p">12</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__2 ">
<p class="p">oltp_range_size=5</p>
</td>
<td class="entry" headers="pwp__table_ycc_2v5_ywb__entry__3 ">
<p class="p">连续取值 5 个,必定走到 5 个分片。</p>
</td>
</tr>
</tbody></table>
</section>
<section class="section" id="pwp__section_etn_ycv_ywb"><h2 class="doc-tairway">测试设计</h2>
<ul class="ul" id="pwp__ul_ej2_zcv_ywb">
<li class="li">
<p class="p">购买DRDS、RDS实例。</p>
</li>
<li class="li">
<p class="p">DRDS目前有7种规格 :2C4G 、 4C8G 、 8C16G、 16C32G、32C64G、64C128G、128C256G。</p>
</li>
<li class="li">
<p class="p">RDS(3台):16C128G、MySQL 5.7、独享型。</p>
<div class="note note note_note" id="pwp__note_y2y_2dv_ywb"><span class="note__title">说明:</span> DRDS、RDS都处于同一可用区。</div>
</li>
<li class="li">
<p class="p">在DRDS控制台创建逻辑库,选择已经购买的3台RDS。</p>
</li>
<li class="li">
<p class="p">在DRDS控制台创建水平拆分表,选择已经购买的3台RDS。</p>
</li>
<li class="li">
<p class="p">安装Sysbench,并准备1亿数据。</p>
</li>
</ul>
</section>
<section class="section" id="pwp__section_z34_hdv_ywb"><h2 class="doc-tairway">测试参数说明</h2>
<table class="table" id="pwp__table_nmx_qv3_zwb"><caption></caption><colgroup><col><col><col></colgroup><thead class="thead">
<tr class="row">
<th class="entry" id="pwp__table_nmx_qv3_zwb__entry__1">
<p class="p">序号</p>
</th>
<th class="entry" id="pwp__table_nmx_qv3_zwb__entry__2">
<p class="p">参数</p>
</th>
<th class="entry" id="pwp__table_nmx_qv3_zwb__entry__3">
<p class="p">说明</p>
</th>
</tr>
</thead><tbody class="tbody">
<tr class="row">
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__1 ">
<p class="p">1</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__2 ">
<p class="p">test='/usr/local/share/sysbench/oltp_point_select.lua'</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__3 ">
<p class="p">脚本存放位置。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__1 ">
<p class="p">2</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__2 ">
<p class="p">oltp-table-size=100000000</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__3 ">
<p class="p">准备1亿数据。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__1 ">
<p class="p">3</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__2 ">
<p class="p">oltp_skip_trx=on</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__3 ">
<p class="p">跳过事务。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__1 ">
<p class="p">4</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__2 ">
<p class="p">oltp_range_size=1</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__3 ">
<p class="p">连续取值 1 个,必定走到 1 个分片。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__1 ">
<p class="p">5</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__2 ">
<p class="p">rand-init=on</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__3 ">
<p class="p">每个测试表都是用随机数据来填充的sysbench。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__1 ">
<p class="p">6</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__2 ">
<p class="p">num-threads=100</p>
</td>
<td class="entry" headers="pwp__table_nmx_qv3_zwb__entry__3 ">
<p class="p">具体每个场景的并发数。</p>
</td>
</tr>
</tbody></table>
</section>
<section class="section" id="pwp__section_ed2_cw3_zwb"><h2 class="doc-tairway">测试语句范例</h2>
<pre class="pre codeblock" id="pwp__codeblock_zd3_dw3_zwb"><code>sysbench --test='/usr/local/share/sysbench/oltp_point_select.lua'
--oltp_tables_count=10 --oltp-table-size=10000000 --mysql-user=**** --mysql-password=****
--mysql-table-engine=innodb --simple-ranges=1 --mysql-host=**** --mysql-port=3306 --mysql-db=****
--oltp_skip_trx=on --num-threads=100 --max-time=300 run</code></pre>
</section>
<section class="section" id="pwp__section_xd5_fw3_zwb"><h2 class="doc-tairway">测试指标</h2>
<p class="p">QPS(Queries Per Second):数据库每秒执行的SQL数(本测试按主键做等值查询操作)。</p>
</section>
提交成功!非常感谢您的反馈,我们会继续努力做到更好!