LoginSignup
0

More than 5 years have passed since last update.

play-redisから`PeerClosed`のログが出る理由

Posted at

問題

redis.actors.RedisClientActor - ConnectionClosed PeerClosedのWarningログが各APIのCloudWatchに出続ける(出現間隔は1分に1回)

原因

redisにtimeoutが設定されているため、timeout時間内にredisに対してread/writeの操作がなければ、redisへのコネクションを切る
そのため、各APIでredisへのread/writeが頻繁に起こらない状態だと、redis側からコネクションが切られ、play-redis(scala)からPeerClosedのログが発生する。

対策

redisのtimeout値を長く取るか、定期的にreadの処理を走らせるという対策が考えられる
ただし、PeerClosedのログは本番環境など、頻繁にredisへの処理が走る環境では発生しない
redisにはtimeoutの他にも、出力バッファなど上限を超えるとコネクションを切るようなパラメータも設定されているため、注意が必要

PeerClosedのログの意味

PeerClosed will be sent to the listener if the connection has been closed by the remote endpoint.
Per default, the connection will then automatically be closed from this endpoint as well.
To support half-closed connections set the keepOpenOnPeerClosed member of the Register message to true in which case the connection stays open until it receives one of the above close commands.

要約: コネクションがリモートのエンドポイントから切断されている

redis.actors.RedisClientActor - ConnectionClosedのログの調査

ConnectionClosedは以下のrediscalaから出ているログ

play-redisではrediscalaを使っている

ElastiCache(AWS)のRedisの設定

redisにtimeoutのパラメータが設定されており、値が60(デフォルト値)に設定されていた
そのため、read/writeの処理がtimeout時間中にリクエストされければ、コネクションは切断される

redisの固有パラメータ

redisのtimeoutパラメータ

timeoutの詳細

timeoutは60に設定してるためノードがアイドル状態のクライアントを切断するまでに待機する秒数。となる

ノードがタイムアウトまで待機する秒数。値は次のとおりです。
0 – アイドル状態のクライアントを切断しません。
1-19 – 無効な値です。
`>=20 – ノードがアイドル状態のクライアントを切断するまでに待機する秒数。

アイドル状態とはidle (not requested by read or write operations)らしい
つまり、readとwriteのリクエストがない状態のことを言うらしい

OBJECT IDLETIME returns the number of seconds since the object stored at the specified key is idle (not requested by read or write operations).

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0