From: Trond Norbye Date: Sun, 3 May 2009 19:27:56 +0000 (-0700) Subject: Added support for MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH X-Git-Tag: 0.29~10 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b10a03e4afb5514f1c86f5c75b9bfc7d46ce49b4;p=m6w6%2Flibmemcached Added support for MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH From the man page: The binary protocol works a bit different than the textual protocol in the way that a multiget is implemented as a pipe of single get-operations that is sent to the server in a chunk. If you use large multigets you may improve the latency by setting this value so that you send out the first chunk of requests when you hit the specified limit, allowing the server to start processing the request and send the data back while the rest of the requests is created. --- diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index 2799dcce..26a35ec9 100755 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -178,6 +178,16 @@ at least 10 IO requests sent without reading the input buffer). Setting this value to high, may cause libmemcached to deadlock (trying to send data, but the send will block because the input buffer in the kernel is full). +=item MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH + +The binary protocol works a bit different than the textual protocol in the +way that a multiget is implemented as a pipe of single get-operations that +is sent to the server in a chunk. If you use large multigets you may improve +the latency by setting this value so that you send out the first chunk of +requests when you hit the specified limit, allowing the server to start +processing the request and send the data back while the rest of the +requests is created. + =item MEMCACHED_BEHAVIOR_NOREPLY Set this value to specify that you really don't care about the result diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 5f8f308b..52b3834b 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -111,6 +111,7 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) new_clone->server_failure_limit= source->server_failure_limit; new_clone->io_msg_watermark= source->io_msg_watermark; new_clone->io_bytes_watermark= source->io_bytes_watermark; + new_clone->io_key_prefetch= source->io_key_prefetch; if (source->hosts) rc= memcached_server_push(new_clone, source->hosts); diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index aceab59b..a8865a7b 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -117,6 +117,7 @@ struct memcached_st { uint32_t server_failure_limit; uint32_t io_msg_watermark; uint32_t io_bytes_watermark; + uint32_t io_key_prefetch; time_t next_distribution_rebuild; }; diff --git a/libmemcached/memcached_behavior.c b/libmemcached/memcached_behavior.c index 77c9bd3b..fb201d4e 100644 --- a/libmemcached/memcached_behavior.c +++ b/libmemcached/memcached_behavior.c @@ -30,6 +30,9 @@ memcached_return memcached_behavior_set(memcached_st *ptr, case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK: ptr->io_bytes_watermark= (int32_t)data; break; + case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH: + ptr->io_key_prefetch = (int32_t)data; + break; case MEMCACHED_BEHAVIOR_SND_TIMEOUT: ptr->snd_timeout= (int32_t)data; break; @@ -170,6 +173,8 @@ uint64_t memcached_behavior_get(memcached_st *ptr, return ptr->io_msg_watermark; case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK: return ptr->io_bytes_watermark; + case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH: + return ptr->io_key_prefetch; case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL: temp_flag= MEM_BINARY_PROTOCOL; break; diff --git a/libmemcached/memcached_constants.h b/libmemcached/memcached_constants.h index 9133a262..db9c2a73 100644 --- a/libmemcached/memcached_constants.h +++ b/libmemcached/memcached_constants.h @@ -99,6 +99,7 @@ typedef enum { MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK, + MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH, MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY, MEMCACHED_BEHAVIOR_NOREPLY, MEMCACHED_BEHAVIOR_USE_UDP, diff --git a/libmemcached/memcached_get.c b/libmemcached/memcached_get.c index 9d33a85c..4d5fe7ca 100644 --- a/libmemcached/memcached_get.c +++ b/libmemcached/memcached_get.c @@ -311,7 +311,8 @@ static memcached_return binary_mget_by_key(memcached_st *ptr, if ((memcached_io_write(&ptr->hosts[server_key], request.bytes, sizeof(request.bytes), 0) == -1) || (memcached_io_write(&ptr->hosts[server_key], keys[x], - key_length[x], flush) == -1)) + key_length[x], + flush || (x > 0 && x == ptr->io_key_prefetch)) == -1)) { memcached_server_response_reset(&ptr->hosts[server_key]); rc= MEMCACHED_SOME_ERRORS; diff --git a/tests/function.c b/tests/function.c index 485a95cc..bd03ee70 100644 --- a/tests/function.c +++ b/tests/function.c @@ -217,6 +217,7 @@ static test_return clone_test(memcached_st *memc) assert(clone->hash_continuum == memc->hash_continuum); assert(clone->io_bytes_watermark == memc->io_bytes_watermark); assert(clone->io_msg_watermark == memc->io_msg_watermark); + assert(clone->io_key_prefetch == memc->io_key_prefetch); assert(clone->on_cleanup == memc->on_cleanup); assert(clone->on_clone == memc->on_clone); assert(clone->poll_timeout == memc->poll_timeout);