Redis: Read timed out (ElastiCache)

問題

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out

分析

Redis: 2.8.21
App: Java
採用的是AWS的ElastiCache服務,在Cloudwatch上觀察服務狀態,沒有異常。每天有幾百次的報錯量。
並且通過以下方式在應用的機器上檢測網絡狀態,沒有明顯問題。

>nc -v -w 1 xxxxx 6379 
>ping -c 10 xxxxx
>while true; do echo -e "\n" ; date; redis-cli -h xxxxx -p 6379 time; sleep 1; done > /tmp/elc-check.txt 2>&1 

可以推斷爲數據庫連接問題。

解決方案

修改數據庫連接配置

config.setTestOnBorrow(true);
config.setTestOnReturn(true);
pool=new JedisPool(config,bundle.getString("redis.ip"),Integer.valueOf(bundle.getString("redis.port"),600);

相關參考
http://www.cnblogs.com/liuling/p/2014-4-19-04.html #參數
http://www.csdn123.com/html/mycsdn20140110/2c/2c1c08b73539bf13cc5384542a864d59.html
http://m.oschina.net/blog/406807
http://huoding.com/2015/09/14/463 #關於操作setnx
http://coder.beitown.com/archives/1235 #否是硬件及網絡問題造成的


Wait for your reward

這裏寫圖片描述 這裏寫圖片描述 這裏寫圖片描述 這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章