[memcached] sgrimm, r316: When sending large responses over TCP,
w...
commits at code.sixapart.com
commits at code.sixapart.com
Wed Aug 23 19:20:57 UTC 2006
When sending large responses over TCP, write the first 1400 (by default)
bytes of data out in its own separate sendmsg() call. On Solaris this
results in a measurable improvement in response latency; there is no
significant impact on Linux.
U branches/facebook/memcached.c
U branches/facebook/memcached.h
Modified: branches/facebook/memcached.c
===================================================================
--- branches/facebook/memcached.c 2006-08-23 19:15:07 UTC (rev 315)
+++ branches/facebook/memcached.c 2006-08-23 19:20:56 UTC (rev 316)
@@ -422,18 +422,24 @@
* Returns 0 on success, -1 on out-of-memory.
*/
-/* TODO: can this *buf be const? */
-int add_iov(conn *c, void *buf, int len) {
+int add_iov(conn *c, const void *buf, int len) {
struct msghdr *m;
int i;
int leftover;
+ int limit_to_mtu;
do {
m = &c->msglist[c->msgused - 1];
+ /*
+ * Limit UDP packets, and the first payloads of TCP replies, to
+ * UDP_MAX_PAYLOAD_SIZE bytes.
+ */
+ limit_to_mtu = c->udp || (1 == c->msgused);
+
/* We may need to start a new msghdr if this one is full. */
if (m->msg_iovlen == IOV_MAX ||
- c->udp && c->msgbytes >= UDP_MAX_PAYLOAD_SIZE) {
+ limit_to_mtu && c->msgbytes >= UDP_MAX_PAYLOAD_SIZE) {
add_msghdr(c);
m = &c->msglist[c->msgused - 1];
}
@@ -442,7 +448,7 @@
return -1;
/* If the fragment is too big to fit in the datagram, split it up */
- if (c->udp && len + c->msgbytes > UDP_MAX_PAYLOAD_SIZE) {
+ if (limit_to_mtu && len + c->msgbytes > UDP_MAX_PAYLOAD_SIZE) {
leftover = len + c->msgbytes - UDP_MAX_PAYLOAD_SIZE;
len -= leftover;
} else {
Modified: branches/facebook/memcached.h
===================================================================
--- branches/facebook/memcached.h 2006-08-23 19:15:07 UTC (rev 315)
+++ branches/facebook/memcached.h 2006-08-23 19:20:56 UTC (rev 316)
@@ -248,7 +248,7 @@
void process_command(conn *c, char *command);
int transmit(conn *c);
int ensure_iov_space(conn *c);
-int add_iov(conn *c, void *buf, int len);
+int add_iov(conn *c, const void *buf, int len);
int add_msghdr(conn *c);
/* stats */
More information about the memcached-commits
mailing list