测试方法

<p class="shortdesc">购买RDS-MySQL实例后,您可以参照本文对实例性能进行性能测试。</p> <section class="section prereq" id="test__prereq_hgq_tzt_ywb"><div class="tasklabel"><h2 class="doc-tairway">前提条件</h2></div> <ul class="ul" id="test__ul_upc_5zt_ywb"> <li class="li">您已成功创建RDS-MySQL实例,可参考<a class="xref" href="/ssr/help/database/MySQL/Guide.IM.CIns.CCom" target="_blank" rel="external noopener">创建常规实例</a>。</li> <li class="li">您已成功创建账号,可参考<a class="xref" href="/ssr/help/database/MySQL/Guide.Account.Create_Account" target="_blank" rel="external noopener">创建账号</a>。</li> <li class="li">您已成功创建数据库,可参考<a class="xref" href="/ssr/help/database/MySQL/Guide.Database.Create_Database" target="_blank" rel="external noopener">创建数据库</a>。</li> <li class="li">您已成功授权账号与数据库权限,可参考<a class="xref" href="/ssr/help/database/MySQL/Guide.Account.Modify_Permissions_PG" target="_blank" rel="external noopener">授权指定账号访问数据库</a>或<a class="xref" href="/ssr/help/database/MySQL/Guide.Database.Modify_Permissions" target="_blank" rel="external noopener">授权数据库允许指定账号访问</a>。</li> <li class="li">您已成功创建ECS,可参考<a class="xref" href="/ssr/help/compute/ecs/manual.Instance_Manage.Create_Instance" target="_blank" rel="external noopener">创建ECS</a>。</li> <li class="li">您已成功开通白名单,可参考<a class="xref" href="/ssr/help/database/MySQL/Guide.Security_Management.Create_Whitelist_PG" target="_blank" rel="external noopener">开通白名单</a>。</li> <li class="li">您<span class="ph" id="test___Hlk45713374">可以通过</span>ECS连接RDS-MySQL实例,可参考<a class="xref" href="/ssr/help/compute/ecs/manual.Instance_Manage.Login_Linux_Instance.Linux_Login_webpage" target="_blank" rel="external noopener">Linux系统连接</a>。</li> </ul> </section> <section class="section" id="test__section_ygt_kzt_ywb"><h2 class="doc-tairway">测试环境</h2> <ul class="ul" id="test__ul_fmt_nzt_ywb"> <li class="li"> <p class="p">区域:华东</p> </li> <li class="li"> <p class="p">可用区:可用区A </p> </li> <li class="li"> <p class="p">云服务器ECS:通用型g5.2xlarge.4(8核32GB)</p> </li> <li class="li"> <p class="p">操作系统:CentOS7.7-64Bit</p> </li> </ul> </section> <section class="section" id="test__section_qgf_hb5_ywb"><h2 class="doc-tairway">测试工具</h2> <p class="p">SysBench是一个跨平台且支持多线程的模块化基准测试工具,用于评估系统在运行高负载的数据库时,相关核心参数的性能表现。SysBench可以在不进行复杂的数据库基准设置,甚至在没有安装数据库的前提下,快速了解数据库系统的性能。本文以平安云ECS为例安装SysBench,如果您需要安装到其他操作系统,可参考SysBench 官方文档。</p> <p class="p">测试使用的是 SysBench 1.0 版本,登录ECS,执行如下命令进行安装:</p> <pre class="pre codeblock" id="test__codeblock_rzf_qb5_ywb"><code>yum install gcc gcc-c++ autoconf automake make libtool bzr mysql-devel git mysql yum -y install sysbench </code></pre> <div class="p">成功安装SysBench后,RDS-MySQL性能测试默认使用<code class="ph codeph">/usr/local/share/sysbench</code>目录下的压测脚本。您也可以使用源码目录<code class="ph codeph">sysbench/sysbench/tests/db</code>下的压测脚本。SysBench脚本中定义的常用压测模型如下:<table class="table" id="test__table_stc_ls5_ywb"><caption></caption><colgroup><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="test__table_stc_ls5_ywb__entry__1"> <p class="p">压测模型</p> </th> <th class="entry" id="test__table_stc_ls5_ywb__entry__2"> <p class="p">描述</p> </th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="test__table_stc_ls5_ywb__entry__1 "> <p class="p">bulk_inert.lua</p> </td> <td class="entry" headers="test__table_stc_ls5_ywb__entry__2 "> <p class="p">批量插入数据。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_stc_ls5_ywb__entry__1 "> <p class="p">oltp_insert.lua</p> </td> <td class="entry" headers="test__table_stc_ls5_ywb__entry__2 "> <p class="p">插入数据。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_stc_ls5_ywb__entry__1 "> <p class="p">oltp_delete.lua</p> </td> <td class="entry" headers="test__table_stc_ls5_ywb__entry__2 "> <p class="p">删除数据。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_stc_ls5_ywb__entry__1 "> <p class="p">oltp_read_write.lua</p> </td> <td class="entry" headers="test__table_stc_ls5_ywb__entry__2 "> <p class="p">混合读写测试,包含只读测试及只写测试。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_stc_ls5_ywb__entry__1 "> <p class="p">oltp_point_select.lua</p> </td> <td class="entry" headers="test__table_stc_ls5_ywb__entry__2 "> <p class="p">简单的主键查询。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_stc_ls5_ywb__entry__1 "> <p class="p">oltp_read_only.lua</p> </td> <td class="entry" headers="test__table_stc_ls5_ywb__entry__2 "> <p class="p">只读测试,包含简单范围、范围求和、排序查询、distinct查询。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_stc_ls5_ywb__entry__1 "> <p class="p">oltp_update_index.lua</p> </td> <td class="entry" headers="test__table_stc_ls5_ywb__entry__2 "> <p class="p">基于索引更新数据。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_stc_ls5_ywb__entry__1 "> <p class="p">oltp_update_non_index.lua</p> </td> <td class="entry" headers="test__table_stc_ls5_ywb__entry__2 "> <p class="p">不基于索引更新数据。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_stc_ls5_ywb__entry__1 "> <p class="p">oltp_write_only.lua</p> </td> <td class="entry" headers="test__table_stc_ls5_ywb__entry__2 "> <p class="p">只写测试,包含更新数据测试及删除数据测试。</p> </td> </tr> </tbody></table></div> </section> <section class="section" id="test__section_dnd_l55_ywb"><h2 class="doc-tairway">测试指标</h2> <ul class="ul" id="test__ul_i55_l55_ywb"> <li class="li"> <p class="p">TPS(Transactions Per Second):数据库每秒执行的事务数,以COMMIT成功次数为准。</p> </li> <li class="li"> <p class="p">QPS(Queries Per Second):数据库每秒执行的SQL语句数,包含INSERT、SELECT、UPDATE、DELETE等。</p> </li> </ul> </section> <section><div class="tasklabel"><h2 class="doc-tairway">操作步骤</h2></div><ol class="ol steps"><li class="li step stepexpand"> <span class="ph cmd">登录ECS,进入压测脚本所在的目录。</span> </li><li class="li step stepexpand"> <span class="ph cmd">执行如下命令,导入测试数据。 </span> <div class="itemgroup info"> <pre class="pre codeblock" id="test__codeblock_l41_bt5_ywb"><code>sysbench --time=3600 --events=999999999 --mysql-host=xxx --mysql-port=<port> --mysql-user=<user> --mysql-password=<password> --mysql-db=dbtest --db-driver=mysql --tables=64 --threads=20 --table_size=10000000 oltp_read_write.lua prepare</code></pre> </div> </li><li class="li step stepexpand"> <span class="ph cmd">执行如下命令,压测性能。 </span> <div class="itemgroup info"> <pre class="pre codeblock" id="test__codeblock_ppx_bt5_ywb"><code>sysbench --time=3600 --events=999999999 --mysql-host=xxx --mysql-port=<port> --mysql-user=<user> --mysql-password=<password> --mysql-db=dbtest --db-driver=mysql --tables=64 --threads=20 --table_size=10000000 --report-interval=10 oltp_read_write.lua run</code></pre> </div> </li><li class="li step stepexpand"> <span class="ph cmd">执行如下命令,清理环境。 </span> <div class="itemgroup info"> <pre class="pre codeblock" id="test__codeblock_ljk_nt5_ywb"><code>sysbench --time=3600 --events=999999999 --mysql-host=xxx --mysql-port=<port> --mysql-user=<user> --mysql-password=<password> --mysql-db=dbtest --db-driver=mysql --tables=64 --threads=20 --table_size=10000000 oltp_read_write.lua cleanup</code></pre> <div class="p">以上命令中,参数解释如下:<table class="table" id="test__table_d4q_st5_ywb"><caption></caption><colgroup><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="test__table_d4q_st5_ywb__entry__1"> <p class="p">参数</p> </th> <th class="entry" id="test__table_d4q_st5_ywb__entry__2"> <p class="p">说明</p> </th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="test__table_d4q_st5_ywb__entry__1 "> <p class="p">time</p> </td> <td class="entry" headers="test__table_d4q_st5_ywb__entry__2 "> <p class="p">测试时间。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_d4q_st5_ywb__entry__1 "> <p class="p">events</p> </td> <td class="entry" headers="test__table_d4q_st5_ywb__entry__2 "> <p class="p">测试的请求数量。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_d4q_st5_ywb__entry__1 "> <p class="p">mysql-host</p> </td> <td class="entry" headers="test__table_d4q_st5_ywb__entry__2 "> <p class="p">实例的访问域名,可参考<a class="xref" href="/ssr/help/database/MySQL/Guide.IM.ViewIns.View_Common_Instance" target="_blank" rel="external noopener">查看实例基本信息</a>。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_d4q_st5_ywb__entry__1 "> <p class="p">mysql-port</p> </td> <td class="entry" headers="test__table_d4q_st5_ywb__entry__2 "> <p class="p">实例的连接端口,可参考<a class="xref" href="/ssr/help/database/MySQL/Guide.IM.ViewIns.View_Common_Instance" target="_blank" rel="external noopener">查看实例基本信息</a>。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_d4q_st5_ywb__entry__1 "> <p class="p">mysql-user</p> </td> <td class="entry" headers="test__table_d4q_st5_ywb__entry__2 "> <p class="p">连接实例的账号,可参考<a class="xref" href="/ssr/help/database/MySQL/Guide.Account.Create_Account" target="_blank" rel="external noopener">创建账号</a>。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_d4q_st5_ywb__entry__1 "> <p class="p">mysql-password</p> </td> <td class="entry" headers="test__table_d4q_st5_ywb__entry__2 "> <p class="p">创建账号时设置的密码,可参考<a class="xref" href="/ssr/help/database/MySQL/Guide.Account.Create_Account" target="_blank" rel="external noopener">创建账号</a>。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_d4q_st5_ywb__entry__1 "> <p class="p">mysql-db</p> </td> <td class="entry" headers="test__table_d4q_st5_ywb__entry__2 "> <p class="p">实例中创建的数据库,可参考<a class="xref" href="/ssr/help/database/MySQL/Guide.Database.Create_Database" target="_blank" rel="external noopener">创建数据库</a>。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_d4q_st5_ywb__entry__1 "> <p class="p">db-driver</p> </td> <td class="entry" headers="test__table_d4q_st5_ywb__entry__2 "> <p class="p">数据库引擎。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_d4q_st5_ywb__entry__1 "> <p class="p">tables</p> </td> <td class="entry" headers="test__table_d4q_st5_ywb__entry__2 "> <p class="p">测试的表数量。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_d4q_st5_ywb__entry__1 "> <p class="p">threads</p> </td> <td class="entry" headers="test__table_d4q_st5_ywb__entry__2 "> <p class="p">测试的线程数。</p> </td> </tr> <tr class="row"> <td class="entry" headers="test__table_d4q_st5_ywb__entry__1 "> <p class="p">table_size</p> </td> <td class="entry" headers="test__table_d4q_st5_ywb__entry__2 "> <p class="p">测试的表大小。</p> </td> </tr> </tbody></table></div> </div> </li></ol></section>
以上内容是否解决了您的问题?
请补全提交信息!
联系我们

电话咨询

400-151-8800

邮件咨询

fincloud@ocft.com

在线客服

工单支持

解决云产品相关技术问题