From: Brian Aker Date: Wed, 27 May 2009 21:07:38 +0000 (-0700) Subject: Stat fix and storage boost performance. X-Git-Tag: 0.30~2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=cab710477d5208fa4715a1b64f29f332c77033da;p=awesomized%2Flibmemcached Stat fix and storage boost performance. --- diff --git a/ChangeLog b/ChangeLog index 98585a49..42241508 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ 0.30 * Added memcachd_dump command (and framework for memdump tool) * Realigned all structures to remove padding (and line up important bits for 64bit caches. + * Remove some of sprintf() in storage calls(). + * Removed printf() in stat call for unknown stat member. 0.29 Tue May 19 08:26:48 PDT 2009 * Fixed malloc usage to calloc for spots where we need zero filled memory. diff --git a/libmemcached/memcached_constants.h b/libmemcached/memcached_constants.h index 970fd0b4..6d8d00f1 100644 --- a/libmemcached/memcached_constants.h +++ b/libmemcached/memcached_constants.h @@ -65,6 +65,7 @@ typedef enum { MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_INVALID_HOST_PROTOCOL, MEMCACHED_SERVER_MARKED_DEAD, + MEMCACHED_UNKNOWN_STAT_KEY, MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */ } memcached_return; diff --git a/libmemcached/memcached_stats.c b/libmemcached/memcached_stats.c index e6a4e07f..d7e3b8dd 100644 --- a/libmemcached/memcached_stats.c +++ b/libmemcached/memcached_stats.c @@ -30,12 +30,13 @@ static char *memcached_stat_keys[] = { }; -static void set_data(memcached_stat_st *stat, char *key, char *value) +static memcached_return set_data(memcached_stat_st *stat, char *key, char *value) { if(strlen(key) < 1) { - fprintf(stderr, "Invalid key %s\n", key); + WATCHPOINT_STRING(key); + return MEMCACHED_UNKNOWN_STAT_KEY; } else if (!strcmp("pid", key)) { @@ -149,8 +150,11 @@ static void set_data(memcached_stat_st *stat, char *key, char *value) strcmp("accepting_conns", key) == 0 || strcmp("listen_disabled_num", key) == 0)) { - fprintf(stderr, "Unknown key %s\n", key); + WATCHPOINT_STRING(key); + return MEMCACHED_UNKNOWN_STAT_KEY; } + + return MEMCACHED_SUCCESS; } char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *stat, @@ -278,7 +282,11 @@ static memcached_return binary_stats_fetch(memcached_st *ptr, return rc; } - set_data(stat, buffer, buffer + strlen(buffer) + 1); + unlikely((set_data(stat, buffer, buffer + strlen(buffer) + 1)) == MEMCACHED_UNKNOWN_STAT_KEY) + { + WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY); + WATCHPOINT_ASSERT(0); + } } while (1); /* shit... memcached_response will decrement the counter, so I need to @@ -332,7 +340,11 @@ static memcached_return ascii_stats_fetch(memcached_st *ptr, value= string_ptr; value[(size_t)(end_ptr-string_ptr)]= 0; string_ptr= end_ptr + 2; - set_data(stat, key, value); + unlikely((set_data(stat, key, value)) == MEMCACHED_UNKNOWN_STAT_KEY) + { + WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY); + WATCHPOINT_ASSERT(0); + } } else break; diff --git a/libmemcached/memcached_storage.c b/libmemcached/memcached_storage.c index 97ca33cc..97d345bd 100644 --- a/libmemcached/memcached_storage.c +++ b/libmemcached/memcached_storage.c @@ -24,17 +24,17 @@ static char *storage_op_string(memcached_storage_action verb) switch (verb) { case SET_OP: - return "set"; + return "set "; case REPLACE_OP: - return "replace"; + return "replace "; case ADD_OP: - return "add"; + return "add "; case PREPEND_OP: - return "prepend"; + return "prepend "; case APPEND_OP: - return "append"; + return "append "; case CAS_OP: - return "cas"; + return "cas "; default: return "tosserror"; /* This is impossible, fixes issue for compiler warning in VisualStudio */ }; @@ -97,13 +97,30 @@ static inline memcached_return memcached_send(memcached_st *ptr, (unsigned long long)cas, (ptr->flags & MEM_NOREPLY) ? " noreply" : ""); else - write_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "%s %s%.*s %u %llu %zu%s\r\n", - storage_op_string(verb), - ptr->prefix_key, - (int)key_length, key, flags, + { + char *buffer_ptr= buffer; + const char *command= storage_op_string(verb); + + /* Copy in the command, no space needed, we handle that in the command function*/ + memcpy(buffer_ptr, command, strlen(command)); + + /* Copy in the key prefix, switch to the buffer_ptr */ + buffer_ptr= memcpy(buffer_ptr + strlen(command) , ptr->prefix_key, strlen(ptr->prefix_key)); + + /* Copy in the key, adjust point if a key prefix was used. */ + buffer_ptr= memcpy(buffer_ptr + (ptr->prefix_key ? strlen(ptr->prefix_key) : 0), + key, key_length); + buffer_ptr+= key_length; + buffer_ptr[0]= ' '; + buffer_ptr++; + + write_length= (size_t)(buffer_ptr - buffer); + write_length+= snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE, + "%u %llu %zu%s\r\n", + flags, (unsigned long long)expiration, value_length, (ptr->flags & MEM_NOREPLY) ? " noreply" : ""); + } if (ptr->flags & MEM_USE_UDP && ptr->flags & MEM_BUFFER_REQUESTS) { diff --git a/libmemcached/memcached_strerror.c b/libmemcached/memcached_strerror.c index 4b626713..44f8f88a 100644 --- a/libmemcached/memcached_strerror.c +++ b/libmemcached/memcached_strerror.c @@ -74,6 +74,8 @@ char *memcached_strerror(memcached_st *ptr __attribute__((unused)), memcached_re return "THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT"; case MEMCACHED_SERVER_MARKED_DEAD: return "SERVER IS MARKED DEAD"; + case MEMCACHED_UNKNOWN_STAT_KEY: + return "ENCOUNTERED AN UNKNOWN STAT KEY"; case MEMCACHED_MAXIMUM_RETURN: return "Gibberish returned!"; default: diff --git a/tests/output.res b/tests/output.res index a14f45e4..627ed3f9 100644 --- a/tests/output.res +++ b/tests/output.res @@ -41,7 +41,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -78,6 +78,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -114,7 +115,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -151,7 +152,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -188,7 +189,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -225,7 +226,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -262,7 +263,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -299,7 +300,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -336,7 +337,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -373,7 +374,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -410,7 +411,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -447,7 +448,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -484,30 +485,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo -ketama_weighted:10.0.1.1|11211|600|176 -ketama_weighted:10.0.1.2|11211|300|88 -ketama_weighted:10.0.1.3|11211|200|56 -ketama_weighted:10.0.1.4|11211|350|104 -ketama_weighted:10.0.1.5|11211|1000|296 -ketama_weighted:10.0.1.6|11211|800|236 -ketama_weighted:10.0.1.7|11211|950|280 -ketama_weighted:10.0.1.8|11211|100|28 -ketama_weighted:10.0.1.1|11211|600|160 -ketama_weighted:10.0.1.2|11211|300|80 -ketama_weighted:10.0.1.4|11211|350|92 -ketama_weighted:10.0.1.5|11211|1000|272 -ketama_weighted:10.0.1.6|11211|800|216 -ketama_weighted:10.0.1.7|11211|950|256 -ketama_weighted:10.0.1.8|11211|100|24 -ketama_weighted:10.0.1.1|11211|600|176 -ketama_weighted:10.0.1.2|11211|300|88 -ketama_weighted:10.0.1.3|11211|200|56 -ketama_weighted:10.0.1.4|11211|350|104 -ketama_weighted:10.0.1.5|11211|1000|296 -ketama_weighted:10.0.1.6|11211|800|236 -ketama_weighted:10.0.1.7|11211|950|280 -ketama_weighted:10.0.1.8|11211|100|28 +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -544,7 +522,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -581,7 +559,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -618,7 +596,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -655,7 +633,7 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key foo +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY Error 0 -> SUCCESS Error 1 -> FAILURE Error 2 -> HOSTNAME LOOKUP FAILURE @@ -692,78 +670,14 @@ Error 32 -> ACTION QUEUED Error 33 -> A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE Error 34 -> THE HOST TRANSPORT PROTOCOL DOES NOT MATCH THAT OF THE CLIENT Error 35 -> SERVER IS MARKED DEAD -Key Thisismorethentheallottednumberofcharactersfoo -ketama_weighted:10.0.1.1|11211|600|176 -ketama_weighted:10.0.1.2|11211|300|88 -ketama_weighted:10.0.1.3|11211|200|56 -ketama_weighted:10.0.1.4|11211|350|104 -ketama_weighted:10.0.1.5|11211|1000|296 -ketama_weighted:10.0.1.6|11211|800|236 -ketama_weighted:10.0.1.7|11211|950|280 -ketama_weighted:10.0.1.8|11211|100|28 -ketama_weighted:localhost|11221|1|160 -ketama_weighted:localhost|11222|1|160 -ketama_weighted:localhost|11223|1|160 -ketama_weighted:localhost|11224|1|160 -ketama_weighted:localhost|11225|1|160 -ketama_weighted:localhost|11221|1|160 -ketama_weighted:localhost|11222|1|160 -ketama_weighted:localhost|11223|1|160 -ketama_weighted:localhost|11224|1|160 -ketama_weighted:localhost|11225|1|160 -ketama_weighted:localhost|11221|1|160 -ketama_weighted:localhost|11222|1|160 -ketama_weighted:localhost|11223|1|160 -ketama_weighted:localhost|11224|1|160 -ketama_weighted:localhost|11225|1|160 -ketama_weighted:localhost|11221|1|160 -ketama_weighted:localhost|11222|1|160 -ketama_weighted:localhost|11223|1|160 -ketama_weighted:localhost|11224|1|160 -ketama_weighted:localhost|11225|1|160 +Error 36 -> ENCOUNTERED AN UNKNOWN STAT KEY -server 0|localhost|11221 bytes: 3257982 +server 0|localhost|11221 bytes: 3122227 -server 1|localhost|11222 bytes: 3099222 +server 1|localhost|11222 bytes: 3274763 -server 2|localhost|11223 bytes: 3503809 +server 2|localhost|11223 bytes: 3658723 -server 3|localhost|11224 bytes: 3780740 +server 3|localhost|11224 bytes: 3866224 -server 4|localhost|11225 bytes: 3124164 -ketama_weighted:localhost|11221|1|160 -ketama_weighted:localhost|11222|1|160 -ketama_weighted:localhost|11223|1|160 -ketama_weighted:localhost|11224|1|160 -ketama_weighted:localhost|11225|1|160 -ketama_weighted:localhost|11221|1|160 -ketama_weighted:localhost|11222|1|160 -ketama_weighted:localhost|11223|1|160 -ketama_weighted:localhost|11224|1|160 -ketama_weighted:localhost|11225|1|160 -ketama_weighted:localhost|11221|1|160 -ketama_weighted:localhost|11222|1|160 -ketama_weighted:localhost|11223|1|160 -ketama_weighted:localhost|11224|1|160 -ketama_weighted:localhost|11225|1|160 -ketama_weighted:localhost|11221|1|160 -ketama_weighted:localhost|11222|1|160 -ketama_weighted:localhost|11223|1|160 -ketama_weighted:localhost|11224|1|160 -ketama_weighted:localhost|11225|1|160 -ketama_weighted:localhost|11221|1|160 -ketama_weighted:localhost|11222|1|160 -ketama_weighted:localhost|11223|1|160 -ketama_weighted:localhost|11224|1|160 -ketama_weighted:localhost|11225|1|160 -ketama_weighted:localhost|6666|1|160 -ketama_weighted:localhost|11221|1|160 -ketama_weighted:localhost|11222|1|160 -ketama_weighted:localhost|11223|1|160 -ketama_weighted:localhost|11224|1|160 -ketama_weighted:localhost|11225|1|160 -ketama_weighted:localhost|11221|1|160 -ketama_weighted:localhost|11222|1|160 -ketama_weighted:localhost|11223|1|160 -ketama_weighted:localhost|11224|1|160 -ketama_weighted:localhost|11225|1|160 +server 4|localhost|11225 bytes: 3307046