1. 程式人生 > >Redis異常及使用總結

Redis異常及使用總結

現象:各種釋出,和其他指令都失效

日誌:

com.lingyu.common.core.ServiceException: redis.clients.jedis.exceptions.JedisDataException: ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context
	at com.lingyu.common.db.Redis.publish(Redis.java:1402)
	at com.lingyu.game.service.stat.StatRepository.publish(StatRepository.java:16)
	at com.lingyu.game.service.stat.StatManager.statRealTime(StatManager.java:232)
	at com.lingyu.game.service.job.JobManager.statRealTime(JobManager.java:336)
	at sun.reflect.GeneratedMethodAccessor203.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:756)
Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context
	at redis.clients.jedis.Protocol.processError(Protocol.java:117)
	at redis.clients.jedis.Protocol.process(Protocol.java:151)
	at redis.clients.jedis.Protocol.read(Protocol.java:205)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
	at redis.clients.jedis.Connection.getIntegerReply(Connection.java:222)
	at redis.clients.jedis.Jedis.publish(Jedis.java:2601)
	at com.lingyu.common.db.Redis.publish(Redis.java:1399)

現象 :早上後臺的訂閱執行緒無故退出,導致統計和監控失效長達5個小時左右

日誌:

原因:The error comes from the fact a Redis connection cannot be shared between publishers and subscribers. Actually you need a connection (or a pool of connections) for publishers, and just one dedicated connection for the subscriber thread. Running a single subscriber thread per process is usually enough.

由於訂閱執行緒因為某種 原因逃逸,導致被阻塞的訂閱連線重新投入使用,一旦被用來做其他指令的操作,就報出了以上異常,訂閱過的連線不能用來做其他用處,否則就會有以上的問題。

2015-04-13 05:00:00.256 ERROR [Message SubScribe Monitor][SubScribeManager.java:127] - 訂閱執行緒無故退出
com.lingyu.common.core.ServiceException: redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream.
        at com.lingyu.common.db.Redis.subscribe(Redis.java:1439) ~[Redis.class:?]
        at com.lingyu.common.db.SubScribeManager.run(SubScribeManager.java:125) ~[SubScribeManager.class:?]
        at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream.
        at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:198) ~[jedis-2.6.2.jar:?]
        at redis.clients.util.RedisInputStream.read(RedisInputStream.java:180) ~[jedis-2.6.2.jar:?]
        at redis.clients.jedis.Protocol.processBulkReply(Protocol.java:158) ~[jedis-2.6.2.jar:?]
        at redis.clients.jedis.Protocol.process(Protocol.java:132) ~[jedis-2.6.2.jar:?]
        at redis.clients.jedis.Protocol.processMultiBulkReply(Protocol.java:183) ~[jedis-2.6.2.jar:?]
        at redis.clients.jedis.Protocol.process(Protocol.java:134) ~[jedis-2.6.2.jar:?]
        at redis.clients.jedis.Protocol.read(Protocol.java:192) ~[jedis-2.6.2.jar:?]
        at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:282) ~[jedis-2.6.2.jar:?]
        at redis.clients.jedis.Connection.getRawObjectMultiBulkReply(Connection.java:227) ~[jedis-2.6.2.jar:?]
        at redis.clients.jedis.JedisPubSub.process(JedisPubSub.java:108) ~[jedis-2.6.2.jar:?]
        at redis.clients.jedis.JedisPubSub.proceed(JedisPubSub.java:102) ~[jedis-2.6.2.jar:?]
        at redis.clients.jedis.Jedis.subscribe(Jedis.java:2496) ~[jedis-2.6.2.jar:?]
        at com.lingyu.common.db.Redis.subscribe(Redis.java:1435) ~[Redis.class:?]
        ... 2 more


被try{}catch(Exception e){} 的居然還會退出,很疑惑~~

查到了這篇文章:

https://github.com/xetorthio/jedis/issues/932

client-output-buffer-limit was the cause. redis-server closed the connections, leading to the exceptions.

client-output-buffer-limit

客戶端buffer控制。在客戶端與server進行的互動中,每個連線都會與一個buffer關聯,此buffer用來佇列化等待被client接受的響應資訊。如果client不能及時的消費響應資訊,那麼buffer將會被不斷積壓而給server帶來記憶體壓力.如果buffer中積壓的資料達到閥值,將會導致連線被關閉,buffer被移除。


buffer控制型別包括:normal -> 普通連線;slave ->與slave之間的連線;pubsub ->pub/sub型別連線,此型別的連線,往往會產生此種問題;因為pub端會密集的釋出訊息,但是sub端可能消費不足.
指令格式:client-output-buffer-limit <class> <hard> <soft> <seconds>",其中hard表示buffer最大值,一旦達到閥值將立即關閉連線;
soft表示"容忍值",它和seconds配合,如果buffer值超過soft且持續時間達到了seconds,也將立即關閉連線,如果超過了soft但是在seconds之後,buffer資料小於了soft,連線將會被保留.
其中hard和soft都設定為0,則表示禁用buffer控制.通常hard值大於soft.

生產線上調整引數(記憶體和配置同步修改):

127.0.0.1:6380> CONFIG GET client-output-buffer-limit
client-output-buffer-limit
normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60

127.0.0.1:6380> config set client-output-buffer-limit 'normal 0 0 0 slave 268435456 67108864 60 pubsub 0 0 0'


redis.conf
client-output-buffer-limit pubsub 0 0 0

===========================================================

昨天又遇到俄羅斯地區 後臺活動上傳不成功,我們的後臺活動是通過redos publish出去的,但發現publish失敗,試著手工publish 小位元組的是沒問題,大位元組的就失敗,info 也沒法檢視。

後臺確認原因是,內網區域網傳輸對包的大小進行了限制,超過一定大小的包,都無法進行傳輸,並導致連線失效。開啟限制,問題解決。

=============================================================

6470672人


平均下來每個人,887位元組 記憶體佔用,608 AOF 磁碟佔用 344 RDB磁碟佔用


檔案cache需要額外佔用一半的記憶體佔用,所以大概就有10幾G的佔用

=============================================================

慢查詢獲取

slowlog get

127.0.0.1:6379> slowlog get 
 1) 1) (integer) 27
    2) (integer) 1417531320
    3) (integer) 24623
    4) 1) "info".0.1:6379> slowlog get 
 1) 1) (integer) 27
    2) (integer) 1417531320
    3) (integer) 24623
    4) 1) "info"

其中,各項指標表示:

  • A unique progressive identifier for every slow log entry. slowlog的流水號

  • The unix timestamp at which the logged command was processed. unix時間戳

  • The amount of time needed for its execution, in microseconds 平均耗時(注意,microseconds翻譯成微秒,而不是毫秒).

  • The array composing the arguments of the command.

slowlog len 獲取總共的slow log數量

slowlog get number 根據數量獲取slowlog

=======================================

commandstats 部分記錄了各種不同型別的命令的執行統計資訊,比如命令執行的次數、命令耗費的 CPU 時間(單位毫秒)、執行每個命令耗費的平均 CPU 時間(單位毫秒)等等。對於每種型別的命令,這個部分都會新增一行以下格式的資訊:

cmdstat_XXX:calls=XXX,usec=XXX,usecpercall=XXX
10.104.5.98:6379>info commandstats
# Commandstats
cmdstat_get:calls=180608685,usec=470928529,usec_per_call=2.61
cmdstat_set:calls=147550519,usec=562225572,usec_per_call=3.81
cmdstat_del:calls=177224,usec=1643815,usec_per_call=9.28
cmdstat_exists:calls=14130110,usec=31402378,usec_per_call=2.22
cmdstat_incr:calls=1017,usec=3261,usec_per_call=3.21
cmdstat_mget:calls=666034,usec=18069595,usec_per_call=27.13
cmdstat_lpush:calls=103077132,usec=181583996,usec_per_call=1.76
cmdstat_lrange:calls=38777511,usec=138617427,usec_per_call=3.57
cmdstat_ltrim:calls=2056,usec=7622,usec_per_call=3.71
cmdstat_lrem:calls=103075076,usec=579401111,usec_per_call=5.62
cmdstat_zadd:calls=15900133,usec=56515414,usec_per_call=3.55
cmdstat_zincrby:calls=11747959,usec=196212310,usec_per_call=16.70
cmdstat_zrem:calls=257783,usec=1053833,usec_per_call=4.09
cmdstat_zrange:calls=7141527,usec=41950470,usec_per_call=5.87
cmdstat_zrevrangebyscore:calls=10,usec=51489,usec_per_call=5148.90
cmdstat_zcount:calls=16104028,usec=112221789,usec_per_call=6.97
cmdstat_zrevrange:calls=27497771,usec=582807534,usec_per_call=21.19
cmdstat_zscore:calls=8663683,usec=44001575,usec_per_call=5.08
cmdstat_zrank:calls=3,usec=43,usec_per_call=14.33
cmdstat_zrevrank:calls=15906400,usec=68891802,usec_per_call=4.33
cmdstat_hset:calls=10236125,usec=37507245,usec_per_call=3.66
cmdstat_hget:calls=1618802100,usec=2755577270,usec_per_call=1.70
cmdstat_hmset:calls=369619411,usec=4843444966,usec_per_call=13.10
cmdstat_hmget:calls=56015,usec=344231,usec_per_call=6.15
cmdstat_hincrby:calls=170633471,usec=884820311,usec_per_call=5.19
cmdstat_hdel:calls=44233,usec=201881,usec_per_call=4.56
cmdstat_hlen:calls=21724,usec=39834,usec_per_call=1.83
cmdstat_hgetall:calls=311374011,usec=3269118749,usec_per_call=10.50
cmdstat_hexists:calls=70864759,usec=285319509,usec_per_call=4.03
cmdstat_incrby:calls=2942269,usec=42251052,usec_per_call=14.36
cmdstat_decrby:calls=2050,usec=3616,usec_per_call=1.76
cmdstat_rename:calls=6472,usec=33326,usec_per_call=5.15
cmdstat_keys:calls=3636,usec=1974535725,usec_per_call=543051.62
cmdstat_dbsize:calls=9,usec=15,usec_per_call=1.67
cmdstat_ping:calls=46747,usec=61691,usec_per_call=1.32
cmdstat_type:calls=1,usec=3,usec_per_call=3.00
cmdstat_psync:calls=1,usec=3164,usec_per_call=3164.00
cmdstat_replconf:calls=21643928,usec=25568830,usec_per_call=1.18
cmdstat_info:calls=4,usec=3669,usec_per_call=917.25
cmdstat_config:calls=2,usec=37,usec_per_call=18.50
cmdstat_subscribe:calls=45505,usec=476993,usec_per_call=10.48
cmdstat_publish:calls=34572782,usec=262298295,usec_per_call=7.59
cmdstat_client:calls=3,usec=47628,usec_per_call=15876.00
cmdstat_eval:calls=2050,usec=76432,usec_per_call=37.28
cmdstat_slowlog:calls=1,usec=30,usec_per_call=30.00

redis.2.8.23 版本部署時會有兩個warning

[32555] 09 Nov 12:06:37.804 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
[32555] 09 Nov 12:06:37.804 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

只要按照提示來就行:

echo never > /sys/kernel/mm/transparent_hugepage/enabled

echo 511 > /proc/sys/net/core/somaxconn

並加到 /etc/rc.local 

==============================================

Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk"

1.沒有配置 vm.overcommit_memory=1  

2.磁碟空間不足

3.rdb檔案被刪除,解決辦法 

<span style="color:#000000">CONFIG SET dir /data/redis/</span>

相關推薦

Redis異常使用總結

現象:各種釋出,和其他指令都失效 日誌: com.lingyu.common.core.ServiceException: redis.clients.jedis.exceptions.JedisDataException: ERR only (P)SUBSCRIBE /

Redis異常解決

1.redis 1.1redis系統版本 使用版本:3.2.11 <groupId>com.foriseland.fjf</groupId> <artifactId>fjf-cache</artifactId> <version>

pandas安裝若干異常解決方案總結

在為Python安裝第三方工具pandas出現了若干問題。 當我在cmd命令環境輸入pip install pandas準備安裝pandas時,出現了錯誤提示:Microsoft Visual C++ 9.0 is required.從網上查詢資料有如下解決方案: 1.下載

RMI總結可能產生的幾種異常解決

RMI技術的總結 一、概要 主要包括5個檔案:IRMI(介面),RMIImp, RMIServer, RMIClient, RMIImp_stub 在和cn統一目錄級別下執行: rmic cn.cnic.osg.RMIImp 二、安全機制 在Think In Jav

“全棧2019”22篇Java異常學習資料總結

學習計劃 分鐘 轉載 學習 tell intellij 總結 https 聲明 難度 初級 學習時間 10分鐘 適合人群 零基礎 開發語言 Java 開發環境 JDK v11 IntelliJ IDEA v2018.3 文章原文鏈接 “全棧2019”22篇Java異常學

redisredis簡介下載安裝

移動 持久化 文檔 acl inf zxvf osql .cn ted 1. 數據庫的分類:關系型數據庫,非關系型數據庫(Nosql) 2.非關系型數據庫: 鍵值型數據庫:redis 等。 列式存儲數據庫: hbase 等。 文檔型數據庫 : mongoDB 等。 圖形數

Redis部署參數筆記

redis部署 redis參數 Redis Cluster是Redis的集群實現,內置數據自動分片機制,集群內部將所有的key映射到16384個Slot中,集群中的每個Redis Instance負責其中的一部分的Slot的讀寫。 集群客戶端連接集群中任一Redis Instance即可發送命令,當R

java web 常見異常解決辦法

eset log const 鍵值 cannot tomcat action asp tex javax.servlet.ServletException: javax/servlet/jsp/SkipPageException 重啟tomcat, javax.serv

Redis基礎入門

是否 解釋器 redis 單獨 示例 lease out field 發布系統 一. 什麽是 Redis Redis 是一個可基於內存,有著完備的持久化機制並以 Key-Value 形式存儲的非關系型數據庫。也稱為數據結構服務器。 二.

redis安裝主從配置

redis;redis主從配置一、redis介紹 redis是一個key-value存儲系統。和Memcached類似,它支持存儲的value類型相對更多,包括string(字符串)、list(鏈表)、set(集合)和zset(有序集合)。這些數據類型都支持push/pop、add/remove及取交集並

一道正則練習總結

轉義字符 ima 總結 懶惰模式 nbsp 數據 image img bsp 要求:匹配每對中括號之間的${}裏面的內容。   例如[idkey=${param1}] and [CNNAME<>${param2}] or [column3>${param3

Maven常見異常解決方法

for display maven2 main collect nts exist temp set 異常1: [ERROR] Failed to execute goal on project biz_zhuhai: Could not resolve dependen

redis安裝php擴展

redis php 擴展 下載地址:http://redis.io/download,下載最新文檔版本。1.下載安裝sudo wget http://download.redis.io/releases/redis-3.2.9.tar.gzsudo tar -zxvf redis-3.2.9.ta

redis cluster 實踐總結

監聽 截至目前 實踐 啟動 但是 -- 是什麽 size 發現 最近項目接觸到了redis cluster,現在趁著使用做一下總結,記錄一下遇到過的問題,簡單的概述一下常用到的命令和功能。 本篇文章主要是以運維的角度去講述如何去更好的規劃redis cluster和跳坑

緩存系列之三:redis安裝基本數據類型命令使用

pytho children tile 指令 sed eject 檢測 install 文件的 一:Redis是一個開源的key-value存儲系統。與Memcached類似,Redis將大部分數據存儲在內存中,支持的數據類型包括:字符串、哈希表、鏈表、集合、有序集合以及基

異常File類概述

異常 error exception file filenamefileter io流 一、異常 1、異常分類: Throwable:Throwable類是 Java 語言中所有錯誤或異常的超類。它只有兩個子類 Error:屬於嚴重問題,只能避免;如內存溢出(OutOfMemor

使用php-amqplib連接rabbitMQ 學習筆記總結

upd echo 密碼 分發 rop 必須 mco fan span 1、使用composer安裝php-amqplib 在你的項目中添加一個 composer.json文件: { "require": { "php-amqplib/php-am

異常日誌使用與項目打包

最新 rac clas ssa led html round div [] 你會捕捉異常嗎? 異常簡要信息(僅有出錯原因): Exception.getMessage() 或 Exception.toString () 異常詳細信息(有具體出錯的行號):

postman 訪問 jenkins api 接口異常處理

mis replace imp group 用戶 .cn con 權限 -- 問題:通過Postman訪問 Jenkins api時出現訪問權限問題 <html> <head> <meta http-equiv=‘refr

redis 安裝啟動關閉

containe art size ash bin 一份 四種 color service 1、redis下載   方式1:直接去官網下載     https://redis.io/download   方式2:通過命令下載     wget http://download