Search code examples
jdbcjmeterperformance-testingresultset

JMeter JDBC sampler fails on large ResultSet


In my JMeter 3.2 runned test I have a JDBC sampler that is setup like follows:

<JDBCSampler enabled="true" guiclass="TestBeanGUI" testclass="JDBCSampler" testname="query1">
  <stringProp name="dataSource">jdbcConfig_tpcds</stringProp>
  <stringProp name="query">${__FileToString(sql/query1.sql)}</stringProp>
  <stringProp name="queryArguments"/>
  <stringProp name="queryArgumentsTypes"/>
  <stringProp name="queryType">Select Statement</stringProp>
  <stringProp name="resultVariable"/>
  <stringProp name="variableNames"/>
  <stringProp name="queryTimeout"/>
  <stringProp name="resultSetHandler">Count Records</stringProp>
</JDBCSampler>

The query tests db performance and returns very large ResultSet (~10M records). I don't care about result itself so resultSetHandler option is set to Count Records so my expectation is that I will get a row count and ResultSet will be closed. However at the end of this long query when db is done JMeter fails with OutOfMemoryError: Java heap space error which most likely due to Java trying to handle the monstrous ResultSet.

Is there anything I can do using stock JDBC sampler or do I need to write my own?

I cannot limit the ResultSet by adding LIMIT to the query, etc. since it's a performance query

P.S. This does not look good since after looking at the stacktrace it's pretty obvious that regardless of value of resultSetHandler JMeter code still loops through entire ResultSet and tries to suck the complete set into memory

2017/05/05 00:07:42 ERROR - jmeter.threads.JMeterThread: Test failed! java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:3332)
    at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:448)
    at java.lang.StringBuilder.append(StringBuilder.java:136)
    at java.lang.StringBuilder.append(StringBuilder.java:131)
    at org.apache.jmeter.protocol.jdbc.AbstractJDBCTestElement.getStringFromResultSet(AbstractJDBCTestElement.java:548)
    at org.apache.jmeter.protocol.jdbc.AbstractJDBCTestElement.execute(AbstractJDBCTestElement.java:175)
    at org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler.sample(JDBCSampler.java:89)

Solution

  • The solutions are in: