Skip to content

gets in binary mode is unnecessarily slow #149

@Forty-Bot

Description

@Forty-Bot

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 GETK when key_length is 1 (i.e. as if mget_mode is false).
  • Don't flush memcached_io_writev until sending the final NOP (or at least until sending the final GETKQ).
  • Add an API to retrieve the CAS value without mget.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions