binary protocol notes from the facebook hackathon

marc at marc at
Wed Jul 11 07:45:24 UTC 2007

Hi everyone,

I'm happy to see a nice and compact result with zero bloat.  I'm also 
happy you guys kept alignment within the request/response struct and 
that would help performance.

I see byte ordering is mentioned twice;  the length field both in the 
request and response.

While network byte ordering (Big Endian) is traditionally the 'right' 
thing to do (or the default thing to do), in most cases it's a minor 
performance hit due to constant swapping.  Since we're implementing a 
binary protocol specifically to avoid/minimize minor performance hits 
and since this is a brand new protocol I would recommend to keep all 
values as Little Endian because:

- It's easier that all values are kept to a the same endianess; reduces 
- Nowadays MOST (but obviously not all) servers are running little 
endian.   So this saves byte swapping for most people's cases and thus a 
few cycles are spared on each request -- isn't that the whole point? ;)

And since I mentioned alignment at the top;  Would the entire packet, 
including its payload, be aligned?   It can be a waste of up to a three 
bytes per stored object but could potentially improve performance a 
little bit -- something entertaining to benchmark -- think we'll be able 
to notice a timing difference above the noise level? :)


More information about the memcached mailing list