Timeout exception for Java read Redis

Source: Internet
Author: User
Tags redis redis server

Exception content:

Redis.clients.jedis.exceptions.JedisConnectionException:java.net.SocketTimeoutException:Read timed out at Redis.clients.jedis.Protocol.process (protocol.java:79) ~[jedis-2.1.0.jar:na] at Redis.clients.jedis.Protocol.read (protocol.java:131) ~[jedis-2.1.0.jar:na] at redis.clients.jedis.Connection.getBinaryBulkReply (Connection.java : ~[jedis-2.1.0.jar:na] at redis.clients.jedis.Connection.getBulkReply (connection.java:171) ~[jedis-2.1.0.jar: NA] at Redis.clients.jedis.Jedis.lpop (jedis.java:1090) ~[jedis-2.1.0.jar:na] at Zju.lzm.storm.spout.RedisReadSpout.nextTuple (redisreadspout.java:52) ~[bin/:na] at Backtype.storm.daemon.executor $eval 5100$fn__5101$fn__5116$fn__5145.invoke (executor.clj:562) ~[na:na] at backtype.storm.util$async_loop$fn__390. Invoke (util.clj:433) ~[na:na] at Clojure.lang.AFn.run (afn.java:24) [Clojure-1.4.0.jar:na] at Java.lang.Thread.run ( Unknown Source) [na:1.7.0_07] caused by:java.net.SocketTimeoutException:Read timed out at JAVA.NET.SOCKETINPUTSTREAM.S OckeTRead0 (Native method) ~[na:1.7.0_07] at Java.net.SocketInputStream.read (Unknown Source) ~[na:1.7.0_07] at Java.net.SocketInputStream.read (Unknown source) ~[na:1.7.0_07] at Java.net.SocketInputStream.read (Unknown source) ~[ NA:1.7.0_07] at Redis.clients.util.RedisInputStream.fill (redisinputstream.java:109) ~[jedis-2.1.0.jar:na] at Redis.clients.util.RedisInputStream.readByte (redisinputstream.java:45) ~[jedis-2.1.0.jar:na] at Redis.clients.jedis.Protocol.process (protocol.java:64) ~[jedis-2.1.0.jar:na] ... 
9 Common frames omitted 209206 [thread-27-redisreadspout] ERROR Backtype.storm.daemon.executor- Redis.clients.jedis.exceptions.JedisConnectionException:java.net.SocketTimeoutException:Read timed out at Redis.clients.jedis.Protocol.process (protocol.java:79) ~[jedis-2.1.0.jar:na] at Redis.clients.jedis.Protocol.read (protocol.java:131) ~[jedis-2.1.0.jar:na] at redis.clients.jedis.Connection.getBinaryBulkReply (Connection.java : ~[jedis-2.1.0.jar:na] at REDIS.CLIENTS.JEDIS.COnnection.getbulkreply (connection.java:171) ~[jedis-2.1.0.jar:na] at Redis.clients.jedis.Jedis.lpop (Jedis.java : 1090) ~[jedis-2.1.0.jar:na] at Zju.lzm.storm.spout.RedisReadSpout.nextTuple (redisreadspout.java:52) ~[bin/:na] at Backtype.storm.daemon.executor$eval5100$fn__5101$fn__5116$fn__5145.invoke (executor.clj:562) ~[na:na] at Backtype.storm.util$async_loop$fn__390.invoke (util.clj:433) ~[na:na] at Clojure.lang.AFn.run (afn.java:24) [ Clojure-1.4.0.jar:na] at Java.lang.Thread.run (Unknown Source) [na:1.7.0_07] caused by: Java.net.SocketTimeoutException:Read timed out in Java.net.SocketInputStream.socketRead0 (Native method) ~[na:1.7.0_ Modified] at Java.net.SocketInputStream.read (Unknown Source) ~[na:1.7.0_07] at Java.net.SocketInputStream.read (Unknown Source) ~[na:1.7.0_07] at Java.net.SocketInputStream.read (Unknown Source) ~[na:1.7.0_07] at Redis.clients.util.RedisInputStream.fill (redisinputstream.java:109) ~[jedis-2.1.0.jar:na] at Redis.clients.util.RedisInputStream.readByte (Redisinputstream.java:45) ~[jedis-2.1.0.jar:na] at redis.clients.jedis.Protocol.process (protocol.java:64) ~[ Jedis-2.1.0.jar:na] ...
 9 Common frames omitted

This timeout problem occurs when you use Jedis to perform REDIS database operations in Java.

workaround : When calling Jedis's construction method, the timeout time is set to a greater size. Such as:

Jedis Jedis = new Jedis ("127.0.0.1", 8371,100000);//The time-out period is set to 100000 milliseconds
If this is large enough, it will basically not have a timeout problem.

analysis of the problem:

In the default constructor method for Jedis, the time to timeout is typically set to 2000 milliseconds, or 2 seconds. Of course this time, for Redis this data from the memory of the database should be quite large, but why timeout. The possible reason is that when the amount of redis data is large, timeouts may occur in Redis server. Because Redis is single-threaded to handle all client connections at run time. This also follows the FIFO scheduling strategy when the number of connections is large or the volume of data is high. As a result, timeouts may occur.


Other false changes:

Jedis.configset ("Timeout", "30");
The above method is to set the Redis to turn off idle connections that timeout more than 30 seconds. Instead of setting a timeout for reading data.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.