¿Establecer un tamaño de búfer más pequeño para sys.stdin?

Estoy ejecutando memcached con el siguiente patrón de comando bash:

memcached -vv 2>&1 | tee memkeywatch2010098.log 2>&1 | ~/bin/memtracer.py | tee memkeywatchCounts20100908.log

para tratar de rastrear inigualables conjuntos de teclas para toda la plataforma.

El script de memtracer está debajo y funciona según lo deseado, con un problema menor. Al observar el tamaño del archivo de registro intermedio, memtracer.py no comienza a recibir información hasta que memkeywatchYMD.log tiene un tamaño de aproximadamente 15-18K. ¿Hay una mejor manera de leer en stdin o tal vez una forma de reducir el tamaño del búfer a menos de 1k para tiempos de respuesta más rápidos?

#!/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], )

Respuestas a la pregunta(5)

Su respuesta a la pregunta