Patch: Solaris performance tweak
Steven Grimm
sgrimm at facebook.com
Fri Aug 18 08:25:20 UTC 2006
We've been playing with memcached on different OSes to compare
performance. It turns out Solaris 10 does not deal with large
scatter-gather sendmsg() calls in as low-latency a way as Linux. (They
are optimizing for throughput rather than latency, but latency is often
more important in the case of memcached.) So we made the following
change, which has a negligible performance impact on Linux and is a
measurable improvement on Solaris.
Note that we are NOT running this in production yet. It should be safe
-- it's very simple, as you'll see -- but caveat emptor.
This is against the 1.2.0-rc1 source but you should be able to apply it
to the Facebook branch too if you like.
-Steve
-------------- next part --------------
--- memcached.c.orig 2006-08-18 01:16:37.000000000 -0700
+++ memcached.c 2006-08-18 01:19:00.000000000 -0700
@@ -352,13 +352,20 @@
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];
}
@@ -367,7 +374,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 {
More information about the memcached
mailing list