
우리 서버의 Redis에 문제가 있습니다.
먼저 PHP 스크립트에서 캐싱을 위해 포트를 통해 Redis에 연결했습니다 tcp:127.0.0.1:6379
. 이 경우 netstat -anp |grep 6379 |wc -l
명령을 사용하면 약 57000개의 연결이 있었고 PHP는 Redis에 연결할 수 없었습니다.
그 후 연결 tcp
로 변경했습니다. unixsocket
Redis에 이상적인 클라이언트 연결이 많이 있다는 것을 발견하기 전까지는 모든 것이 괜찮아 보입니다.
아래에서 Redis의 명령 출력을 볼 수 있습니다 client list
.
id=4369214 addr=/tmp/redis.sock:0 fd=953 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369215 addr=/tmp/redis.sock:0 fd=955 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369216 addr=/tmp/redis.sock:0 fd=1045 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369217 addr=/tmp/redis.sock:0 fd=1056 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369218 addr=/tmp/redis.sock:0 fd=1108 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369219 addr=/tmp/redis.sock:0 fd=1109 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369220 addr=/tmp/redis.sock:0 fd=1110 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369221 addr=/tmp/redis.sock:0 fd=1112 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369222 addr=/tmp/redis.sock:0 fd=1113 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369223 addr=/tmp/redis.sock:0 fd=1114 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369224 addr=/tmp/redis.sock:0 fd=1115 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369225 addr=/tmp/redis.sock:0 fd=1116 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369226 addr=/tmp/redis.sock:0 fd=1117 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369227 addr=/tmp/redis.sock:0 fd=1118 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369228 addr=/tmp/redis.sock:0 fd=1119 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369229 addr=/tmp/redis.sock:0 fd=1120 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369230 addr=/tmp/redis.sock:0 fd=1121 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369231 addr=/tmp/redis.sock:0 fd=1122 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369232 addr=/tmp/redis.sock:0 fd=1123 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369233 addr=/tmp/redis.sock:0 fd=1124 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369234 addr=/tmp/redis.sock:0 fd=1125 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369235 addr=/tmp/redis.sock:0 fd=1126 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369236 addr=/tmp/redis.sock:0 fd=1127 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369237 addr=/tmp/redis.sock:0 fd=1128 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369238 addr=/tmp/redis.sock:0 fd=1129 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369239 addr=/tmp/redis.sock:0 fd=1130 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369240 addr=/tmp/redis.sock:0 fd=1131 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369241 addr=/tmp/redis.sock:0 fd=1132 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369242 addr=/tmp/redis.sock:0 fd=1133 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369243 addr=/tmp/redis.sock:0 fd=1134 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369244 addr=/tmp/redis.sock:0 fd=1135 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
id=4369245 addr=/tmp/redis.sock:0 fd=1136 name= age=0 idle=0 flags=U db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
...
출력은 다음과 info clients
같습니다.
# Clients
connected_clients:917
client_longest_output_list:2
client_biggest_input_buf:0
blocked_clients:0
컵 사용량이 많고 Redis가 느립니다. 캐싱을 비활성화한 후에도 이 문제는 여전히 발생합니다.
감사해요
답변1
Redis에는 구성에 시간 초과가 있습니다. 다음을 사용하여 동적으로 시간 초과 설정
config set timeout <valid value in seconds>
Redis는 구성된 시간 동안 유휴 상태이면 연결을 닫습니다. 이 문제는 PHP 스크립트가 요청이 끝날 때 redis 소켓을 닫지 않기 때문에 발생합니다. Redis가 열린 파일 설명자 제한에 도달하면 속도가 느려지는 것 같습니다.