Merge lp://qastaging/~athomason/libmemcached/tcpcork into lp://qastaging/~tangent-org/libmemcached/trunk

Proposed by Adam Thomason
Status: Merged
Merged at revision: not available
Proposed branch: lp://qastaging/~athomason/libmemcached/tcpcork
Merge into: lp://qastaging/~tangent-org/libmemcached/trunk
Diff against target: 75 lines (+29/-0)
3 files modified
libmemcached/memcached_io.c (+27/-0)
libmemcached/memcached_server.c (+1/-0)
libmemcached/memcached_server.h (+1/-0)
To merge this branch: bzr merge lp://qastaging/~athomason/libmemcached/tcpcork
Reviewer Review Type Date Requested Status
Libmemcached-developers Pending
Review via email: mp+15051@code.qastaging.launchpad.net
To post a comment you must log in.
Revision history for this message
Adam Thomason (athomason) wrote :

This is behind #ifdef's so should be a no-op for unsupported platforms (non-Linux/BSD/OSX).

Revision history for this message
Brian Aker (brianaker) wrote :

I've got this in a tree, but I am finding that the performance for it is awful.

Did you get good benchmarks for this?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libmemcached/memcached_io.c'
2--- libmemcached/memcached_io.c 2009-10-14 11:40:42 +0000
3+++ libmemcached/memcached_io.c 2009-11-19 20:00:26 +0000
4@@ -142,6 +142,28 @@
5 return false;
6 }
7
8+#ifdef TCP_CORK
9+ #define CORK TCP_CORK
10+#elif defined TCP_NOPUSH
11+ #define CORK TCP_NOPUSH
12+#endif
13+
14+static void memcached_io_cork(memcached_server_st *ptr, int enable)
15+{
16+ #ifdef CORK
17+ if (ptr->type != MEMCACHED_CONNECTION_TCP)
18+ return;
19+
20+ if ((enable && ptr->is_corked) || (!enable && !ptr->is_corked))
21+ return;
22+
23+ int err= setsockopt(ptr->fd, IPPROTO_TCP, CORK,
24+ &enable, (socklen_t)sizeof(int));
25+ if (!err)
26+ ptr->is_corked= enable;
27+ #endif
28+}
29+
30 #ifdef UNUSED
31 void memcached_io_preread(memcached_st *ptr)
32 {
33@@ -268,6 +290,10 @@
34 original_length= length;
35 buffer_ptr= buffer;
36
37+ /* more writable data is coming if a flush isn't required, so delay send */
38+ if (!with_flush)
39+ memcached_io_cork(ptr, 1);
40+
41 while (length)
42 {
43 char *write_ptr;
44@@ -319,6 +345,7 @@
45 WATCHPOINT_ASSERT(ptr->fd != -1);
46 if (io_flush(ptr, &rc) == -1)
47 return -1;
48+ memcached_io_cork(ptr, 0);
49 }
50
51 return (ssize_t) original_length;
52
53=== modified file 'libmemcached/memcached_server.c'
54--- libmemcached/memcached_server.c 2009-10-10 11:57:03 +0000
55+++ libmemcached/memcached_server.c 2009-11-19 20:00:26 +0000
56@@ -38,6 +38,7 @@
57 host->fd= -1;
58 host->type= type;
59 host->read_ptr= host->read_buffer;
60+ host->is_corked= 0;
61 if (memc)
62 host->next_retry= memc->retry_timeout;
63 if (type == MEMCACHED_CONNECTION_UDP)
64
65=== modified file 'libmemcached/memcached_server.h'
66--- libmemcached/memcached_server.h 2009-10-10 11:57:03 +0000
67+++ libmemcached/memcached_server.h 2009-11-19 20:00:26 +0000
68@@ -40,6 +40,7 @@
69 char read_buffer[MEMCACHED_MAX_BUFFER];
70 char write_buffer[MEMCACHED_MAX_BUFFER];
71 char hostname[MEMCACHED_MAX_HOST_LENGTH];
72+ bool is_corked;
73 };
74
75 #define memcached_server_count(A) (A)->number_of_hosts

Subscribers

People subscribed via source and target branches

to all changes: