I want to loadtest redis with jmeter. I already have a working JSR223Sampler with a groovy-script
import redis.clients.jedis.Jedis; import java.util.concurrent.ThreadLocalRandom; String varuser = "user:" + ThreadLocalRandom.current().nextInt(1, 500); Jedis jedis = new Jedis(IP, port); String result = jedis.hgetAll(varuser); SampleResult.setResponseData(result.toString().getBytes());
under a ThreadGroup with 10 'users'. Works fine. Now I want to raise the number of 'users' to 1000. Performance will be influenced negatively by the high number of connections, right? So I want to get the advantages of a connection pool. According to
JedisPool is the answer. My question is how my jmeter testplan have to look like? Where do I have to put the jmeter-element (which one?) in which JedisPool will be created? Not under my ThreadGroup, right? And how I can use the connections from the pool in my sampler-script from above?
So with Dmitris advise I createt two different testplans. Both not working. Maybe somebody sees my mistake?
|---setUp Thread Group
----|---JSR223 Sampler (1)
----|---JSR223 Sampler (2)
|---View Results Tree
with JSR223 Sampler (1)
import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; JedisPool pool = new JedisPool(new JedisPoolConfig(), IP); prop.put('pool', pool);
and JSR223 Sampler (2)
import redis.clients.jedis.Jedis; import java.util.concurrent.ThreadLocalRandom; String varuser = "user:" + ThreadLocalRandom.current().nextInt(1, 500); Jedis jedis = props.get('pool'); String result = jedis.hgetAll(varuser); SampleResult. ... jedis.close();
My second TestPlan looks like
----|---View Results Tree
with PreProcessor like the above JSR223 Sampler (1) and JSR223 Sampler like the above JSR223 Sampler (2).
First Plan comes with the response message
cannot cast object '[email protected]' with class 'redis.clients.jedis.JedisPool' to class 'redis.clients.jedis.Jedis'
Second Plan responds
no such property: pool for class: Script41082
What I'm doing wrong?groovyredisjmeterjedis
I would recommend creating JedisPool somewhere in setUp Thread Group using either JSR223 Sampler (if you want to measure pool creation time) or Test Action Sampler and JSR223 PreProcessor combination (if you don't want to include pool creation request into your test results)
Once done you can put this "pool" into JMeter Properties like:
In setUp Thread Group
def pool = new JedisPool(new JedisPoolConfig(), 'localhost') props.put('pool', pool)
Somewhere in the middle of your test
def pool = props.get('pool')
See Apache Groovy - Why and How You Should Use It article for more information on using Groovy scripting in JMeter tests
You are getting
JedisPool from properties and try to cast it to
Jedis which is impossible, you need to get
import redis.clients.jedis.JedisPool; .... JedisPool pool = props.get('pool'); Jedis jedis = pool.getResource();