prometheus/client_java — pull request #50 by brian-brazil (2014-12-12 15:18:45+00:00)
Title: Switch to DoubleAdder for simpleclient, it's more performant.

This pull request depends on https://github.com/prometheus/client_java/pull/49

Add benchmarks for both of our java clients, and a comparison with
codahale/yammer metrics. This is based on internal benchmarks by Will Fleury.

Add caching of the Child when there's no labels. This is the most common use
case, and makes it 4-5x faster than the naive approach.

Performance comparison:
Codehale(a popular java instrumention library) takes 12ns per increment
of a counter uncontended, rising to 18ns with 4 threads

The original client takes 126ns, rising to 245ns with 4 threads.
Incrementing the child takes 13ns, rising to 382ns with 4 threads (odd - it should be <245ns).

With theese changes the Simpleclient's performance goes from:
- Uncontended labels() increment: 70ns -> 54ns
- 2-thread labels() increment: 146ns -> 103ns
- 4-thread labels() increment: 509ns -> 130ns
- Uncontended Child increment: 29ns -> 13ns
- 2-thread Child increment: 102ns -> 16ns
- 4-thread Child increment: 215ns -> 19ns
- Uncontended nolabels convenience increment: 50ns -> 13ns
- 2-thread nolabels convenience increment: 172ns -> 17ns
- 4-thread nolabels convenience increment: 434ns -> 20ns

The new numbers are much faster, and comparable with codehale.
ConcurrentHashMap doesn't seem great with lots of threads, avoiding
that by caching the Child is advised where you have labels and a high rate of concurrent updates.
I tested on a 2-core MacBook Pro with a 2.5GHz i5 processor, Oracle Java 64 1.7.0_51.