Redisには多くのクライアントがある

Redisには多くのクライアントがある

サーバーの Redis に問題が発生しています。

まず、PHP スクリプトでtcp:127.0.0.1:6379キャッシュ用のポート経由で Redis に接続しました。この場合、netstat -anp |grep 6379 |wc -lコマンドでは約 57000 の接続があり、PHP は Redis に接続できませんでした。

その後、接続tcpに変更しましたunixsocket。Redis に理想的なクライアント接続が多数あることがわかるまで、すべてが正常に見えました。

client list以下に、 Redis でのコマンドの出力を示します。

    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 の速度が低下すると考えられます。

関連情報