From: Brian Aker Date: Wed, 23 Jan 2008 04:18:54 +0000 (-0800) Subject: Modifications for IO performance. X-Git-Tag: 0.15~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=174becbbeeb981dc4c497e2bb8916c72fee8e60c;p=m6w6%2Flibmemcached Modifications for IO performance. --- diff --git a/ChangeLog b/ChangeLog index 208aa0a9..cfbf0cdc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ + * Slight performance increase in both read() and write(). + 0.14 Tue Jan 22 06:21:49 PST 2008 * For for bug found by Evan Weaver where increment() was not returning propper error of value was not found. diff --git a/lib/memcached_io.c b/lib/memcached_io.c index 52d91297..9e63fe73 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -93,8 +93,11 @@ ssize_t memcached_io_read(memcached_server_st *ptr, data_read= read(ptr->fd, ptr->read_buffer, MEMCACHED_MAX_BUFFER); - if (data_read == -1) + if (data_read) + break; + else if (data_read == -1) { + ptr->cached_errno= errno; switch (errno) { case EAGAIN: @@ -105,21 +108,15 @@ ssize_t memcached_io_read(memcached_server_st *ptr, if (rc == MEMCACHED_SUCCESS) continue; - - memcached_quit_server(ptr, 1); - return -1; } + /* fall trough */ default: { memcached_quit_server(ptr, 1); - ptr->cached_errno= errno; return -1; } } } - else if (data_read) - break; - /* If zero, just keep looping unless testing, then assert() */ else { WATCHPOINT_ASSERT(0); @@ -148,10 +145,10 @@ ssize_t memcached_io_read(memcached_server_st *ptr, else { *buffer_ptr= *ptr->read_ptr; - length--; ptr->read_ptr++; ptr->read_buffer_length--; buffer_ptr++; + break; } if (found_eof) @@ -164,35 +161,34 @@ ssize_t memcached_io_read(memcached_server_st *ptr, ssize_t memcached_io_write(memcached_server_st *ptr, char *buffer, size_t length, char with_flush) { - unsigned long long x; + size_t original_length; + + original_length= length; - if (length < (MEMCACHED_MAX_BUFFER - ptr->write_buffer_offset )) + while (length) { char *write_ptr; + size_t should_write; + should_write= MEMCACHED_MAX_BUFFER - ptr->write_buffer_offset; write_ptr= ptr->write_buffer + ptr->write_buffer_offset; - memcpy(write_ptr, buffer, length); - ptr->write_buffer_offset+= length; - } - else - { - for (x= 0; x < length; x++) - { - ptr->write_buffer[ptr->write_buffer_offset]= buffer[x]; - ptr->write_buffer_offset++; - WATCHPOINT_ASSERT(ptr->write_buffer_offset <= MEMCACHED_MAX_BUFFER); - if (ptr->write_buffer_offset == MEMCACHED_MAX_BUFFER) - { - memcached_return rc; - ssize_t sent_length; + should_write= (should_write < length) ? should_write : length; - sent_length= io_flush(ptr, &rc); - if (sent_length == -1) - return -1; + memcpy(write_ptr, buffer, should_write); + ptr->write_buffer_offset+= should_write; + length-= should_write; - WATCHPOINT_ASSERT(sent_length == MEMCACHED_MAX_BUFFER); - } + if (ptr->write_buffer_offset == MEMCACHED_MAX_BUFFER) + { + memcached_return rc; + ssize_t sent_length; + + sent_length= io_flush(ptr, &rc); + if (sent_length == -1) + return -1; + + WATCHPOINT_ASSERT(sent_length == MEMCACHED_MAX_BUFFER); } } @@ -203,7 +199,7 @@ ssize_t memcached_io_write(memcached_server_st *ptr, return -1; } - return length; + return original_length; } memcached_return memcached_io_close(memcached_server_st *ptr)