次のbashコマンドパターンでmemcachedを実行しています。
memcached -vv 2>&1 | tee memkeywatch2010098.log 2>&1 | ~/bin/memtracer.py | tee memkeywatchCounts20100908.log
プラットフォーム全体のキーのセットへの比類のない取得を追跡しようとします。
memtracerスクリプトは以下のとおりであり、1つの小さな問題がありますが、希望どおりに機能します。中間ログファイルのサイズを監視すると、memkeywatchYMD.logのサイズが約15〜18Kになるまで、memtracer.pyは入力の取得を開始しません。stdinで読み取るためのより良い方法、または応答時間を短縮するためにバッファーサイズを1k未満に減らす方法はありますか?
#!/usr/bin/python
import sys
from collections import defaultdict
if __name__ == "__main__":
keys = defaultdict(int)
GET = 1
SET = 2
CLIENT = 1
SERVER = 2
#if <
for line in sys.stdin:
key = None
components = line.strip().split(" ")
#newConn = components[0][1:3]
direction = CLIENT if components[0].startswith("<") else SERVER
#if lastConn != newConn:
# lastConn = newConn
if direction == CLIENT:
command = SET if components[1] == "set" else GET
key = components[2]
if command == SET:
keys[key] -= 1
elif direction == SERVER:
command = components[1]
if command == "sending":
key = components[3]
keys[key] += 1
if key != None:
print "%s:%s" % ( key, keys[key], )