Some time ago, because the memory usage of the online redis server reached more than 50% of the total machine memory usage, the dump persistence of memory data failed. After expansion to multiple redis instances, when the application system accesses redis, when the business volume is small, the following exceptions may occur from time to time. When the business volume is large and the redis Access frequency is very high, this exception will not occur, I
Some time ago, because the memory usage of the online redis server reached more than 50% of the total machine memory usage, the dump persistence of memory data failed. After expansion to multiple redis instances, when the application system accesses redis, when the business volume is small, the following exceptions may occur from time to time. When the business volume is large and the redis Access frequency is very high, this exception will not occur, I
Some time ago, because the memory usage of the online redis server reached more than 50% of the total machine memory usage, the dump persistence of memory data failed. When the application system accesses redis,When the business volume is small, the following exceptions may occur from time to time. When the business volume is large and the Access Frequency of redis is very high, this exception will not occur.At the moment, I felt very strange.
Redis. clients. jedis. exceptions. JedisConnectionException :? It? Seems? Like? Server? Has? Closed? The? Connection.
At? Redis. clients. util. RedisInputStream. readLine (RedisInputStream. java: 90 )?~ [Jedis-2.1.0.jar: na]
At? Redis. clients. jedis. Protocol. processInteger (Protocol. java: 110 )?~ [Jedis-2.1.0.jar: na]
At? Redis. clients. jedis. Protocol. process (Protocol. java: 70 )?~ [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. getIntegerReply (Connection. java: 188 )?~ [Jedis-2.1.0.jar: na]
At? Redis. clients. jedis. Jedis. sismember (Jedis. java: 1266 )?~ [Jedis-2.1.0.jar: na]
Check that the server closes the connection. Check the configuration of the newly launched redis server:
# Close the connection after a client is idle for N seconds (0 to disable)timeout 120
This configuration refers to the number of seconds after the client connection is idle for more than, the server actively closes the connection. The default value 0 indicates that the server never closes. The op staff set the server timeout to 120 seconds. This explains the cause of this exception. The client uses a connection pool to manage all connections that access redis. These connections are persistent connections. When the service volume is small, the usage of some client connections is low, when the interval between two uses exceeds 120 seconds, the redis server closes the connection. When the client uses the connection object again, it finds that the server has closed the connection, an error is returned.
There are two solutions:
1. Modify the redis configuration directly under redis-cli and change the timeout value to 0. The configuration takes effect directly without restarting redis.
2. modify the application system code and set the maximum idle duration of the connection (the idle connection will be disconnected if the maximum idle duration is exceeded) to less than 120 seconds.
In consideration of the cost of modification, the first scheme is adopted. After modification, no error is reported.
Here is a problem, why does the server take the initiative to close the idle connection, the client did not report an error, the system depends on the jedis-2.1.0, this need to look at the implementation of the jedis connection pool that, the jedis connection pool is mainly written based on commons-pool. I will study it again and write an article to summarize it.
(This Article has been read for 18 times)
Some time ago, because the memory usage of the online redis server reached more than 50% of the total machine memory usage, the dump persistence of memory data failed. After expansion to multiple redis instances, when the application system accesses redis, when the business volume is small, the following exceptions may occur from time to time. When the business volume is large and the redis Access frequency is very high, this exception will not occur, at the moment, I felt very strange. Redis. clients. jedis. exceptions. JedisConnectionException :? It? Seems? Like? Server? Has? Closed? The? Connection.? Redis. clients. util. RedisInputStream. readLine (RedisInputStream. java: 90 )?~ [Jedis-2.1.0.jar: na]? Redis. clients. jedis. Protocol. processInteger (Protocol. java: 110 )?~ [Jedis-2.1.0.jar: na]? Redis. clients. jedis. Protocol. process (Protocol. java: 70 )?~ [Jedis-2.1.0.jar: na]? Redis. clients. jedis. Protocol. read (Protocol. java: 131 )?~ [Jedis-2.1.0.jar: na]? Redis. clients. jedis. Connection. getIntegerReply (Connection. java: 188 )?~ [Jedis-2.1.0.jar: na]? Redis. clients. jedis. Jedis. sismember (Jedis. java: 1266 )?~ [Jedis-2.1.0.jar: na] Look at the prompt, it should be that the server actively closed the connection. Check the configuration of the new redis server. There is one such item: # Close the connection after a client is idle for N seconds (0 to disable) timeout 120 indicates the number of seconds after the client connection is idle. The server closes the connection. The default value 0 indicates that the server never closes the connection. The op staff set the server timeout to 120 seconds. This explains the cause of this exception. The client uses a connection pool to manage all connections that access redis. These connections are persistent connections. When the service volume is small, the usage of some client connections is low, when the interval between two uses exceeds 120 seconds, the redis server closes the connection. When the client uses the connection object again, it finds that the server has closed the connection, an error is returned. There are two solutions: 1. Modify the redis configuration directly under redis-cli and change the timeout back to 0. The change takes effect immediately without restarting redis. 2. modify the application system code and set the maximum idle duration of the connection (the idle connection will be disconnected if the maximum idle duration is exceeded) to less than 120 seconds. In consideration of the cost of modification, the first scheme is adopted. After modification, no error is reported. Here is a problem, why does the server take the initiative to close the idle connection, the client did not report an error, the system depends on the jedis-2.1.0, this need to look at the implementation of the jedis connection pool that, the jedis connection pool is mainly written based on commons-pool. I will study it again and write an article to summarize it. (This Article has been read for 18 times)