当前位置:网站首页>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.
边栏推荐
- Fundamentals of process management
- 差异与阵列和阵列结构和链表的区别
- 服装企业部署MES管理系统的五个原因
- 【Socket】①Socket技术概述
- 电气工程及其自动化
- Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
- 写作系列之contribution
- Niuke programming problem -- double pointer of 101 must be brushed
- Have fun | latest progress of "spacecraft program" activities
- Qt蓝牙:QBluetoothDeviceInfo
猜你喜欢
Django数据库(SQlite)基本入门使用教程
Redis入门完整教程:复制配置
Hash table and full comments
Douban average 9 x. Five God books in the distributed field!
Fundamentals of process management
The panel floating with the mouse in unity can adapt to the size of text content
记一次JAP查询导致OOM的问题分析
AWS学习笔记(一)
MySQL提升大量数据查询效率的优化神器
Google Earth engine (GEE) -- 1975 dataset of Landsat global land survey
随机推荐
巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
3 -- Xintang nuc980 kernel supports JFFS2, JFFS2 file system production, kernel mount JFFS2, uboot network port settings, and uboot supports TFTP
Application analysis of face recognition
Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
Redis入門完整教程:問題定比特與優化
Error in fasterxml tostringserializerbase
Redis入门完整教程:复制拓扑
实施MES管理系统时,哪些管理点是需要注意的
MMDetection3D加载毫米波雷达数据
Apifox, is your API interface document rolled up like this?
Number theory --- fast power, fast power inverse element
wzoi 1~200
Qpushbutton- "function refinement"
电气工程及其自动化
Contribution of Writing Series
How to write test cases for test coupons?
What are the applications and benefits of MES management system
Common fitting models and application methods of PCL
Argo workflows source code analysis