Timeout
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: Java.net.SocketTimeoutException:Read timed out at redis.clients.jedis.Protocol.process (Protocol.java:79 ) at redis.clients.jedis.Protocol.read (protocol.java:131) at Redis.clients.jedis.Connection.getBinaryMultiBulkReply (Connection.java:199) at Redis.clients.jedis.Jedis.hgetAll (Jedis.java:851)
If what you want to does is set Jedis connection timeoutand you should does it using the special constructor for T Hat
timeout)
What's doing is setting the timeout in Redis settings from Jedis.
Doing CONFIG SET timeout 60
, means that Redis would close idle client connections after seconds.
That's why you get the exception in Jedis.
The timeout parameter of the constructor is in milliseconds because this value was affected internally to Java.net.socket#c Onnect (java.net.SocketAddress, int) and java.net.socket#setsotimeout (int) methods. So the this value is connection and a socket read timeout.
This is a bit of the extension to Xetorthio's answer, but here's similar approach for use with a jedispool. (Caveat:this is based on my understanding from looking at the Jedis version 2.6.2 code directly and have not been tested I n a live use case.)
New jedispoolconfig (); Jedispoolconfig.setmaxwaitmillis (writetimeout); readtimeout);
The writetimeout is max time for a Jedis resource from the pool to wait for a write operation .
The readtimeout specified for the pool constructor are the wait time for a socket read, see Java . Net. Socket. setsotimeout for more specific details.
Few Things to consider:
For both Jedis and Jedispool classes, timeout was in miliseconds. Default timeout, at least in 2.5.1, as I See, is (MILISEC):int redis.clients.jedis.Protocol.DEFAULT_TIMEOUT = 2000 [0x7d0]
As per this documentation, recent version of Redis does isn't close connection, even if the client is idle. I has not verified this yet, and I'll try to update the post when I do.
Http://stackoverflow.com/questions/14993644/configure-jedis-timeout
https://github.com/xetorthio/jedis/issues/1190
Redis server, no changes during all test
redis_version:2.6.9
We ' ve been upgrading Jedis client from 2.0.0 to 2.7.3, with the same configuration parameters,
We saw a lot more exceptions like below
Exception in Thread "Thread-4" redis.clients.jedis.exceptions.JedisConnectionException:Could not get a resource from the Pool at Redis.clients.util.Pool.getResource (pool.java:50) at Redis.clients.jedis.JedisPool.getResource (JEDISPOOL.J ava:99) at Com.yaojuncn.jedis.jedisperftest$.onecall (jedisperftest.scala:94) at com.yaojuncn.jedis.jedisperftest$$ anonfun$runthreadtest$1$ $anon $1$ $anonfun $run$1.apply$mcvi$sp (jedisperftest.scala:69) at SCALA.COLLECTION.IMMUTABLE.RANGE.FOREACH$MVC$SP (range.scala:141) at com.yaojuncn.jedis.jedisperftest$ $anonfun $ runthreadtest$1$ $anon $1.run (jedisperftest.scala:68) at Java.lang.Thread.run (thread.java:745) caused by: Java.util.NoSuchElementException:Timeout waiting for idle object at Org.apache.commons.pool2.impl.GenericObjectPool.borrowObject (genericobjectpool.java:449) at Org.apache.commons.pool2.impl.GenericObjectPool.borrowObject (genericobjectpool.java:363) at Redis.clients.util.Pool.getResource (pool.java:48) ... 6 more
- After some hard time, finally reached the test code of below with 2.7.3 Version,https://github.com/yaojuncn/jedis273concur Rentperftest/blob/master/src/main/scala/com/yaojuncn/jedis/jedisperftest.scala
We saw a lot of pool.getresource invocations longer than 20ms .... (If we uncomment out line PNs above source file we'll see a lot of exceptions)
Https://github.com/yaojuncn/jedis273concurrentperftest/blob/master/jedis2.7.3.sampleoutput.txt
With 2.0.0 version
Https://github.com/yaojuncn/jedis200concurrentperftest/blob/master/src/main/scala/com/yaojuncn/jedis/JedisPerfTest.scala
The output is pretty clean
Https://github.com/yaojuncn/jedis200concurrentperftest/blob/master/jedis2.0.0.sampleoutput.txt
- I guess this was related to the Apache-common pool version that Jedis was using and I do saw the Faqhttps://github.com/xetor Thio/jedis/wiki/faq and issues listed here's like
#844
But by comparing with 2.7.3 and 2.0.0, I think there ' s something wrong now.
With threads on a 8 max pool size,
The 2.0.0 could perform very well while the 2.7.3 would see a lot of exceptions if we set the maxwait=20ms;
https://github.com/xetorthio/jedis/issues/1139
Redis.clients.jedis.exceptions.JedisConnectionException:Could not get a resource from the pool