使用 JMeter 对 CassandraDB 进行负载测试
Load Testing CassandraDB with JMeter
我正在使用已集成到 apache-JMeter2.9 中的 Cassandra JMeter 插件https://github.com/slowenthal/jmeter-cassandra#cassandra-jmeter-plugin-for-cassandra
我有一个 Cassandra 集群,其中包含 2 个数据中心和每个数据中心上的 2 个节点。
JMeter:
卡桑德拉连接:
contact points : 192.168.1.50,192.168.1.51,192.168.1.52
keyspace : test_db
Cassandra 采样器
CQL Query : select * from test_db.feed_yogesh limit 1000;
Consistency Level : QUORUM
测试场景
1.Fetch 1 位用户 1000 条记录
User/Thread : 1
Ramp-Up-Period : 0
Generate Summary Results = 1 in 2.2s = 0.5/s Avg: 2180 Min: 2180 Max: 2180 Err: 0 (0.00%)
2.Fetch 1000 位用户 1000 条记录
我想同时测试多个用户,因此我将 Ramp-Up-period 添加为 0,根据 JMeter 将立即启动所有用户。
User/Thread : 1000
RampUp Period : 0
Summary Results = 1000 in 18s = 56.1/s Avg: 6857 Min: 5000 Max: 17044 Err: 987 (98.70%)
它确实启动了我所有的用户,但只有 4-5 个用户 return success rest all give me error such as
All host(s) tried for query failed (tried: /192.168.1.50:9042 (com.datastax.driver.core.BusyConnectionException))
但是当我测试同一个 1000 名用户时,给定的启动期为 300,它 return 全部成功。
User/Thread : 1000
RampUp Period : 300
Generate Summary Results = 1000 in 301s = 3.3/s Avg: 519 Min: 255 Max: 1811 Err: 0 (0.00%)
卡斯德拉 Sampler.jmx
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.4" jmeter="2.9 r1437961">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1000</stringProp>
<stringProp name="ThreadGroup.ramp_time">0</stringProp>
<longProp name="ThreadGroup.start_time">1420788860000</longProp>
<longProp name="ThreadGroup.end_time">1420788860000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
<hashTree>
<org.apache.cassandra.jmeter.config.CassandraConnection guiclass="TestBeanGUI" testclass="org.apache.cassandra.jmeter.config.CassandraConnection" testname="Cassandra Connection" enabled="true">
<stringProp name="contactPoints">192.168.1.50,192.168.1.51,192.168.1.52</stringProp>
<stringProp name="keyspace">test_db</stringProp>
<stringProp name="loadBalancer">Default</stringProp>
<stringProp name="localDataCenter"></stringProp>
<stringProp name="password"></stringProp>
<stringProp name="sessionName">mydatabase</stringProp>
<stringProp name="username"></stringProp>
</org.apache.cassandra.jmeter.config.CassandraConnection>
<hashTree/>
<org.apache.cassandra.jmeter.sampler.CassandraSampler guiclass="TestBeanGUI" testclass="org.apache.cassandra.jmeter.sampler.CassandraSampler" testname="Cassandra Sampler" enabled="true">
<stringProp name="batchSize"></stringProp>
<stringProp name="consistencyLevel">QUORUM</stringProp>
<stringProp name="query">select * from test_db.feed_yogesh limit 1000;</stringProp>
<stringProp name="queryArguments">Running</stringProp>
<stringProp name="queryType">Simple Statement</stringProp>
<stringProp name="resultVariable"></stringProp>
<stringProp name="sessionName">mydatabase</stringProp>
<stringProp name="variableNames">VARCHAR</stringProp>
</org.apache.cassandra.jmeter.sampler.CassandraSampler>
<hashTree/>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<ResultCollector guiclass="SummaryReport" testclass="ResultCollector" testname="Summary Report" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
我很疑惑,是不是说多个用户不能同时读取数据,是不是必须要加上Ramp-Up-Period值呢
加速期决定了用户应该上线或开始达到目标负载的时间范围。
您的结果显示,当您以 0 rampup 开始时,所有 1000 个用户同时启动(1000 个并发用户同时访问数据库)。结果显示只有少数用户 1% 通过,其余失败,如果没有进行适当的调整或数据库服务器没有足够的配置,这是预料之中的。
出现上述行为的原因可能是您的数据库服务器无法一次承受那么大的负载。它试图尽可能多地提供服务,但超出了某个限制,它就停止工作了。
但是,当您添加加速时,queries/users 达到分贝率是在分贝服务限制内,因此它可以服务。
您可以检查的是找出那些失败的瓶颈或原因。一些原因可能是,
- 低连接池
- 减少事务超时
- 低配置
- DB 上缺少调整参数
可能有很多原因,但请尝试调试和解决性能问题,然后以较低的加速重新测试(不建议 1000 位用户至少保持 5-10 秒为 0 秒)。如果你想让1000个用户同时命中一个点,有一个叫同步定时器的组件可以帮你。
我正在使用已集成到 apache-JMeter2.9 中的 Cassandra JMeter 插件https://github.com/slowenthal/jmeter-cassandra#cassandra-jmeter-plugin-for-cassandra
我有一个 Cassandra 集群,其中包含 2 个数据中心和每个数据中心上的 2 个节点。
JMeter:
卡桑德拉连接:
contact points : 192.168.1.50,192.168.1.51,192.168.1.52
keyspace : test_db
Cassandra 采样器
CQL Query : select * from test_db.feed_yogesh limit 1000;
Consistency Level : QUORUM
测试场景
1.Fetch 1 位用户 1000 条记录
User/Thread : 1
Ramp-Up-Period : 0
Generate Summary Results = 1 in 2.2s = 0.5/s Avg: 2180 Min: 2180 Max: 2180 Err: 0 (0.00%)
2.Fetch 1000 位用户 1000 条记录
我想同时测试多个用户,因此我将 Ramp-Up-period 添加为 0,根据 JMeter 将立即启动所有用户。
User/Thread : 1000
RampUp Period : 0
Summary Results = 1000 in 18s = 56.1/s Avg: 6857 Min: 5000 Max: 17044 Err: 987 (98.70%)
它确实启动了我所有的用户,但只有 4-5 个用户 return success rest all give me error such as
All host(s) tried for query failed (tried: /192.168.1.50:9042 (com.datastax.driver.core.BusyConnectionException))
但是当我测试同一个 1000 名用户时,给定的启动期为 300,它 return 全部成功。
User/Thread : 1000
RampUp Period : 300
Generate Summary Results = 1000 in 301s = 3.3/s Avg: 519 Min: 255 Max: 1811 Err: 0 (0.00%)
卡斯德拉 Sampler.jmx
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.4" jmeter="2.9 r1437961">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1000</stringProp>
<stringProp name="ThreadGroup.ramp_time">0</stringProp>
<longProp name="ThreadGroup.start_time">1420788860000</longProp>
<longProp name="ThreadGroup.end_time">1420788860000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
<hashTree>
<org.apache.cassandra.jmeter.config.CassandraConnection guiclass="TestBeanGUI" testclass="org.apache.cassandra.jmeter.config.CassandraConnection" testname="Cassandra Connection" enabled="true">
<stringProp name="contactPoints">192.168.1.50,192.168.1.51,192.168.1.52</stringProp>
<stringProp name="keyspace">test_db</stringProp>
<stringProp name="loadBalancer">Default</stringProp>
<stringProp name="localDataCenter"></stringProp>
<stringProp name="password"></stringProp>
<stringProp name="sessionName">mydatabase</stringProp>
<stringProp name="username"></stringProp>
</org.apache.cassandra.jmeter.config.CassandraConnection>
<hashTree/>
<org.apache.cassandra.jmeter.sampler.CassandraSampler guiclass="TestBeanGUI" testclass="org.apache.cassandra.jmeter.sampler.CassandraSampler" testname="Cassandra Sampler" enabled="true">
<stringProp name="batchSize"></stringProp>
<stringProp name="consistencyLevel">QUORUM</stringProp>
<stringProp name="query">select * from test_db.feed_yogesh limit 1000;</stringProp>
<stringProp name="queryArguments">Running</stringProp>
<stringProp name="queryType">Simple Statement</stringProp>
<stringProp name="resultVariable"></stringProp>
<stringProp name="sessionName">mydatabase</stringProp>
<stringProp name="variableNames">VARCHAR</stringProp>
</org.apache.cassandra.jmeter.sampler.CassandraSampler>
<hashTree/>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<ResultCollector guiclass="SummaryReport" testclass="ResultCollector" testname="Summary Report" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
我很疑惑,是不是说多个用户不能同时读取数据,是不是必须要加上Ramp-Up-Period值呢
加速期决定了用户应该上线或开始达到目标负载的时间范围。
您的结果显示,当您以 0 rampup 开始时,所有 1000 个用户同时启动(1000 个并发用户同时访问数据库)。结果显示只有少数用户 1% 通过,其余失败,如果没有进行适当的调整或数据库服务器没有足够的配置,这是预料之中的。
出现上述行为的原因可能是您的数据库服务器无法一次承受那么大的负载。它试图尽可能多地提供服务,但超出了某个限制,它就停止工作了。
但是,当您添加加速时,queries/users 达到分贝率是在分贝服务限制内,因此它可以服务。
您可以检查的是找出那些失败的瓶颈或原因。一些原因可能是,
- 低连接池
- 减少事务超时
- 低配置
- DB 上缺少调整参数
可能有很多原因,但请尝试调试和解决性能问题,然后以较低的加速重新测试(不建议 1000 位用户至少保持 5-10 秒为 0 秒)。如果你想让1000个用户同时命中一个点,有一个叫同步定时器的组件可以帮你。