How to check which service is consuming more resources on Redis.
Or which service has the highest number of connections on Redis?
How to check which service is consuming more resources on Redis.
Or which service has the highest number of connections on Redis?
You can type the command "CLIENT LIST", You'll see these like :
id=39 addr=127.0.0.1:34706 fd=7 name= age=141156 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
id=78 addr=127.0.0.1:58014 fd=5 name= age=63779 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=llen
id=80 addr=127.0.0.1:36826 fd=6 name= age=46776 idle=1685 flags=N db=1 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=del
The most useful keys for your answer is "age" && "idle" , "age" means the total duration of the connection in seconds and "idle" means idle time of this connection. so (age - idle) / age relects this client uses server's cpu more than other client which the value is smaller , but not very precisely
Other command also can give you some suggestions, like "INFO" and "MONITOR" . INFO gives you a statistics information about redis server , such as the memory usage, the command processed, the cpu usage, the connected clients and so on , you can refer this to get more.
"MONITOR" gives you a real time display which says that what happens now, what command is being executed, who sent this command. Maybe you can compute the every client resource using by the MONITOR output.
e.g. for every command, you first parse it and using a cost to add the client cost sum. In time consuming computing, SET is O(1) and Lrange is O(N). But this is also difficult to do this very precisely. But you can log this using this command like :
redis-cli monitor > redis-command.log
you can use this log to do some analytics. but notes that MONITOR command will reduce your redis server throughput, check this
Do simply
info clients
output
connected_clients:xxx
client_longest_output_list:xxx
client_biggest_input_buf:x
blocked_clients:xx
To get which client is having higher number of connection we can use the below shell script
#!/bin/bash
# Get the list of clients with their connection count
clients=$(redis-cli client list | awk '{print $2}' | sort | uniq -c | sort -rn)
# Print the client with the highest number of connections
highest=$(echo "$clients" | head -n 1)
echo "Client with the highest number of connections: $highest"
This will provide the top first client which has more no of clients I hope it will help!!
If you run the "client list" command against your Redis instance, you should be able to see the entire list of clients connected to your redis instance along with their IP addresses. You can then see which clients (services) have the highest number of connections to your Redis instance.
To get the connection count per client IP, run the following command
redis-cli CLIENT LIST | awk -F[=:] '{print $3}' | sort | uniq -c | sort
Or in case awk
cmd didn't work properly:
redis-cli CLIENT LIST | cut -f 2 -d " " | cut -f 2 -d "=" | cut -f 1 -d":" | sort | uniq -c | sort
The output would be something like this:
1 10.10.X.X
8 10.10.X.X
15 10.10.X.X
20 10.10.X.X
© 2022 - 2024 — McMap. All rights reserved.