memcachedはキャッシュなので,
memcachedはデータ削除もリソースを有効活用する
memcachedから実際にデータは消えない
前回の記事で紹介させていただきましたが,
Lazy Expiration
memcachedは内部的にレコードがexpireしたかの監視を行いません。替わりにgetする際にレコードのtimestampを見ることで,
LRU: 有効的にキャッシュからデータが消える仕組み
memcached はtimeoutしたレコードの領域を優先的に再利用しますが,
ユースケースによっては,
$ memcached -M -m 1024
スタートアップ時に気をつけないといけない点は,
“-M”
memcachedの最新動向
現在,
バイナリプロトコルに関して
バイナリプロトコルを採用した理由は,
バイナリプロトコルの形式
プロトコルのパケット形式は24バイトの固定長フレーム,
Byte/ 0 | 1 | 2 | 3 |
/ | | | |
|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|
+---------------+---------------+---------------+---------------+
0/ HEADER /
/ /
/ /
/ /
+---------------+---------------+---------------+---------------+
24/ COMMAND-SPECIFIC EXTRAS (as needed) /
+/ (note length in th extras length header field) /
+---------------+---------------+---------------+---------------+
m/ Key (as needed) /
+/ (note length in key length header field) /
+---------------+---------------+---------------+---------------+
n/ Value (as needed) /
+/ (note length is total body length header field, minus /
+/ sum of the extras and key length body fields) /
+---------------+---------------+---------------+---------------+
Total 24 bytes
ご覧の通り,
Request Header
Byte/ 0 | 1 | 2 | 3 |
/ | | | |
|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|
+---------------+---------------+---------------+---------------+
0| Magic | Opcode | Key length |
+---------------+---------------+---------------+---------------+
4| Extras length | Data type | Reserved |
+---------------+---------------+---------------+---------------+
8| Total body length |
+---------------+---------------+---------------+---------------+
12| Opaque |
+---------------+---------------+---------------+---------------+
16| CAS |
| |
+---------------+---------------+---------------+---------------+
Response Header
Byte/ 0 | 1 | 2 | 3 |
/ | | | |
|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|
+---------------+---------------+---------------+---------------+
0| Magic | Opcode | Key Length |
+---------------+---------------+---------------+---------------+
4| Extras length | Data type | Status |
+---------------+---------------+---------------+---------------+
8| Total body length |
+---------------+---------------+---------------+---------------+
12| Opaque |
+---------------+---------------+---------------+---------------+
16| CAS |
| |
+---------------+---------------+---------------+---------------+
各々の要素に関して詳しく知りたい場合は,
HEADERを見て気になる点
HEADERの形式を見て私が思ったことは,
バイナリプロトコルは次世代の1.