当前位置:网站首页>Redis getting started complete tutorial: common exceptions on the client
Redis getting started complete tutorial: common exceptions on the client
2022-07-07 02:48:00 【Gu Ge academic】
In the process of using the client , Whether the client is used improperly or Redis The server appears
problem , The client will react with some exceptions . This section will analyze Jedis Common during use
Abnormal conditions of .
1. Unable to get connection from connection pool
JedisPool Medium Jedis The number of objects is limited , The default is 8 individual . It is assumed that the default
Recognition configuration , If there is 8 individual Jedis Object is occupied , And didn't return it , At this point, the caller also needs to start from
JedisPool Borrowing from China Jedis, We need to wait ( For example, the maxWaitMillis>0), Such as
Fruit in maxWaitMillis You still can't get Jedis Object will throw the following exception :
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource
from the pool
…
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.
java:449)
There's another situation , It's set up blockWhenExhausted=false, Then the caller finds
When there are no resources in the pool , An exception will be thrown immediately without waiting , The following exception is
blockWhenExhausted=false The effect of the :
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource
from the pool
…
Caused by: java.util.NoSuchElementException: Pool exhausted
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.
java:464)
For this question , What we need to focus on is why the connection pool has no resources , Cause no
There are many reasons for resources , May be the following :
· client : The setting of high parallel outgoing connection pool is too small , There is a shortage of Supply , So it will appear above
Error of , But normally, as long as the number of connections is greater than the default maximum (8 individual ) Just a little more , because
Under normal circumstances JedisPool as well as Jedis The processing efficiency is high enough .
· client : Connection pool is not used correctly , For example, no release , For example, the following code
in .
Definition JedisPool, Use the default connection pool configuration :
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
JedisPool jedisPool = new JedisPool(poolConfig, "127.0.0.1", 6379);
image JedisPool To borrow 8 Secondary connection , But no return operation was performed :
for (int i = 0; i < 8; i++) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
jedis.ping();
} catch (Exception e) {
e.printStackTrace();
}
}
When the caller borrows from the connection pool Jedis when ( Do the following ), Will throw an exception :
jedisPool.getResource().ping();
· client : There are slow query operations , These slow queries hold Jedis Objects will return faster than
slower , Cause the pool to be full .
· Server side : The client is normal , however Redis For some reasons, the server has caused customers
Blocking of end command execution , It will also cause the client to throw such an exception .
We can see that there are many reasons for this exception , Don't be fascinated by abnormal appearances
Puzzled , And there is no master key to solve all problems , Development and operation and maintenance can only be continuously strengthened for
Redis The understanding of the , Gradually find the problem .
2. Client read / write timeout
Jedis Calling Redis when , If there is a read-write timeout , The following exception will appear :
redis.clients.jedis.exceptions.JedisConnectionException:
java.net.SocketTimeoutException: Read timed out
There are also several reasons for this exception :
· The read-write timeout is set too short .
· The command itself is slow .
· The client and server networks are abnormal .
·Redis Self blocking .
3. Client connection timeout
Jedis Calling Redis when , If there is a connection timeout , The following exception will appear :
redis.clients.jedis.exceptions.JedisConnectionException:
java.net.SocketTimeoutException: connect timed out
There are also several reasons for this exception :
1) Connection timeout set too short , You can set it through the following code :
// millisecond
jedis.getClient().setConnectionTimeout(time);
2)Redis happening , cause tcp-backlog Is full , Cause new connection failure .
3) The client and server networks are abnormal .
4. Client buffer exception
Jedis Calling Redis when , If a client data flow exception occurs , The following differences will appear
often :
redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream.
There may be several reasons for this exception :
1) Output buffer full . For example, set the output buffer of the normal client to 1M1M60:
config set client-output-buffer-limit "normal 1048576 1048576 60 slave 268435456
67108864 60 pubsub 33554432 8388608 60"
If you use get Command to get a bigkey( for example 3M), This anomaly will appear .
2) A long idle connection is actively disconnected by the server , This question has been analyzed in detail in the last section
topic .
3) Abnormal concurrent reading and writing :Jedis Objects are operated concurrently by multiple threads at the same time , There may be
Above anomaly .
5.Lua The script is executing
If Redis Currently executing Lua Script , And more than lua-time-limit, here Jedis
call Redis when , You will receive the following exception . How to deal with such problems , In the 3 Chapter Lua Of
Section has been introduced , No more details here .
redis.clients.jedis.exceptions.JedisDataException: BUSY Redis is busy running a
script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
6.Redis Loading persistent file
Jedis call Redis when , If Redis Loading persistent file , Then you will receive the following
abnormal :
redis.clients.jedis.exceptions.JedisDataException: LOADING Redis is loading the
dataset in memory
7.Redis Use more memory than maxmemory To configure
Jedis When writing , If Redis Memory used is greater than maxmemory Set up , Meeting
Received the following exception , At this point, you should adjust maxmemory And find the cause of memory growth :
redis.clients.jedis.exceptions.JedisDataException: OOM command not allowed when
used memory > 'maxmemory'.
8. The number of client connections is too large
If the number of client connections exceeds maxclients, The newly applied connection will appear the following differences
often :
redis.clients.jedis.exceptions.JedisDataException: ERR max number of clients reached
At this point, the new client connection executes any commands , The returned results are as follows :
127.0.0.1:6379> get hello
(error) ERR max number of clients reached
This problem may be tricky , Because it cannot be executed at this time Redis Order problem repair
complex , Generally speaking, it can be solved from two aspects :
· client : If maxclients If the parameter is not very small , The client connection number base of the application
This will not exceed maxclients, Generally speaking, it is because the application side is interested in Redis Improper use of the client
Yes . At this time, if the application side is a distributed structure , You can apply nodes through the offline part ( example
For example, nodes that occupy more connections ), bring Redis The number of connections dropped first . So that most
The node can operate normally , At this point, through the search program bug Or adjust maxclients Conduct problem
Repair .
· Server side : If the client cannot process at this time , And the current Redis High availability mode ( for example
Redis Sentinel and Redis Cluster), You can consider the current Redis Do failover .
There is no definite solution to this problem , But no matter from which aspect , Faulty
Rapid recovery is extremely important , Of course, it is more important to find the problem , Otherwise, after a period of time
The number of client connections will still exceed maxclients.
边栏推荐
- 一文读懂Faster RCNN
- 差异与阵列和阵列结构和链表的区别
- Unity custom webgl packaging template
- Django database (SQLite) basic introductory tutorial
- [node learning notes] the chokidar module realizes file monitoring
- [leetcode]Search for a Range
- 安全交付工程师
- Redis入门完整教程:问题定位与优化
- 牛客编程题--必刷101之双指针篇
- The 8 element positioning methods of selenium that you have to know are simple and practical
猜你喜欢
Number theory --- fast power, fast power inverse element
Unity custom webgl packaging template
NuScenes数据集关于Radar数据的统计
[Mori city] random talk on GIS data (II)
【Socket】①Socket技术概述
记一次JAP查询导致OOM的问题分析
Use of fiddler
Django database (SQLite) basic introductory tutorial
Planning and design of double click hot standby layer 2 network based on ENSP firewall
The panel floating with the mouse in unity can adapt to the size of text content
随机推荐
MySQL
Qpushbutton- "function refinement"
左程云 递归+动态规划
LeetCode 77:组合
Digital scrolling increases effect
Derivative, partial derivative, directional derivative
Redis入門完整教程:問題定比特與優化
How to build a 32core raspberry pie cluster from 0 to 1
Application analysis of face recognition
服装企业部署MES管理系统的五个原因
安德鲁斯—-多媒体编程
AWS学习笔记(一)
Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B
CSDN 夏令营课程 项目分析
MySQL
dotConnect for DB2数据提供者
安全交付工程师
MATLB|具有储能的经济调度及机会约束和鲁棒优化
Examples of how to use dates in Oracle
一本揭秘字节万台节点ClickHouse背后技术实现的白皮书来了!