-
Notifications
You must be signed in to change notification settings - Fork 26
Description
When using memcached_mget with a single key and cas enabled, the client will send a GETKQ request, wait for it to be acked by the server, and then follows it up by a NOP request. However, Linux delays sending acks until it has some data to reply with or until a timeout occurs. The above request pattern results in the timeout occuring every time the client makes a request. This timeout may be on the order of dozens of milliseconds, increasing the latency of gets commands by up to 1000x that of get commands.
In contrast, memcached_get sends a single GETK request which receives an immediate response, avoiding the delayed ack timeout. However, the CAS value cannot be retrieved with is API.
I have recorded an example PCAP showing the latency difference between memcached_get and memcached_gets in text/binary modes (with the CAS behavior enabled). gets in binary mode takes around 400 ms total, while all other operations take around 1 ms total. This example only performs 10 requests per mode; with 1000s of requests an even larger different may be observed.
I recommend the following improvements:
- Send a single
GETKwhenkey_lengthis 1 (i.e. as ifmget_modeis false). - Don't flush
memcached_io_writevuntil sending the finalNOP(or at least until sending the finalGETKQ). - Add an API to retrieve the CAS value without
mget.