使用JMeter加载测试CassandraDB

时间:2015-01-09 11:59:42

标签: java performance jmeter performance-testing cassandra-2.0

我正在使用我已集成在apache-JMeter2.9中的Cassandra JMeter插件https://github.com/slowenthal/jmeter-cassandra#cassandra-jmeter-plugin-for-cassandra

我有一个Cassandra集群,每个数据中心包含2个数据中心和2个节点。

JMeter的:

Cassandra连接:

contact points : 192.168.1.50,192.168.1.51,192.168.1.52
keyspace : test_db

Cassandra Sampler

CQL Query : select  * from test_db.feed_yogesh limit 1000;
Consistency Level : QUORUM

测试场景

1.为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.为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个用户返回成功休息所有给我错误,如

All host(s) tried for query failed (tried: /192.168.1.50:9042 (com.datastax.driver.core.BusyConnectionException))

但是,当我测试相同的1000用户给出加速期为300时,它会返回所有成功。

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%) 

Cassndra 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值。

1 个答案:

答案 0 :(得分:2)

Rampup period决定用户上线或开始在目标上加载的时间范围。

您的结果显示,当您以0加速开始时,所有1000个用户同时启动(1000个并发用户同时命中数据库)。结果显示只有少数用户1%通过并且休息失败,如果没有进行适当的调整或者DB服务器没有足够的配置,这是预期的。

上述行为的原因可能是您的数据库服务器一次无法承担那么多负载。它试图尽可能地服务但超出一定限度它停止工作。

但是当你添加斜坡时,查询/用户达到数据库速率是在数据库服务限制内,因此服务。

您可以检查的是发现这些故障的瓶颈或原因。一些原因可能是,

  1. 低连接池
  2. 降低交易超时
  3. 低配置
  4. DB上缺少调整参数
  5. 可能有很多原因,但尝试调试和解决性能问题,并以较低的增加重新测试(不建议1000个用户0秒至少保持5-10秒)。如果你想让1000个用户同时点击,那么就会有一个叫做同步计时器的组件来帮助你。