LoginSignup
0
0

More than 5 years have passed since last update.

キャッシュサーバが遠くなるとレイテンシは上がるのか。pingとtcpdumpで計算してみた

Posted at

これは何

私の持っているシステムではフロント系サーバからmemcached サーバへ接続回数が結構ある。データセンタ内で今まではフロント系サーバもキャッシュサーバも同一セグメント、物理的にも近くにいた。とある事情でサーバをリプレイスしなくてはならず一時的にそれが違うセグメントで、物理的にも遠く、間にいくつかスイッチとルータが挟まるようになる。これにより新しいフロント系サーバから古いmemcachedサーバに接続するとレイテンシが問題になるかもしれない。ネットワーク的に遠くなると実際にアプリケーションの応答性能の視点で問題になるのか、いまと比べて実際は大した事ないのか判断するために考えたことのメモ。

測定

測定方法

ping のtimeの100回の平均を取る。
pingのtimeは何か -> https://linuxjm.osdn.jp/html/netkit/man8/ping.8.html

往復時間 (round-trip time) と消失パケットの統計が計算される。

なので、単なる往復時間。

TCPにおける遅延は? TCPの場合はパケットごとにACKするので、送りたいもののデータサイズが大きく、パケットの個数が増えると全体としてはそれだけ1パケットあたりの遅延が蓄積されていくことになる。
なので、pingのRTTの増加はそのままレスポンスタイムの遅れに繋がると考えられる。

測定実施

2台のサーバが同一セグメントにある 旧frontサーバ(hoge-old-web) => 旧cacheサーバ(hoge-cache)

[myuser@hoge-old-web ~]$  ping -c 100 xx.xx.xx.xx > ./tmp_to_hoge-cache_ping
[myuser@hoge-old-web ~]$ grep "time="  ./tmp_to_hoge-cache_ping > ./tmp_to_hoge-cache_latency
[myuser@hoge-old-web ~]$ awk '{print $(NF-1)}' tmp_to_hoge-cache_latency | awk -F'=' '{sum+=$2} END{print sum/NR}'
0.14284

0.14 ms くらい

新frontサーバ(hoge-new-web) => 旧cacheサーバ(hoge-cache)

[root@hoge-new-web ~]# ping -c 100 xx.xx.xx.xx > ./tmp_to_hoge-cache_ping
[root@hoge-new-web ~]# grep "time="  ./tmp_to_hoge-cache_ping > ./tmp_to_hoge-cache_latency
[root@hoge-new-web check_latency]# awk '{print $(NF-1)}' tmp_to_hoge-cache_latency | awk -F'=' '{sum+=$2} END{print sum/NR}'
0.16793

0.16 ms くらい

差分

0.16793 - 0.14284 = 0.02509 ms
割合ていうと
0.02509 / 0.14284 * 100 = 17%。

frontへアクセスした時にmemcachedはどれくらい叩かれている?

コードで呼ばれているcacheメソッドの回数も重要だが、遅延全体を考えるならパケットがどれくらい投げられているかが重要。なのでtcpdump でパケット数がどれくらい投げられているのか確認したい。

myuser@hoge-dev-web [~ ] $ sudo tcpdump -i eth0 > ./tmp_tcpdump_to_memcache
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
^C7136 packets captured
7136 packets received by filter   // 全部でこれだけのパケットが1リクエストで通った
0 packets dropped by kernel

その中で memcachedにつなぎにいっているのは?

myuser@hoge-dev-web [~ ] $ grep "xx.xx.xx.xx.11211 >" tmp_tcpdump_to_memcache -c
1579

memcachedから来ているパケットは1リクエスト1579回。(行きも同数。pingのtimeはRTTなので片方の道を通っている回数がわかれば良い。)

最大で増えるレイテンシはどれくらい?

毎回のパケット 0.02509 ms * 1579 = 39.6 ms。ほとんど誤差。気にしなくてもよさそう。

結論

今回の件ではレイテンシはあまり気にしなくても良い。

0
0
0

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
0