Permalink
Commits on Nov 5, 2008
  1. auto detect the number of cpus

    Summary: Instead of relying on -t to run on greater than 4 cpu systems, auto detect the number of active processors
    
    Reviewed By: ttung
    
    Test Plan: ran memcached on 8 core machine, 9 threads created.  ran on 4 core machine, 5 threads created.
    
    Revert: OK
    ps committed Nov 5, 2008
Commits on Oct 16, 2008
  1. Bump version number of memcached

    Summary: Prepare to release 1.2.3e
    
    Reviewed By: ttung
    
    Test Plan: running in production
    
    Revert: OK
    ps committed Oct 16, 2008
Commits on Oct 15, 2008
  1. if item_storage_allocated is per-thread, we actually allocate (#threa…

    …d) * memlimit
    
    Summary: accumulate item_storage_allocated before reading.  this should happen infrequently enough that it won't kill system performance.
    
    Reviewed By: ps
    
    Test Plan: ran it with mcblaster cmdline:
               ./mcblaster -p 15151 -u 15151 -c 32 -k 1000000 -x 4 -w 50000 -r 50000 -z 8192 127.0.0.1
               
               resident memory went to about 100mb, but dropped back to ~66mb after i killed mcblaster.
    
    Revert: OK
    ttung committed Oct 15, 2008
Commits on Oct 1, 2008
  1. Initial check-in of a polling memcached load generator. This still needs

    work, particularly:
      - at high rates (>120K req/sec) UDP replies get mismatched, 
        resulting in a steady stream of error messages and a trashed run.
      - split off components (rqwheel, conn, dgram_ap, thread) into separate files
      - documentation
      - more testing, optimization
    
    Even in its present state I was able to get over 150K UDP gets/sec with 2 threads at which point my 4-core memcached server starts showing signs of saturation. ~120K UDP gets/sec with a single thread.
    march committed Oct 1, 2008
Commits on Sep 28, 2008
  1. remove unneeded assert for stats locking

    Summary: stats are gotten via TLS, so there's no reason to assert verify the threadid when locking.  This also resolves a bug where stats aggregation runs from any thread and therefore the assert would be wrong.
    
    Reviewed By: marc
    
    Test Plan: Ran in production before and got an assertion before.  Ran in production after this change and the assertion did not come up.
    
    Revert: OK
    ps committed Sep 28, 2008
Commits on Sep 24, 2008
  1. make cache_lock adaptive

    Summary: the cache_lock in memcached is now our "giant" lock and is a source of much contention.  by making it adaptive, performance on an 8 core system with 8 server threads goes from 240,000 gets/s to over 300,000.
    
    Reviewed By: sgrimm
    
    Test Plan: ran stress test
               
               blasted with both tcp and udp requests
    
    Revert: OK
    ps committed Sep 24, 2008
  2. move stats collection in memcached to per-thread

    Summary: Remove the global stats lock and collect stats per thread and aggregate only when the stats command is issued.
             
             The prefix, bucket and cost-benefit stats still use a global lock, but they are not enabled in normal operation, so they were not addressed here.
             
             Prior to this change, on an 8 core system, peak req/s is around 160,000 with 8 server threads.  With this change, peak req/s is 240,000.
    
    Reviewed By: marc
    
    Test Plan: Ran tester with asserts on and off.   Ran libmcc against server and verified stats matched what libmcc tester reports.
               
               Have not run in production yet.
               
               Have not blasted with UDP other than using libmcc
    
    Revert: OK
    ps committed Sep 24, 2008
Commits on Sep 19, 2008
  1. fix flat allocator tests to work with new connection buffer group scheme

    Summary: n/a
    
    Reviewed By: ps
    
    Test Plan: passed flat allocator tests.
    
    Revert: OK
    ttung committed Sep 19, 2008
Commits on Sep 18, 2008
  1. flat allocator broken by my last change

    Summary: oops, i'm dumb.
    
    Reviewed By: ps
    
    Test Plan: compiled.
    
    Revert: OK
    ttung committed Sep 18, 2008
  2. connection buffers are per-thread to avoid lock contention

    Summary: - A connection buffer group is created per thread.  It gets the thread id so if asserts are compiled in, it can determine if it is being used by a different thread.
             - conn_new and dispatch_conn_new no longer needs an initial read buffer size.  it is meaningless in the context of connection buffers.
             
             Minor change:
             - udp support for stress test
    
    Reviewed By: ps
    
    Test Plan: ran stress test with asserts on for 1 hr with 4 clients that reconnect every 15 minutes.
               
               ran in production with asserts on for 10 minutes (and still going...)
    
    Revert: OK
    ttung committed Sep 18, 2008
Commits on Sep 16, 2008
  1. killed non-threaded operation

    Summary: self explanatory
    
    Reviewed By: ps
    
    Test Plan: ran stress test for 1 hr
    
    Revert: OK
    ttung committed Sep 16, 2008
Commits on Sep 9, 2008
  1. crank up the udp receive buffer to avoid dropping gets

    Summary: maximize_sndbuf was broken in that it was expecting setsockopt to fail when being asked to set the send buffer to a size larger than permitted.  it actually might not, so use getsockopt to observe the effect of the setsockopt.
    
    Reviewed By: ps
    
    Test Plan: ran with -vv
    
    Revert: OK
    ttung committed Sep 9, 2008
Commits on Sep 4, 2008
  1. ip stamp not refreshed when reusing connection

    Summary: when we reuse a connection, we don't save the ip address.  therefore, we write the ip address of a previous connection instead of the current ip address.
             
             some tweaking to the stress test loader to find the shared library.
    
    Reviewed By: ps
    
    Test Plan: ran with asserts on, spawned multiple connections and the assert did not fire.
    
    Revert: OK
    ttung committed Sep 4, 2008
Commits on Aug 28, 2008
  1. fix slab allocator

    Summary: slab allocator build was broken by last checkin (allowing keys to be split across chunks in flat allocator)
    
    Reviewed By: marc
    
    Test Plan: ran stress test for about 1 hour
    
    Revert: OK
    ttung committed Aug 28, 2008
Commits on Aug 21, 2008
  1. open the maps file before we drop root privileges

    Summary: once we drop root privileges, we cannot open the maps file.
    
    Reviewed By: ps
    
    Test Plan: started memcached with sudo and -u nobody.  did a stats maps.  flooded memcached with sets to force it to do a brk.  did a stats maps.  diffed the outputs to verify that rewinding and rereading the file works.
    
    Revert: OK
    ttung committed Aug 21, 2008
Commits on Jul 29, 2008
  1. the flat allocator uses space inefficiently when there are keys that …

    …don't fit in a small chunk
    
    Summary: If we size small chunks too big, we're wasting space on small items.  If we size small chunks too small, then keys that don't fit in a small chunk get autopromoted to a large chunk.  That's pretty wasteful too.  So this change allows us to split keys across multiple chunks.
             
             minor tweaks:
             - use memcmp instead of strncmp (so I can stop having to look up the definition of strncmp with respect to null termination).
             - #defined the format string for stats_prefix_dump so we can get compiler warnings when the format makes no sense.
    
    Reviewed By: ps
    
    Test Plan: libmcc test/test.py passes.
               flat storage unit tests pass.
               stress test passes.
               ran in production for a few days without any issues.
    
    Revert: OK
    ttung committed Jul 29, 2008
Commits on Jul 8, 2008
  1. merge LRU queues, other fixes.

    Summary: What's life without a memcached diff in diffcamp? :)
             
             There are two key changes:
             
             1) here is that there is now only one LRU queue.  There's no benefit to maintaining two queues, but offers simpler code.
             2) do_add_delta takes a key/nkey pair instead of an item pointer.  this has two key advantages:
             a) it avoids us having to look up the item again when we don't do an update-in-place, since there is no race condition between the item_get and the add_delta locks.
             b) it is enormously helpful when we allow the splitting of keys across data chunks, as now we have a contiguous copy of the key.
             
             Other changes include:
             - warnings are now errors, except "deprecated" warnings (generated by OSX, ugh) which are ignored.
             - assoc_delete no longer requires that the item we delete be the one expected, since this assumption can be wrong when there are race conditions.
             - prefix stats now take a key/nkey pair instead of just key, since keys are no longer null-terminated.
             - append_to_buffer didn't properly reserve space for the terminator.
    
    Reviewed By: marc
    
    Test Plan: stress test passes.
               libmcc tests pass.
               flat allocator unit tests pass.
               ran in production.
    
    Revert: OK
    ttung committed Jul 8, 2008
Commits on Jun 16, 2008
  1. connection buffer sharing

    Summary: - create a pool of connection buffers.  these are giant buffers that are just mmaped.  if we don't use it all, then we never fault in the page.
             - track the maximum usage of a buffer.  the client code must report how much of the buffer it used, otherwise the module assumes the entire buffer was touched.
             - if a buffer goes beyond a certain limit, we throw it away back to the OS.  if a global limit is hit, we also start reclaiming free buffers.
             - when getting a buffer, the module will always return the buffer that was used the most.  this allows us to minimize the amount of memory touched.
    
    Reviewed By: ps
    
    Test Plan: - ran the stress test against memcached with alloc_conn_buffer randomly returning NULL.  libmcc reported a lot of errors (not surprising) but memcached did not crash.
               - ran with freelist_check on, which ensures that the connection buffer free list is sane.
               - ran with conn_buffer_corruption_detection, which takes every buffer returned from memcached, and marks it unreadable/unwritable.  if memcached subsequently accesses this memory, it will segfault.  this ran fine until the OS refused to give us the same page back, but it was at least a few minutes.
               - the test/conn_buffer_test/* code is a stub that i never finished since the two checks embedded in the code are pretty thorough.  maybe one day. :)
               - this has run in production.
    
    Revert: OK
    ttung committed Jun 16, 2008
Commits on Jun 12, 2008
  1. fixes to item_walk, a unit test for item_walk

    Summary: item_walk had some bugs for extracting the middle part of an item.  we never do that (we get the entire item for arithmetic/send/receive, and we get the end for memset/stamping), so this probably shouldn't actually make a difference.  still, it is good to fix.
             
             also added some unit tests for item_walk (which is how the bugs were found).
             
             This includes http://www.dev.facebook.com/intern/diffcamp/?tab=review&revisionID=13628
    
    Reviewed By: marc
    
    Test Plan: all flat allocator tests pass
    
    Revert: OK
    ttung committed Jun 12, 2008
  2. fixes to flat allocator, stats gathering, etc.

    Summary: general fixes:
             1) account for expire items properly in stats.
             2) added a stat-bucket test.
             3) renamed gets to hits for stats-by-bucket.
             4) modified tests to check expire stats.
             
             flat allocator fixes:
             1) flat allocator is sometimes more efficient with large objects.  fixed evict tests so that they work with the flat allocator.
             2) item_memcpy_from, item_memcpy_to, item_memset, item_strtoul, add_item_to_iov, item_setup_receive all share the basic framework.  refactored the code into an ITEM_WALK macro so that fixes can be shared.
    
    Reviewed By: marc
    
    Test Plan: the following tests pass with the flat allocator:
               test/{cost_benefit_stats,metaget_test,prefix_stats,stats_buckets}.py pass
               libmcc/test/test.py -a 
               libmcc/test/test.py -a --binary
    
    Revert: OK
    ttung committed Jun 12, 2008
Commits on May 28, 2008
  1. Do not hard code the use of -ldl

    Summary: Not all operating system have -ldl, so check for it's existence with autoconf.
    
    Reviewed By: ttung
    
    Test Plan: Builds on systems without -ldl and systems with -ldl.
    
    Revert: OK
    ps committed May 28, 2008
Commits on May 15, 2008
  1. Test for client support of udp reply ports

    Summary: Abuse the last 2 bytes of the UDP header to encode the number of udp reply ports the client supports.  If the client supports less ports than the server has configured, use the receive socket to transmit the reply on.
             
             While I'm here, make sure no dns requests are done in allocate_udp_reply_port.
    
    Reviewed By: marc
    
    Test Plan: Compiled libmcc without udp reply ports and responses were sent out on port 11300.  Compiled libmcc with udp reply ports and saw responses come from configured reply ports.  Set the # of reply ports to < # of threads in memcached, and the responses came from port 11300.
    
    Revert: OK
    ps committed May 15, 2008
Commits on May 14, 2008
  1. re-add file lost in merge

    ttung committed May 14, 2008
  2. move refactor tree to trunk

    ttung committed May 14, 2008
  3. last port from trunk to storage refactor tree

    Summary: Porting paul's multi-udp port changes to refactor tree.
             
             With this change, the storage refactor tree will have all of the changes in trunk.  Following this checkin, I plan on copying everything in the storage refactor tree back to trunk, i.e., https://trac.facebook.com/trac/browser/projects/memcached/branches/memcached-storage to https://trac.facebook.com/trac/browser/projects/memcached/trunk
             
             Please let me know if you have any objections.  I'm expanding the audience a bit on the CRR as to give potentially interested parties a chance to object.
    
    Reviewed By: ps
    
    Test Plan: configure and build.
    
    Revert: OK
    ttung committed May 14, 2008
Commits on May 13, 2008
  1. port changes from trunk to storage refactor tree

    Summary: most of these changes have been reviewed before.  the key change is for last-update time and ip address timestamping for flat allocator.
    
    Reviewed By: marc
    
    Test Plan: libmcc test/test.py -a passes
               libmcc test/test.py -a --binary passes
               
               test/prefix_stats.py passes
               test/cost_benefit_stats.py passes
    
    Revert: OK
    ttung committed May 13, 2008
  2. port changes from trunk to storage refactor tree

    Summary: most of these changes have been reviewed before.  the key change is for last-update time and ip address timestamping for flat allocator.
    
    Reviewed By: marc
    
    Test Plan: libmcc test/test.py -a passes
               libmcc test/test.py -a --binary passes
               
               test/prefix_stats.py passes
               test/cost_benefit_stats.py passes
    
    Revert: OK
    ttung committed May 13, 2008
  3. removed two SConstruct files

    Summary: use auto* for stress test, moved metaget into tests directory.
    
    Reviewed By: marc
    
    Test Plan: ran bootstrap, configure, and make for stress test.
    
    Revert: OK
    ttung committed May 13, 2008
Commits on May 8, 2008
  1. Allocate per-thread udp reply ports

    Summary: For UDP on Linux, the transmit path is heavily contended when multiple threads are transmitting on the same socket.  Allocate per-thread udp socket to sent response packets to.
             
             Feature is only used when configured with --enable-udp-reply-ports and the -x option given on the command line.
    
    Reviewed By: ttung
    
    Test Plan: modified libmcc to not ignore packets from different source ports.  ran load-mcc against memcache server and pushed server to 200,000 pps where before the limit was ~65,000 pps
    
    Revert: OK
    ps committed May 8, 2008
  2. Fix build when stat buckets or cost-benefit-stats are not enabled

    Summary: memcached fails to build if not configured with --enable-stat-buckets   and  --enable-cost-benefit-stats
    
    Reviewed By: marc
    
    Test Plan: it builds.. no real functional changes
    
    Revert: OK
    ps committed May 8, 2008
Commits on May 7, 2008
  1. improved stress test by segmenting keyspace into "normal" ops and ari…

    …thmetic ops
    
    Summary: other changes:
             1) added overlapping keyspace region, where both set ops and arithmetic ops will take place.  this will exercise the code path that requires arithmetic ops to zero out values that  can't be converted to a numerical value.
             2) on a arithmetic op miss, execute a set (mimicking the /tfb/www/trunk behavior.
             3) fixed memory leak with arith ops.
    
    Reviewed By: marc
    
    Test Plan: stress test for 5 minutes
    
    Revert: OK
    ttung committed May 7, 2008
  2. add cost benefit stats to memcached

    Summary: cost: slot-seconds
             benefit: hits
             
             additional tweaks:
             1) merged calls for size-buckets and cost-benefit stat collection
             2) removed \r\n from consideration in stat bytecounting
             3) removed the number of STAT_LOCK() and STAT_UNLOCK() calls by merging stat gathering blocks of code together
             4) "lifetime" -> "avrg lifetime" for size buckets
             5) reduced references to current_time, which is volatile
    
    Reviewed By: marc
    
    Test Plan: libmcc/test/test.py -a passes
               test/prefix_stats.py passes
               test/cost_benefit_stats.py passes
    
    Revert: OK
    ttung committed May 7, 2008
  3. add cost benefit stats to memcached

    Summary: cost: slot-seconds
             benefit: hits
             
             additional tweaks:
             1) merged calls for size-buckets and cost-benefit stat collection
             2) removed \r\n from consideration in stat bytecounting
             3) removed the number of STAT_LOCK() and STAT_UNLOCK() calls by merging stat gathering blocks of code together
             4) "lifetime" -> "avrg lifetime" for size buckets
             5) reduced references to current_time, which is volatile
    
    Reviewed By: marc
    
    Test Plan: libmcc/test/test.py -a passes
               test/prefix_stats.py passes
               test/cost_benefit_stats.py passes
    
    Revert: OK
    ttung committed May 7, 2008
  4. add cost benefit stats to memcached

    Summary: cost: slot-seconds
             benefit: hits
             
             additional tweaks:
             1) merged calls for size-buckets and cost-benefit stat collection
             2) removed \r\n from consideration in stat bytecounting
             3) removed the number of STAT_LOCK() and STAT_UNLOCK() calls by merging stat gathering blocks of code together
             4) "lifetime" -> "avrg lifetime" for size buckets
             5) reduced references to current_time, which is volatile
    
    Reviewed By: marc
    
    Test Plan: libmcc/test/test.py -a passes
               test/prefix_stats.py passes
               test/cost_benefit_stats.py passes
    
    Revert: OK
    ttung committed May 7, 2008
  5. binary protocol reply was not getting the flags parameter

    Summary: binary protocol reply was not getting the flags parameter.
             
             removed some references to current_time by only reading it once per function (it is a volatile).
    
    Reviewed By: marc
    
    Test Plan: test/test.py -a passes
               test/test.py -a --binary passes
    
    Revert: OK
    ttung committed May 7, 2008