binary protocol motivations

Tomash Brechko tomash.brechko at gmail.com
Tue Nov 13 10:26:49 UTC 2007


On Tue, Nov 13, 2007 at 13:09:15 +0300, Tomash Brechko wrote:
> Since you want to query lots of data, I guess <tag> is more than one
> byte, right (otherwise you can query at most 256 items in one
> streaming round)?

Actually I know the size, it's 4 bytes:

  RESPONSE STRUCTURE:

    * Magic byte / version (different from req's magic byte/version,
      to distinguish that it's a response for, say, protocol
      analyzers)
    * cmd byte (same as response it goes to)
    * err code byte (0 on success, else errcode.  hit bit set if
      fatal/non-normal error)
    * Reserved byte (should be 0)
!>  * 4 byte opaque id copied back from response
    * 4 byte body length (network order; not including 12 byte header)
    [cmd-specific body]


You may encode not_found reply as 

    * Magic byte / version (different from req's magic byte/version,
      to distinguish that it's a response for, say, protocol
      analyzers)
    * cmd byte (same as response it goes to)
    * err code byte (NOT_FOUND)


So you'll save 4 bytes on positive response and a cost of 3 bytes on
negative responce.  With the hit rate > 43%, you'll have the saving.


-- 
   Tomash Brechko


More information about the memcached mailing list