Skip to content

Instantly share code, notes, and snippets.

@danielnorberg
Created September 1, 2012 09:45
Show Gist options
  • Save danielnorberg/3568485 to your computer and use it in GitHub Desktop.
Save danielnorberg/3568485 to your computer and use it in GitHub Desktop.
NonBlockingHashMap unbounded growth and slowdown
import org.cliffc.high_scale_lib.NonBlockingHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class NonBlockingHashMapTest {
static class Progress extends Thread {
public volatile long operations;
public void run() {
while (true) {
long pre = operations;
long start = System.nanoTime();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
long end = System.nanoTime();
long post = operations;
System.out.printf("%s: %,d operations/s (heap size: %,d)\n",
Thread.currentThread().getName(),
1000000000L * (post - pre) / (end - start),
Runtime.getRuntime().totalMemory());
}
}
}
// Start with -Xmx1g to avoid immediately running out of heap space
public static void main(String[] args) {
Map<Object, Object> map = new NonBlockingHashMap<Object, Object>();
// Map<Object, Object> map = new ConcurrentHashMap<java.lang.Object, java.lang.Object>();
Progress progress = new Progress();
progress.setName(map.getClass().getSimpleName());
progress.setDaemon(true);
progress.start();
for (long i = 0;;i++) {
map.put(i, i);
map.remove(i);
progress.operations++;
}
}
}
ConcurrentHashMap: 5,026,568 operations/s (heap size: 85,000,192)
ConcurrentHashMap: 5,569,104 operations/s (heap size: 85,000,192)
ConcurrentHashMap: 5,519,454 operations/s (heap size: 85,000,192)
ConcurrentHashMap: 5,572,655 operations/s (heap size: 85,000,192)
ConcurrentHashMap: 3,929,061 operations/s (heap size: 85,000,192)
ConcurrentHashMap: 4,411,633 operations/s (heap size: 85,000,192)
ConcurrentHashMap: 4,225,931 operations/s (heap size: 85,000,192)
ConcurrentHashMap: 5,239,113 operations/s (heap size: 85,000,192)
ConcurrentHashMap: 5,142,590 operations/s (heap size: 85,000,192)
ConcurrentHashMap: 5,321,935 operations/s (heap size: 85,000,192)
ConcurrentHashMap: 5,084,868 operations/s (heap size: 85,000,192)
...
NonBlockingHashMap: 518,473 operations/s (heap size: 85,000,192)
NonBlockingHashMap: 26,448 operations/s (heap size: 85,000,192)
NonBlockingHashMap: 203,867 operations/s (heap size: 95,551,488)
NonBlockingHashMap: 320,926 operations/s (heap size: 95,551,488)
NonBlockingHashMap: 257 operations/s (heap size: 95,551,488)
NonBlockingHashMap: 157 operations/s (heap size: 95,551,488)
NonBlockingHashMap: 117 operations/s (heap size: 95,551,488)
NonBlockingHashMap: 98 operations/s (heap size: 95,551,488)
NonBlockingHashMap: 85 operations/s (heap size: 95,551,488)
NonBlockingHashMap: 41,062 operations/s (heap size: 139,239,424)
NonBlockingHashMap: 903,932 operations/s (heap size: 213,368,832)
NonBlockingHashMap: 727 operations/s (heap size: 213,368,832)
NonBlockingHashMap: 200 operations/s (heap size: 213,368,832)
NonBlockingHashMap: 177 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 101 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 108 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 109 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 79 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 88 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 74 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 76 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 68 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 66 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 62 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 57 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 49 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 56 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 50 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 55 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 43 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 40 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 45 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 45 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 42 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 41 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 41 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 224,810 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 1,174,176 operations/s (heap size: 314,028,032)
NonBlockingHashMap: 635,854 operations/s (heap size: 332,312,576)
NonBlockingHashMap: 384 operations/s (heap size: 515,465,216)
NonBlockingHashMap: 644 operations/s (heap size: 515,465,216)
NonBlockingHashMap: 219 operations/s (heap size: 515,465,216)
NonBlockingHashMap: 208 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 165 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 124 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 107 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 100 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 101 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 61 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 84 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 65 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 75 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 83 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 51 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 55 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 49 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 59 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 51 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 68 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 42 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 69 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 43 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 45 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 46 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 42 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 43 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 33 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 37 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 49 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 44 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 32 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 13 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 22 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 23 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 30 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 40 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 38 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 43 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 33 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 23 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 21 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 23 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 28 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 36 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 31 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 22 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 29 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 24 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 24 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 34 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 20 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 30 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 27 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 32 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 26 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 27 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 29 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 20 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 21 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 29 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 37 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 22 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 25 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 24 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 24 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 25 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 22 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 28 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 25 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 22 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 30 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 24 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 23 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 23 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 20 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 23 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 25 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 20 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 19 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 23 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 17 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 18 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 18 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 18 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 18 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 19 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 24 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 18 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 18 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 18 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 22 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 13 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 18 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 20 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 19 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 18 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 25 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 20 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 23 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 19 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 19 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 15 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 18 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 17 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 16 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 17 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 19 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 919,503 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 1,028,316 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 845,853 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 472,244 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 472,508 operations/s (heap size: 627,310,592)
NonBlockingHashMap: 0 operations/s (heap size: 991,748,096)
NonBlockingHashMap: 1,117 operations/s (heap size: 991,748,096)
NonBlockingHashMap: 339 operations/s (heap size: 991,748,096)
NonBlockingHashMap: 233 operations/s (heap size: 1,069,416,448)
NonBlockingHashMap: 186 operations/s (heap size: 1,069,416,448)
NonBlockingHashMap: 188 operations/s (heap size: 1,069,416,448)
NonBlockingHashMap: 147 operations/s (heap size: 1,069,416,448)
NonBlockingHashMap: 117 operations/s (heap size: 1,069,416,448)
NonBlockingHashMap: 144 operations/s (heap size: 1,069,416,448)
$ java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
$ uname -a
Darwin daniel-norbergs-macbook-pro.local 12.0.0 Darwin Kernel Version 12.0.0: Sun Jun 24 23:00:16 PDT 2012; root:xnu-2050.7.9~1/RELEASE_X86_64 x86_64
$ system_profiler SPHardwareDataType
Hardware:
Hardware Overview:
Model Name: MacBook Pro
Model Identifier: MacBookPro5,3
Processor Name: Intel Core 2 Duo
Processor Speed: 2.8 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache: 6 MB
Memory: 8 GB
Bus Speed: 1.07 GHz
Boot ROM Version: MBP53.00AC.B03
SMC Version (system): 1.48f2
Serial Number (system): W892406J644
Hardware UUID: 0B38A94F-0980-56CF-8E44-C4ED3546A0B2
Sudden Motion Sensor:
State: Enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment