twitter/ostrich — pull request #66 by daggerrz (2013-11-26 20:47:21+00:00)
Title: Replace Atomics with LongAdder (JSR-166e)

This replaces the use of atomics with the `LongAdder` implementation from JSR-166e (packaged by Twitter, coming in Java 8). It greatly reduces thread contention on metrics that are mutated frequently.

`LongAdder.add()` outperforms `AtomicLong.incrementAndGet()` by several orders of magnitude under heavy contention on multi-core systems, but does not return the current value. Many metric use-cases, however, do not need it, so we have deprecated the old `incr()` method in the API and replaced it with explicit versions of `increment()` and `incrementAndGet()`. The latter still performs significantly better than the atomic version, although just in the 2x range.

`Histogram`s are also updated, but this might be a bit more controversial as it removes thread synchronization and race conditions definitely are introduced due to this. The race conditions will not cause errors, but histograms _will_ not be accurate unless concurrent load is very light. This is perfectly reasonable for our use-case, but you might disagree and I'd be happy to a) remove this from the PR or b) allow the user to specifically ask for an "inaccurate" but fast histogram version while leaving original as a default.

We have been running this branch in production under very heavy load for about 4 weeks now.