├── .gitignore ├── DirectMemory-Cache ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.ltk.core.refactoring.prefs │ └── org.maven.ide.eclipse.prefs ├── bench.bat ├── bench.sh ├── config │ └── logback-test.xml ├── data │ └── benchmarks │ │ ├── database.h2.db │ │ └── graphs │ │ ├── org.directmemory.serialization.test.SerializerTest-run1.html │ │ ├── org.directmemory.serialization.test.SerializerTest-run1.json │ │ ├── org.directmemory.serialization.test.SerializerTest-run2.html │ │ ├── org.directmemory.serialization.test.SerializerTest-run2.json │ │ ├── org.directmemory.serialization.test.SerializerTest-run3.html │ │ ├── org.directmemory.serialization.test.SerializerTest-run3.json │ │ ├── org.directmemory.serialization.test.SerializerTest-run4.html │ │ ├── org.directmemory.serialization.test.SerializerTest-run4.json │ │ ├── org.directmemory.serialization.test.SerializerTest-run5.html │ │ ├── org.directmemory.serialization.test.SerializerTest-run5.json │ │ ├── org.directmemory.serialization.test.SerializerTest.html │ │ └── org.directmemory.serialization.test.SerializerTest.json ├── lib │ ├── javasimon │ │ ├── eval-0.5.jar │ │ ├── javasimon-core-2.4.0.jar │ │ ├── sjsxp.jar │ │ └── stax-api-1.0.1.jar │ ├── orientdb │ │ ├── orient-commons-0.9.24.jar │ │ └── orientdb-core-0.9.24.jar │ ├── protostuff │ │ ├── protostuff-api-1.0.0.M6.jar │ │ ├── protostuff-benchmark-1.0.0.M6.jar │ │ ├── protostuff-codegen-1.0.0.M6.jar │ │ ├── protostuff-compiler-1.0.0.M6.jar │ │ ├── protostuff-core-1.0.0.M6.jar │ │ ├── protostuff-json-1.0.0.M6.jar │ │ ├── protostuff-maven-plugin-1.0.0.M6.jar │ │ ├── protostuff-model-1.0.0.M6.jar │ │ ├── protostuff-model-json-1.0.0.M6.jar │ │ ├── protostuff-parser-1.0.0.M6.jar │ │ ├── protostuff-runtime-1.0.0.M6.jar │ │ ├── protostuff-xml-1.0.0.M6.jar │ │ └── protostuff-yaml-1.0.0.M6.jar │ └── slf4j │ │ ├── logback-classic-0.9.26.jar │ │ ├── logback-core-0.9.26.jar │ │ └── slf4j-api-1.6.1.jar ├── pom.xml ├── snapshot.cmd └── src │ ├── main │ ├── aspect │ │ └── org │ │ │ └── directmemory │ │ │ └── monitoring │ │ │ └── Performance.aj │ └── java │ │ └── org │ │ └── directmemory │ │ ├── cache │ │ └── Cache.java │ │ ├── measures │ │ ├── Every.java │ │ ├── Expires.java │ │ ├── For.java │ │ ├── Heap.java │ │ ├── In.java │ │ ├── Memory.java │ │ ├── Monitor.java │ │ ├── Ram.java │ │ ├── Sizing.java │ │ └── Space.java │ │ ├── memory │ │ ├── MemoryManager.java │ │ ├── OffHeapMemoryBuffer.java │ │ └── Pointer.java │ │ ├── misc │ │ ├── DummyPojo.java │ │ └── Format.java │ │ └── serialization │ │ ├── DummyPojoSerializer.java │ │ ├── ProtoStuffSerializerV1.java │ │ ├── ProtoStuffWithLinkedBufferSerializer.java │ │ ├── Serializer.java │ │ └── StandardSerializer.java │ └── test │ └── java │ └── org │ └── directmemory │ ├── cache │ └── test │ │ ├── CacheConcurrentTests.java │ │ ├── CacheLightConcurrentTest.java │ │ └── TestCachePlusSerialization.java │ ├── memory │ └── test │ │ ├── BaseTests.java │ │ ├── ConcurrentTests.java │ │ ├── ConcurrentTests2.java │ │ ├── ConcurrentTests3.java │ │ ├── MallocTests.java │ │ ├── MemoryManagerTests.java │ │ └── Starter.java │ ├── preliminary │ └── test │ │ ├── MicroBenchmarks.java │ │ └── PreliminarBenchmarks.java │ └── serialization │ └── test │ └── SerializerTest.java ├── LICENSE.txt ├── Misc ├── Artwork │ ├── Apache DirectMemory.svg │ ├── Apache-DirectMemory-2.png │ ├── Apache-DirectMemory-3.png │ ├── Apache-DirectMemory-4.png │ ├── Apache-DirectMemory-logo-medium.png │ ├── Apache-DirectMemory-logo.png │ ├── Apache-DirectMemory.png │ ├── Benchmark data │ │ ├── Benchmark.xls │ │ ├── ConcurrentHashMap benchmark.txt │ │ ├── Serialization comparison 2.txt │ │ ├── Serialization comparison.txt │ │ ├── average.PNG │ │ ├── cachemanager2-directmemory.log │ │ ├── orient doc vs binary.txt │ │ └── totalTestTime.PNG │ ├── DirectMemory-Cache-logo-medium.png │ ├── DirectMemory-Cache-logo-small.png │ ├── DirectMemory-Cache-logo-with-banner.png │ ├── DirectMemory-Cache-logo.png │ ├── DirectMemory-Cache-logo.svg │ ├── DirectMemory-icon.png │ └── apache penna.png └── mvn-repo │ └── snapshots │ └── org │ └── directmemory │ └── DirectMemory-Cache │ ├── 0.5.5-SNAPSHOT │ ├── DirectMemory-Cache-0.5.5-20110917.125705-2.jar │ ├── DirectMemory-Cache-0.5.5-20110917.125705-2.jar.md5 │ ├── DirectMemory-Cache-0.5.5-20110917.125705-2.jar.sha1 │ ├── DirectMemory-Cache-0.5.5-20110917.125705-2.pom │ ├── DirectMemory-Cache-0.5.5-20110917.125705-2.pom.md5 │ ├── DirectMemory-Cache-0.5.5-20110917.125705-2.pom.sha1 │ ├── DirectMemory-Cache-0.5.5-20110917.163520-3.jar │ ├── DirectMemory-Cache-0.5.5-20110917.163520-3.jar.md5 │ ├── DirectMemory-Cache-0.5.5-20110917.163520-3.jar.sha1 │ ├── DirectMemory-Cache-0.5.5-20110917.163520-3.pom │ ├── DirectMemory-Cache-0.5.5-20110917.163520-3.pom.md5 │ ├── DirectMemory-Cache-0.5.5-20110917.163520-3.pom.sha1 │ ├── DirectMemory-Cache-0.5.5-20110922.062228-4.jar │ ├── DirectMemory-Cache-0.5.5-20110922.062228-4.jar.md5 │ ├── DirectMemory-Cache-0.5.5-20110922.062228-4.jar.sha1 │ ├── DirectMemory-Cache-0.5.5-20110922.062228-4.pom │ ├── DirectMemory-Cache-0.5.5-20110922.062228-4.pom.md5 │ ├── DirectMemory-Cache-0.5.5-20110922.062228-4.pom.sha1 │ ├── maven-metadata.xml │ ├── maven-metadata.xml.md5 │ └── maven-metadata.xml.sha1 │ ├── maven-metadata.xml │ ├── maven-metadata.xml.md5 │ └── maven-metadata.xml.sha1 └── README /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /DirectMemoryExperiments/bin 3 | /Demo/DirectMemory-WebDemo/target 4 | /Demo/DirectMemory-WebDemo/logs 5 | /DirectMemoryCache/target 6 | /DirectMemory-Tests/target 7 | /DirectMemory-Cache/target/test-classes 8 | /DirectMemory-Cache/target/classes 9 | /Demo/DirectMemory-StandaloneDemo/logs/directmemory.log -------------------------------------------------------------------------------- /DirectMemory-Cache/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /DirectMemory-Cache/.gitignore: -------------------------------------------------------------------------------- 1 | /dm-test.jar 2 | /logs 3 | /target 4 | -------------------------------------------------------------------------------- /DirectMemory-Cache/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | DirectMemory-Cache 4 | DirectMemory Cache is a multi layered cache implementation featuring off-heap memory management (a-la BigMemory) to enable efficient handling of a large number of java objects without affecting jvm garbage collection performance. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. 5 | 6 | 7 | 8 | 9 | org.eclipse.ajdt.core.ajbuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.ajdt.ui.ajnature 16 | org.eclipse.jdt.core.javanature 17 | 18 | 19 | -------------------------------------------------------------------------------- /DirectMemory-Cache/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Sun Sep 04 00:32:46 CEST 2011 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | eclipse.preferences.version=1 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | org.eclipse.jdt.core.compiler.compliance=1.6 6 | -------------------------------------------------------------------------------- /DirectMemory-Cache/.settings/org.eclipse.ltk.core.refactoring.prefs: -------------------------------------------------------------------------------- 1 | #Sat Jan 01 23:57:03 CET 2011 2 | eclipse.preferences.version=1 3 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false 4 | -------------------------------------------------------------------------------- /DirectMemory-Cache/.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | #Thu Dec 30 12:50:14 CET 2010 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | fullBuildGoals=process-test-resources 5 | resolveWorkspaceProjects=true 6 | resourceFilterGoals=process-resources resources\:testResources 7 | skipCompilerPlugin=true 8 | version=1 9 | -------------------------------------------------------------------------------- /DirectMemory-Cache/bench.bat: -------------------------------------------------------------------------------- 1 | mvn test -Dtest=SerializerTest -Djub.customkey=%1 -Djub.consumers=CONSOLE,XML,H2 -Djub.db.file=data/benchmarks/database -Djub.xml.file=logs/benchmarks.xml -Djub.charts.dir=data/benchmarks/graphs 2 | -------------------------------------------------------------------------------- /DirectMemory-Cache/bench.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mvn test -Djub.customkey=$1 -Dtest=MicroBenchmarks -Djub.consumers=CONSOLE,XML,H2 -Djub.db.file=data/benchmarks/database -Djub.xml.file=logs/benchmarks.xml -Djub.charts.dir=data/benchmarks/graphs 3 | -------------------------------------------------------------------------------- /DirectMemory-Cache/config/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %method - %msg%n 7 | 8 | 9 | 10 | 11 | logs/directmemory.log 12 | 13 | %d{HH:mm:ss.SSS} [%thread] %-5level %method - %msg%n 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/database.h2.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/data/benchmarks/database.h2.db -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest-run1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest 6 | 7 | 8 | 12 | 13 | 57 | 58 | 121 | 122 | 123 | 124 |
125 |

Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest

126 | 127 | 128 |
129 |
130 | 131 |
132 | Click on table headers to change the sorting order and redraw the chart. 133 |
134 | 135 |
136 | 137 | 143 |
144 |
145 | 146 | 147 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest-run1.json: -------------------------------------------------------------------------------- 1 | { 2 | "cols": [ 3 | {"label": "method", "type": "string"}, 4 | {"label": "Average time [s]", "type": "number"}, 5 | {"label": "StdDev", "type": "number"}, 6 | {"label": "GC average [s]", "type": "number"}, 7 | {"label": "GC time [s]", "type": "number"}, 8 | {"label": "StdDev", "type": "number"}, 9 | {"label": "GC calls", "type": "number"}, 10 | {"label": "benchmark rounds", "type": "number"}, 11 | {"label": "warmup rounds", "type": "number"}, 12 | {"label": "Total benchmark time", "type": "number"}, 13 | {"label": "Total warmup time", "type": "number"} 14 | ], 15 | "rows": [ 16 | {"c": [{"v": "ProtostuffTest"}, {"v": 2.49}, {"v": 0.0}, {"v": 0.0}, {"v": 0.02}, {"v": 0.0}, {"v": 6}, {"v": 1}, {"v": 0}, {"v": 2.37}, {"v": 0.12}]}, 17 | {"c": [{"v": "ProtostuffV2Test"}, {"v": 3.24}, {"v": 0.0}, {"v": 0.0}, {"v": 0.01}, {"v": 0.0}, {"v": 7}, {"v": 1}, {"v": 0}, {"v": 3.24}, {"v": 0.0}]}, 18 | {"c": [{"v": "StandardTest"}, {"v": 9.23}, {"v": 0.0}, {"v": 0.0}, {"v": 0.03}, {"v": 0.0}, {"v": 18}, {"v": 1}, {"v": 0}, {"v": 9.23}, {"v": 0.0}]} 19 | ]} 20 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest-run2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest 6 | 7 | 8 | 12 | 13 | 57 | 58 | 121 | 122 | 123 | 124 |
125 |

Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest

126 | 127 | 128 |
129 |
130 | 131 |
132 | Click on table headers to change the sorting order and redraw the chart. 133 |
134 | 135 |
136 | 137 | 143 |
144 |
145 | 146 | 147 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest-run2.json: -------------------------------------------------------------------------------- 1 | { 2 | "cols": [ 3 | {"label": "method", "type": "string"}, 4 | {"label": "Average time [s]", "type": "number"}, 5 | {"label": "StdDev", "type": "number"}, 6 | {"label": "GC average [s]", "type": "number"}, 7 | {"label": "GC time [s]", "type": "number"}, 8 | {"label": "StdDev", "type": "number"}, 9 | {"label": "GC calls", "type": "number"}, 10 | {"label": "benchmark rounds", "type": "number"}, 11 | {"label": "warmup rounds", "type": "number"}, 12 | {"label": "Total benchmark time", "type": "number"}, 13 | {"label": "Total warmup time", "type": "number"} 14 | ], 15 | "rows": [ 16 | {"c": [{"v": "ProtostuffTest"}, {"v": 1.73}, {"v": 0.07}, {"v": 0.0}, {"v": 0.04}, {"v": 0.0}, {"v": 26}, {"v": 5}, {"v": 1}, {"v": 8.66}, {"v": 2.36}]}, 17 | {"c": [{"v": "ProtostuffV2Test"}, {"v": 3.11}, {"v": 0.1}, {"v": 0.0}, {"v": 0.03}, {"v": 0.0}, {"v": 32}, {"v": 5}, {"v": 1}, {"v": 15.53}, {"v": 3.09}]}, 18 | {"c": [{"v": "StandardTest"}, {"v": 8.37}, {"v": 0.06}, {"v": 0.0}, {"v": 0.04}, {"v": 0.0}, {"v": 91}, {"v": 5}, {"v": 1}, {"v": 41.86}, {"v": 9.44}]} 19 | ]} 20 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest-run3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest 6 | 7 | 8 | 12 | 13 | 57 | 58 | 121 | 122 | 123 | 124 |
125 |

Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest

126 | 127 | 128 |
129 |
130 | 131 |
132 | Click on table headers to change the sorting order and redraw the chart. 133 |
134 | 135 |
136 | 137 | 143 |
144 |
145 | 146 | 147 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest-run3.json: -------------------------------------------------------------------------------- 1 | { 2 | "cols": [ 3 | {"label": "method", "type": "string"}, 4 | {"label": "Average time [s]", "type": "number"}, 5 | {"label": "StdDev", "type": "number"}, 6 | {"label": "GC average [s]", "type": "number"}, 7 | {"label": "GC time [s]", "type": "number"}, 8 | {"label": "StdDev", "type": "number"}, 9 | {"label": "GC calls", "type": "number"}, 10 | {"label": "benchmark rounds", "type": "number"}, 11 | {"label": "warmup rounds", "type": "number"}, 12 | {"label": "Total benchmark time", "type": "number"}, 13 | {"label": "Total warmup time", "type": "number"} 14 | ], 15 | "rows": [ 16 | {"c": [{"v": "ProtostuffTest"}, {"v": 1.66}, {"v": 0.01}, {"v": 0.0}, {"v": 0.01}, {"v": 0.0}, {"v": 26}, {"v": 5}, {"v": 1}, {"v": 8.31}, {"v": 2.3}]}, 17 | {"c": [{"v": "ProtostuffV2Test"}, {"v": 3.49}, {"v": 0.0}, {"v": 0.0}, {"v": 0.02}, {"v": 0.0}, {"v": 41}, {"v": 5}, {"v": 1}, {"v": 17.45}, {"v": 3.56}]}, 18 | {"c": [{"v": "StandardTest"}, {"v": 8.13}, {"v": 0.08}, {"v": 0.0}, {"v": 0.08}, {"v": 0.0}, {"v": 90}, {"v": 5}, {"v": 1}, {"v": 40.64}, {"v": 9.07}]} 19 | ]} 20 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest-run4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest 6 | 7 | 8 | 12 | 13 | 57 | 58 | 121 | 122 | 123 | 124 |
125 |

Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest

126 | 127 | 128 |
129 |
130 | 131 |
132 | Click on table headers to change the sorting order and redraw the chart. 133 |
134 | 135 |
136 | 137 | 143 |
144 |
145 | 146 | 147 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest-run4.json: -------------------------------------------------------------------------------- 1 | { 2 | "cols": [ 3 | {"label": "method", "type": "string"}, 4 | {"label": "Average time [s]", "type": "number"}, 5 | {"label": "StdDev", "type": "number"}, 6 | {"label": "GC average [s]", "type": "number"}, 7 | {"label": "GC time [s]", "type": "number"}, 8 | {"label": "StdDev", "type": "number"}, 9 | {"label": "GC calls", "type": "number"}, 10 | {"label": "benchmark rounds", "type": "number"}, 11 | {"label": "warmup rounds", "type": "number"}, 12 | {"label": "Total benchmark time", "type": "number"}, 13 | {"label": "Total warmup time", "type": "number"} 14 | ], 15 | "rows": [ 16 | {"c": [{"v": "ProtostuffTest"}, {"v": 1.67}, {"v": 0.02}, {"v": 0.0}, {"v": 0.01}, {"v": 0.0}, {"v": 26}, {"v": 5}, {"v": 1}, {"v": 8.36}, {"v": 2.3}]}, 17 | {"c": [{"v": "ProtostuffV2Test"}, {"v": 3.58}, {"v": 0.02}, {"v": 0.0}, {"v": 0.02}, {"v": 0.0}, {"v": 43}, {"v": 5}, {"v": 1}, {"v": 17.91}, {"v": 3.64}]}, 18 | {"c": [{"v": "StandardTest"}, {"v": 8.02}, {"v": 0.02}, {"v": 0.0}, {"v": 0.06}, {"v": 0.0}, {"v": 91}, {"v": 5}, {"v": 1}, {"v": 40.08}, {"v": 9.17}]} 19 | ]} 20 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest-run5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest 6 | 7 | 8 | 12 | 13 | 57 | 58 | 121 | 122 | 123 | 124 |
125 |

Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest

126 | 127 | 128 |
129 |
130 | 131 |
132 | Click on table headers to change the sorting order and redraw the chart. 133 |
134 | 135 |
136 | 137 | 143 |
144 |
145 | 146 | 147 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest-run5.json: -------------------------------------------------------------------------------- 1 | { 2 | "cols": [ 3 | {"label": "method", "type": "string"}, 4 | {"label": "Average time [s]", "type": "number"}, 5 | {"label": "StdDev", "type": "number"}, 6 | {"label": "GC average [s]", "type": "number"}, 7 | {"label": "GC time [s]", "type": "number"}, 8 | {"label": "StdDev", "type": "number"}, 9 | {"label": "GC calls", "type": "number"}, 10 | {"label": "benchmark rounds", "type": "number"}, 11 | {"label": "warmup rounds", "type": "number"}, 12 | {"label": "Total benchmark time", "type": "number"}, 13 | {"label": "Total warmup time", "type": "number"} 14 | ], 15 | "rows": [ 16 | {"c": [{"v": "ProtostuffTest"}, {"v": 1.6}, {"v": 0.07}, {"v": 0.0}, {"v": 0.03}, {"v": 0.0}, {"v": 26}, {"v": 5}, {"v": 1}, {"v": 7.98}, {"v": 2.3}]}, 17 | {"c": [{"v": "ProtostuffV2Test"}, {"v": 2.44}, {"v": 0.01}, {"v": 0.0}, {"v": 0.02}, {"v": 0.0}, {"v": 34}, {"v": 5}, {"v": 1}, {"v": 12.22}, {"v": 2.51}]}, 18 | {"c": [{"v": "StandardTest"}, {"v": 8.02}, {"v": 0.12}, {"v": 0.0}, {"v": 0.05}, {"v": 0.0}, {"v": 91}, {"v": 5}, {"v": 1}, {"v": 40.1}, {"v": 9.08}]} 19 | ]} 20 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest 6 | 7 | 8 | 12 | 13 | 50 | 51 | 102 | 103 | 104 | 105 |
106 |

Benchmark results for methods in class org.directmemory.serialization.test.SerializerTest

107 | 108 |
109 |
110 | 111 |
112 | 113 | 114 |
115 |
116 | 117 | 118 | -------------------------------------------------------------------------------- /DirectMemory-Cache/data/benchmarks/graphs/org.directmemory.serialization.test.SerializerTest.json: -------------------------------------------------------------------------------- 1 | { 2 | "cols": [ 3 | {"label": "Run", "type": "string"}, 4 | {"label": "Custom key", "type": "string"}, 5 | {"label": "Timestamp", "type": "string"}, 6 | {"label": "ProtostuffTest", "type": "string"} , 7 | {"label": "ProtostuffV2Test", "type": "string"} , 8 | {"label": "StandardTest", "type": "string"} ], 9 | "rows": [ 10 | {"c": [{"v": "1"}, {"v": "one run only"}, {"v": "2011-09-17 14:25:23.709"}, {"v": 2.487}, {"v": 3.242}, {"v": 9.225}, ]}, 11 | {"c": [{"v": "2"}, {"v": "5 runs +1 warmup"}, {"v": "2011-09-17 14:29:23.094"}, {"v": 1.733}, {"v": 3.106}, {"v": 8.372}, ]}, 12 | {"c": [{"v": "3"}, {"v": "5 runs +1 warmup"}, {"v": "2011-09-17 14:32:52.396"}, {"v": 1.662}, {"v": 3.489}, {"v": 8.128}, ]}, 13 | {"c": [{"v": "4"}, {"v": "5 runs +1 warmup"}, {"v": "2011-09-17 14:37:21.226"}, {"v": 1.672}, {"v": 3.582}, {"v": 8.016}, ]}, 14 | {"c": [{"v": "5"}, {"v": "5+1 (larger buffers in v1 and smaller in v2)"}, {"v": "2011-09-17 14:41:59.63"}, {"v": 1.597}, {"v": 2.443}, {"v": 8.02}, ]} 15 | ]} 16 | -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/javasimon/eval-0.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/javasimon/eval-0.5.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/javasimon/javasimon-core-2.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/javasimon/javasimon-core-2.4.0.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/javasimon/sjsxp.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/javasimon/sjsxp.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/javasimon/stax-api-1.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/javasimon/stax-api-1.0.1.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/orientdb/orient-commons-0.9.24.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/orientdb/orient-commons-0.9.24.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/orientdb/orientdb-core-0.9.24.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/orientdb/orientdb-core-0.9.24.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-api-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-api-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-benchmark-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-benchmark-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-codegen-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-codegen-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-compiler-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-compiler-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-core-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-core-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-json-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-json-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-maven-plugin-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-maven-plugin-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-model-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-model-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-model-json-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-model-json-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-parser-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-parser-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-runtime-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-runtime-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-xml-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-xml-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/protostuff/protostuff-yaml-1.0.0.M6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/protostuff/protostuff-yaml-1.0.0.M6.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/slf4j/logback-classic-0.9.26.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/slf4j/logback-classic-0.9.26.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/slf4j/logback-core-0.9.26.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/slf4j/logback-core-0.9.26.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/lib/slf4j/slf4j-api-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/DirectMemory-Cache/lib/slf4j/slf4j-api-1.6.1.jar -------------------------------------------------------------------------------- /DirectMemory-Cache/snapshot.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | @echo creating snapshot 3 | mvn -DaltDeploymentRepository=snapshot-repo::default::file:..\Misc\mvn-repo\snapshots clean deploy 4 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/aspect/org/directmemory/monitoring/Performance.aj: -------------------------------------------------------------------------------- 1 | package org.directmemory.monitoring; 2 | 3 | import org.directmemory.cache.Cache; 4 | import org.directmemory.measures.Monitor; 5 | import org.directmemory.memory.Pointer; 6 | import org.directmemory.misc.Format; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | public aspect Performance { 11 | public static final String cache_prefix = "cache"; 12 | 13 | public static final String cache_putByteArray = cache_prefix + ".putByteArray"; 14 | public static final String cache_retrieveByteArray = cache_prefix + ".retrieveByteArray"; 15 | public static final String cache_getPointer = cache_prefix + ".getPointer"; 16 | 17 | public static final String cache_putObject = cache_prefix + ".put"; 18 | public static final String cache_retrieveObject = cache_prefix + ".get"; 19 | 20 | public static final String cache_collectLFU = cache_prefix + ".collectLFU"; 21 | public static final String cache_collectExpired = cache_prefix + ".collectExpired"; 22 | 23 | public static final String cache_serialize = cache_prefix + ".serializer.serialize"; 24 | public static final String cache_deserialize = cache_prefix + ".serializer.deserialize"; 25 | 26 | private static Logger logger = LoggerFactory.getLogger(Cache.class); 27 | 28 | pointcut putByteArrayPointcut(String key, byte[] payload) : 29 | execution(Pointer org.directmemory.cache.Cache.putByteArray(String, byte[])) && 30 | args(key, payload); 31 | 32 | pointcut putObjectPointcut(String key, Object object, int expiresIn) : 33 | execution(Pointer org.directmemory.cache.Cache.put(String, Object, int)) && 34 | args(key, object, expiresIn); 35 | 36 | pointcut retrieveByteArrayPointcut(String key) : 37 | execution(byte[] org.directmemory.cache.Cache.retrieveByteArray(String)) && 38 | args(key); 39 | 40 | pointcut retrieveObjectPointcut(String key) : 41 | execution(Object org.directmemory.cache.Cache.retrieve(String)) && 42 | args(key); 43 | 44 | pointcut getPointcut(String key) : 45 | execution(Pointer org.directmemory.cache.Cache.getPointer(String)) && 46 | args(key); 47 | 48 | pointcut collectLFUPointcut() : 49 | execution(void org.directmemory.cache.Cache.collectLFU()); 50 | 51 | pointcut collectExpiredPointcut() : 52 | execution(void org.directmemory.cache.Cache.collectExpired()); 53 | 54 | pointcut serializePointcut(Object obj, @SuppressWarnings("rawtypes") Class clazz) : 55 | execution(byte[] org.directmemory.serialization.ProtoStuffSerializerV1.serialize(Object, Class)) && 56 | args(obj, clazz); 57 | 58 | pointcut deserializePointcut(byte[] source, @SuppressWarnings("rawtypes") Class clazz) : 59 | execution(Object org.directmemory.serialization.ProtoStuffSerializerV1.deserialize(byte[], Class)) && 60 | args(source, clazz); 61 | 62 | Pointer around(String key, byte[] payload): putByteArrayPointcut(key, payload) { 63 | Monitor mon = Monitor.get(cache_putByteArray); 64 | final long startedAt = mon.start(); 65 | Pointer entry = proceed(key, payload); 66 | if (logger.isDebugEnabled()) logger.debug(Format.it("put: [%s] %d bytes", key, payload.length )); 67 | mon.stop(startedAt); 68 | return entry; 69 | } 70 | 71 | Pointer around(String key, Object object, int expiresIn): putObjectPointcut(key, object, expiresIn) { 72 | Monitor mon = Monitor.get(cache_putObject); 73 | final long startedAt = mon.start(); 74 | Pointer entry = proceed(key, object, expiresIn); 75 | if (logger.isDebugEnabled()) logger.debug(Format.it("put object: [%s]", key)); 76 | mon.stop(startedAt); 77 | return entry; 78 | } 79 | 80 | byte[] around(String key): retrieveByteArrayPointcut(key) { 81 | Monitor mon = Monitor.get(cache_retrieveByteArray); 82 | final long startedAt = mon.start(); 83 | byte[] payload = proceed(key); 84 | if (logger.isDebugEnabled()) logger.debug(Format.it("retrieve: [%s]", key )); 85 | mon.stop(startedAt); 86 | return payload; 87 | } 88 | 89 | Object around(String key): retrieveObjectPointcut(key) { 90 | Monitor mon = Monitor.get(cache_retrieveObject); 91 | final long startedAt = mon.start(); 92 | Object payload = proceed(key); 93 | if (logger.isDebugEnabled()) logger.debug(Format.it("retrieve object: [%s]", key )); 94 | mon.stop(startedAt); 95 | return payload; 96 | } 97 | 98 | Pointer around(String key): getPointcut(key) { 99 | Monitor mon = Monitor.get(cache_getPointer); 100 | final long startedAt = mon.start(); 101 | Pointer pointer = proceed(key); 102 | if (logger.isDebugEnabled()) logger.debug(Format.it("get: [%s]", key)); 103 | mon.stop(startedAt); 104 | return pointer; 105 | } 106 | 107 | void around(): collectLFUPointcut() { 108 | Monitor mon = Monitor.get(cache_collectLFU); 109 | final long startedAt = mon.start(); 110 | proceed(); 111 | if (logger.isDebugEnabled()) logger.debug(Format.it("collect LFU")); 112 | mon.stop(startedAt); 113 | } 114 | 115 | void around(): collectExpiredPointcut() { 116 | Monitor mon = Monitor.get(cache_collectExpired); 117 | final long startedAt = mon.start(); 118 | proceed(); 119 | if (logger.isDebugEnabled()) logger.debug(Format.it("collect expired")); 120 | mon.stop(startedAt); 121 | } 122 | 123 | byte[] around(Object obj, @SuppressWarnings("rawtypes") Class clazz): serializePointcut(obj, clazz) { 124 | Monitor mon = Monitor.get(cache_serialize); 125 | final long startedAt = mon.start(); 126 | byte[] payload = proceed(obj, clazz); 127 | if (logger.isDebugEnabled()) logger.debug(Format.it("serialize: [%s]", clazz.getSimpleName() )); 128 | mon.stop(startedAt); 129 | return payload; 130 | } 131 | 132 | Object around(byte[] source, @SuppressWarnings("rawtypes") Class clazz): deserializePointcut(source, clazz) { 133 | Monitor mon = Monitor.get(cache_deserialize); 134 | final long startedAt = mon.start(); 135 | Object obj = proceed(source, clazz); 136 | if (logger.isDebugEnabled()) logger.debug(Format.it("deserialize: [%s]", clazz.getSimpleName() )); 137 | mon.stop(startedAt); 138 | return obj; 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/cache/Cache.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.cache; 2 | 3 | import java.io.EOFException; 4 | import java.io.IOException; 5 | import java.util.Timer; 6 | import java.util.TimerTask; 7 | import java.util.concurrent.ConcurrentMap; 8 | 9 | import org.directmemory.measures.Every; 10 | import org.directmemory.measures.Ram; 11 | import org.directmemory.memory.MemoryManager; 12 | import org.directmemory.memory.OffHeapMemoryBuffer; 13 | import org.directmemory.memory.Pointer; 14 | import org.directmemory.misc.Format; 15 | import org.directmemory.serialization.ProtoStuffSerializerV1; 16 | import org.directmemory.serialization.Serializer; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | 20 | import com.google.common.collect.MapMaker; 21 | 22 | public class Cache { 23 | 24 | private static Logger logger = LoggerFactory.getLogger(MemoryManager.class); 25 | private static ConcurrentMap map; 26 | 27 | public static int DEFAULT_CONCURRENCY_LEVEL = 4; 28 | public static int DEFAULT_INITIAL_CAPACITY = 100000; 29 | 30 | public static Serializer serializer = new ProtoStuffSerializerV1(); 31 | 32 | private Cache() { 33 | // not instantiable 34 | } 35 | 36 | 37 | private final static Timer timer = new Timer(); 38 | 39 | public static void scheduleDisposalEvery(long l) { 40 | timer.schedule(new TimerTask() { 41 | public void run() { 42 | logger.info("begin scheduled disposal"); 43 | collectExpired(); 44 | collectLFU(); 45 | logger.info("scheduled disposal complete"); 46 | } 47 | }, l); 48 | logger.info("disposal scheduled every " + l + " milliseconds"); 49 | } 50 | 51 | public static void init(int numberOfBuffers, int size, int initialCapacity, int concurrencyLevel) { 52 | map = new MapMaker() 53 | .concurrencyLevel(concurrencyLevel) 54 | .initialCapacity(initialCapacity) 55 | .makeMap(); 56 | 57 | logger.info("*** initializing *******************************\r\n" + Format.logo()); 58 | logger.info("************************************************"); 59 | MemoryManager.init(numberOfBuffers, size); 60 | logger.info("initialized"); 61 | logger.info(Format.it("number of buffer(s): \t%1d with %2s each", numberOfBuffers, Ram.inMb(size))); 62 | logger.info(Format.it("initial capacity: \t%1d", initialCapacity)); 63 | logger.info(Format.it("concurrency level: \t%1d", concurrencyLevel)); 64 | scheduleDisposalEvery(Every.seconds(10)); 65 | } 66 | 67 | public static void init(int numberOfBuffers, int size) { 68 | init(numberOfBuffers, size, DEFAULT_INITIAL_CAPACITY, DEFAULT_CONCURRENCY_LEVEL); 69 | } 70 | 71 | public static Pointer putByteArray(String key, byte[] payload, int expiresIn) { 72 | Pointer ptr = MemoryManager.store(payload, expiresIn); 73 | map.put(key, ptr); 74 | return ptr; 75 | } 76 | 77 | public static Pointer putByteArray(String key, byte[] payload) { 78 | return putByteArray(key, payload, 0); 79 | } 80 | 81 | public static Pointer put(String key, Object object) { 82 | return put(key, object, 0); 83 | } 84 | 85 | public static Pointer put(String key, Object object, int expiresIn) { 86 | try { 87 | byte[] payload = serializer.serialize(object, object.getClass()); 88 | Pointer ptr = putByteArray(key, payload); 89 | ptr.clazz = object.getClass(); 90 | return ptr; 91 | } catch (IOException e) { 92 | logger.error(e.getMessage()); 93 | return null; 94 | } 95 | } 96 | 97 | public static Pointer updateByteArray(String key, byte[] payload) { 98 | Pointer p = map.get(key); 99 | p = MemoryManager.update(p, payload); 100 | return p; 101 | } 102 | 103 | public static Pointer update(String key, Object object) { 104 | Pointer p = map.get(key); 105 | try { 106 | p = MemoryManager.update(p, serializer.serialize(object, object.getClass())); 107 | p.clazz = object.getClass(); 108 | return p; 109 | } catch (IOException e) { 110 | logger.error(e.getMessage()); 111 | return null; 112 | } 113 | } 114 | 115 | public static byte[] retrieveByteArray(String key) { 116 | Pointer ptr = getPointer(key); 117 | if (ptr == null) return null; 118 | if (ptr.expired() || ptr.free) { 119 | map.remove(key); 120 | if (!ptr.free) { 121 | MemoryManager.free(ptr); 122 | } 123 | return null; 124 | } else { 125 | return MemoryManager.retrieve(ptr); 126 | } 127 | } 128 | 129 | public static Object retrieve(String key) { 130 | Pointer ptr = getPointer(key); 131 | if (ptr == null) return null; 132 | if (ptr.expired() || ptr.free) { 133 | map.remove(key); 134 | if (!ptr.free) { 135 | MemoryManager.free(ptr); 136 | } 137 | return null; 138 | } else { 139 | try { 140 | return serializer.deserialize(MemoryManager.retrieve(ptr),ptr.clazz); 141 | } catch (EOFException e) { 142 | logger.error(e.getMessage()); 143 | } catch (IOException e) { 144 | logger.error(e.getMessage()); 145 | } catch (ClassNotFoundException e) { 146 | logger.error(e.getMessage()); 147 | } catch (InstantiationException e) { 148 | logger.error(e.getMessage()); 149 | } catch (IllegalAccessException e) { 150 | logger.error(e.getMessage()); 151 | } 152 | } 153 | return null; 154 | } 155 | 156 | public static Pointer getPointer(String key) { 157 | return map.get(key); 158 | } 159 | 160 | public static void free(String key) { 161 | Pointer p = map.remove(key); 162 | if (p != null) { 163 | MemoryManager.free(p); 164 | } 165 | } 166 | 167 | public static void free(Pointer pointer) { 168 | MemoryManager.free(pointer); 169 | } 170 | 171 | public static void collectExpired() { 172 | MemoryManager.collectExpired(); 173 | // still have to look for orphan (storing references to freed pointers) map entries 174 | } 175 | 176 | public static void collectLFU() { 177 | MemoryManager.collectLFU(); 178 | // can possibly clear one whole buffer if it's too fragmented - investigate 179 | } 180 | 181 | public static void collectAll() { 182 | Thread thread = new Thread(){ 183 | public void run(){ 184 | logger.info("begin disposal"); 185 | collectExpired(); 186 | collectLFU(); 187 | logger.info("disposal complete"); 188 | } 189 | }; 190 | thread.start(); 191 | } 192 | 193 | 194 | public static void clear() { 195 | map.clear(); 196 | MemoryManager.clear(); 197 | logger.info("Cache cleared"); 198 | } 199 | 200 | public static long entries() { 201 | return map.size(); 202 | } 203 | 204 | private static void dump(OffHeapMemoryBuffer mem) { 205 | logger.info(Format.it("off-heap - buffer: \t%1d", mem.bufferNumber)); 206 | logger.info(Format.it("off-heap - allocated: \t%1s", Ram.inMb(mem.capacity()))); 207 | logger.info(Format.it("off-heap - used: \t%1s", Ram.inMb(mem.used()))); 208 | logger.info(Format.it("heap - max: \t%1s", Ram.inMb(Runtime.getRuntime().maxMemory()))); 209 | logger.info(Format.it("heap - allocated: \t%1s", Ram.inMb(Runtime.getRuntime().totalMemory()))); 210 | logger.info(Format.it("heap - free : \t%1s", Ram.inMb(Runtime.getRuntime().freeMemory()))); 211 | logger.info("************************************************"); 212 | } 213 | 214 | public static void dump() { 215 | if (!logger.isInfoEnabled()) 216 | return; 217 | 218 | logger.info("*** DirectMemory statistics ********************"); 219 | 220 | for (OffHeapMemoryBuffer mem : MemoryManager.buffers) { 221 | dump(mem); 222 | } 223 | } 224 | 225 | } 226 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/measures/Every.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.measures; 2 | 3 | public class Every extends In { 4 | 5 | public Every(double measure) { 6 | super(measure); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/measures/Expires.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.measures; 2 | 3 | public class Expires extends In { 4 | 5 | public Expires(double measure) { 6 | super(measure); 7 | } 8 | 9 | public static In in(double measure) { 10 | return new In(measure); 11 | } 12 | public static long never() { 13 | return -1L; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/measures/For.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.measures; 2 | 3 | public class For extends In { 4 | 5 | public For(double measure) { 6 | super(measure); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/measures/Heap.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.measures; 2 | 3 | public class Heap extends Sizing { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/measures/In.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.measures; 2 | 3 | public class In { 4 | private double measure; 5 | 6 | public In(double measure) { 7 | this.measure = measure; 8 | } 9 | 10 | public long seconds() { 11 | return seconds(measure); 12 | } 13 | 14 | public long minutes() { 15 | return minutes(measure); 16 | } 17 | 18 | public long hours() { 19 | return hours(measure); 20 | } 21 | 22 | public long days() { 23 | return days(measure); 24 | } 25 | 26 | public static long seconds(double seconds) { 27 | return (long)seconds * 1000; 28 | } 29 | public static long minutes(double minutes) { 30 | return (long)seconds(minutes * 60); 31 | } 32 | public static long hours(double hours) { 33 | return (long)minutes(hours * 60); 34 | } 35 | public static long days(double days) { 36 | return (long)hours(days * 24); 37 | } 38 | 39 | public static In just(double measure) { 40 | return new In(measure); 41 | } 42 | public static In exactly(double measure) { 43 | return new In(measure); 44 | } 45 | public static In only(double measure) { 46 | return new In(measure); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/measures/Memory.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.measures; 2 | 3 | public class Memory extends Sizing { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/measures/Monitor.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.measures; 2 | 3 | import java.text.DecimalFormat; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | import java.util.concurrent.atomic.AtomicLong; 7 | 8 | import org.directmemory.misc.Format; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | public class Monitor { 13 | private AtomicLong hits = new AtomicLong(0); 14 | private long totalTime = 0; 15 | private long min = -1; 16 | private long max = -1; 17 | public String name; 18 | 19 | private static Logger logger = LoggerFactory.getLogger(Monitor.class); 20 | public static Map monitors = new HashMap(); 21 | 22 | public static Monitor get(String key) { 23 | Monitor mon = monitors.get(key); 24 | if (mon == null) { 25 | mon = new Monitor(key); 26 | monitors.put(key, mon); 27 | } 28 | return mon; 29 | } 30 | 31 | public Monitor(String name) { 32 | this.name = name; 33 | } 34 | 35 | public long start() { 36 | return System.nanoTime(); 37 | } 38 | public long stop(long begunAt) { 39 | hits.incrementAndGet(); 40 | final long lastAccessed = System.nanoTime(); 41 | final long elapsed = lastAccessed - begunAt; 42 | totalTime+=elapsed; 43 | if (elapsed > max && hits.get() > 0) max = elapsed; 44 | if (elapsed < min && hits.get() > 0) min = elapsed; 45 | return elapsed; 46 | } 47 | public long hits() { 48 | return hits.get(); 49 | } 50 | public long totalTime() { 51 | return totalTime; 52 | } 53 | public long average() { 54 | return totalTime/hits.get(); 55 | } 56 | public String toString() { 57 | return Format.it("%1$s hits: %2$d, avg: %3$s ms, tot: %4$s seconds", 58 | name, 59 | hits.get(), 60 | new DecimalFormat("####.###").format((double)average()/1000000), 61 | new DecimalFormat("####.###").format((double)totalTime/1000000000) 62 | ); 63 | } 64 | 65 | public static void dump(String prefix) { 66 | for (Monitor monitor : Monitor.monitors.values()) { 67 | if (monitor.name.startsWith(prefix)) 68 | logger.info(monitor.toString()); 69 | } 70 | } 71 | 72 | public static void dump() { 73 | dump(""); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/measures/Ram.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.measures; 2 | 3 | public class Ram extends Sizing { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/measures/Sizing.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.measures; 2 | 3 | import java.util.Formatter; 4 | 5 | public class Sizing { 6 | public static int Gb(double giga) { 7 | return (int)giga * 1024 * 1024 * 1024; 8 | } 9 | 10 | public static int Mb(double mega) { 11 | return (int)mega * 1024 * 1024; 12 | } 13 | 14 | public static int Kb(double kilo) { 15 | return (int)kilo * 1024; 16 | } 17 | public static int unlimited() { 18 | return -1; 19 | } 20 | public static String inKb(long bytes) { 21 | return new Formatter().format("%(,.1fKb", (double)bytes/1024).toString(); 22 | } 23 | public static String inMb(long bytes) { 24 | return new Formatter().format("%(,.1fMb", (double)bytes/1024/1024).toString(); 25 | } 26 | public static String inGb(long bytes) { 27 | return new Formatter().format("%(,.1fKb", (double)bytes/1024/1024/1024).toString(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/measures/Space.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.measures; 2 | 3 | public class Space extends Sizing { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/memory/MemoryManager.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.memory; 2 | 3 | import java.util.List; 4 | import java.util.Vector; 5 | 6 | import org.directmemory.measures.Ram; 7 | import org.directmemory.misc.Format; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | public class MemoryManager { 12 | private static Logger logger = LoggerFactory.getLogger(MemoryManager.class); 13 | public static List buffers = new Vector(); 14 | public static OffHeapMemoryBuffer activeBuffer = null; 15 | 16 | private MemoryManager() { 17 | //static class 18 | } 19 | 20 | public static void init(int numberOfBuffers, int size) { 21 | for (int i = 0; i < numberOfBuffers; i++) { 22 | buffers.add(OffHeapMemoryBuffer.createNew(size, i)); 23 | } 24 | activeBuffer = buffers.get(0); 25 | logger.info(Format.it("MemoryManager initialized - %d buffers, %s each", numberOfBuffers, Ram.inMb(size))); 26 | } 27 | 28 | public static Pointer store(byte[] payload, int expiresIn) { 29 | Pointer p = activeBuffer.store(payload, expiresIn); 30 | if (p == null) { 31 | if (activeBuffer.bufferNumber+1 == buffers.size()) { 32 | return null; 33 | } else { 34 | // try next buffer 35 | activeBuffer = buffers.get(activeBuffer.bufferNumber+1); 36 | p = activeBuffer.store(payload, expiresIn); 37 | } 38 | } 39 | return p; 40 | } 41 | 42 | public static Pointer store(byte[] payload) { 43 | return store(payload, 0); 44 | } 45 | 46 | public static Pointer update(Pointer pointer, byte[] payload) { 47 | Pointer p = activeBuffer.update(pointer, payload); 48 | if (p == null) { 49 | if (activeBuffer.bufferNumber == buffers.size()) { 50 | return null; 51 | } else { 52 | // try next buffer 53 | activeBuffer = buffers.get(activeBuffer.bufferNumber+1); 54 | p = activeBuffer.store(payload); 55 | } 56 | } 57 | return p; 58 | } 59 | 60 | public static byte[] retrieve(Pointer pointer) { 61 | return buffers.get(pointer.bufferNumber).retrieve(pointer); 62 | } 63 | 64 | public static void free(Pointer pointer) { 65 | buffers.get(pointer.bufferNumber).free(pointer); 66 | } 67 | 68 | public static void clear() { 69 | for (OffHeapMemoryBuffer buffer : buffers) { 70 | buffer.clear(); 71 | } 72 | activeBuffer = buffers.get(0); 73 | } 74 | 75 | public static long capacity() { 76 | long totalCapacity = 0; 77 | for (OffHeapMemoryBuffer buffer : buffers) { 78 | totalCapacity += buffer.capacity(); 79 | } 80 | return totalCapacity; 81 | } 82 | 83 | public static long collectExpired() { 84 | long disposed = 0; 85 | for (OffHeapMemoryBuffer buffer : buffers) { 86 | disposed += buffer.collectExpired(); 87 | } 88 | return disposed; 89 | } 90 | 91 | public static void collectLFU() { 92 | for (OffHeapMemoryBuffer buf : MemoryManager.buffers) { 93 | buf.collectLFU(-1); 94 | } 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/memory/OffHeapMemoryBuffer.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.memory; 2 | 3 | import java.nio.BufferOverflowException; 4 | import java.nio.ByteBuffer; 5 | import java.util.ArrayList; 6 | import java.util.Date; 7 | import java.util.List; 8 | import java.util.concurrent.atomic.AtomicInteger; 9 | import java.util.zip.CRC32; 10 | import java.util.zip.Checksum; 11 | 12 | import org.directmemory.measures.Ram; 13 | import org.directmemory.misc.Format; 14 | import org.josql.Query; 15 | import org.josql.QueryExecutionException; 16 | import org.josql.QueryParseException; 17 | import org.josql.QueryResults; 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | public class OffHeapMemoryBuffer { 22 | private static Logger logger = LoggerFactory.getLogger(OffHeapMemoryBuffer.class); 23 | protected ByteBuffer buffer; 24 | public List pointers = new ArrayList(); 25 | // public List pointers = new CopyOnWriteArrayList(); 26 | AtomicInteger used = new AtomicInteger(); 27 | public int bufferNumber; 28 | 29 | 30 | public int used() { 31 | return used.get(); 32 | } 33 | 34 | public int capacity(){ 35 | return buffer.capacity(); 36 | } 37 | 38 | public static OffHeapMemoryBuffer createNew(int capacity, int bufferNumber) { 39 | logger.info(Format.it("Creating OffHeapMemoryBuffer %d with a capacity of %s", bufferNumber, Ram.inMb(capacity))); 40 | return new OffHeapMemoryBuffer(ByteBuffer.allocateDirect(capacity), bufferNumber); 41 | } 42 | 43 | public static OffHeapMemoryBuffer createNew(int capacity) { 44 | return new OffHeapMemoryBuffer(ByteBuffer.allocateDirect(capacity), -1); 45 | } 46 | 47 | private OffHeapMemoryBuffer(ByteBuffer buffer, int bufferNumber) { 48 | this.buffer = buffer; 49 | this.bufferNumber = bufferNumber; 50 | createAndAddFirstPointer(); 51 | } 52 | 53 | private Pointer createAndAddFirstPointer() { 54 | Pointer first = new Pointer(); 55 | first.bufferNumber = bufferNumber; 56 | first.start = 0; 57 | first.free = true; 58 | first.end = buffer.capacity()-1; 59 | pointers.add(first); 60 | return first; 61 | } 62 | 63 | public Pointer slice(Pointer existing, int capacity) { 64 | Pointer fresh = new Pointer(); 65 | fresh.bufferNumber = existing.bufferNumber; 66 | fresh.start = existing.start; 67 | fresh.end = fresh.start+capacity; 68 | fresh.free = true; 69 | existing.start+=capacity+1; 70 | return fresh; 71 | } 72 | 73 | 74 | public Pointer firstMatch(int capacity) { 75 | for (Pointer ptr : pointers) { 76 | if (ptr.free && ptr.end >= capacity) { 77 | return ptr; 78 | } 79 | } 80 | return null; 81 | } 82 | 83 | public Pointer store(byte[] payload) { 84 | return store(payload, -1); 85 | } 86 | 87 | public byte[] retrieve(Pointer pointer) { 88 | // if (!pointer.expired()) { 89 | pointer.lastHit = System.currentTimeMillis(); 90 | pointer.hits++; 91 | 92 | ByteBuffer buf = null; 93 | synchronized (buffer) { 94 | buf = buffer.duplicate(); 95 | } 96 | buf.position(pointer.start); 97 | // not needed for reads 98 | // buf.limit(pointer.end+pointer.start); 99 | final byte[] swp = new byte[pointer.end-pointer.start]; 100 | buf.get(swp); 101 | return swp; 102 | // } else { 103 | // free(pointer); 104 | // return null; 105 | // } 106 | } 107 | 108 | 109 | public long free(Pointer pointer2free) { 110 | pointer2free.free = true; 111 | pointer2free.created = 0; 112 | pointer2free.lastHit = 0; 113 | pointer2free.hits = 0; 114 | pointer2free.expiresIn = 0; 115 | pointer2free.clazz = null; 116 | used.addAndGet(-( pointer2free.end-pointer2free.start)); 117 | pointers.add(pointer2free); 118 | return pointer2free.end-pointer2free.start; 119 | } 120 | 121 | public void clear() { 122 | pointers.clear(); 123 | createAndAddFirstPointer(); 124 | buffer.clear(); 125 | used.set(0); 126 | } 127 | 128 | public Pointer store(byte[] payload, Date expires) { 129 | return store(payload, 0, expires.getTime()); 130 | } 131 | 132 | public Pointer store(byte[] payload, long expiresIn) { 133 | return store(payload, expiresIn, 0); 134 | } 135 | 136 | private synchronized Pointer store(byte[] payload, long expiresIn, long expires) { 137 | Pointer goodOne = firstMatch(payload.length); 138 | 139 | if (goodOne == null ) { 140 | throw new NullPointerException("did not find a suitable buffer"); 141 | } 142 | 143 | Pointer fresh = slice(goodOne, payload.length); 144 | 145 | 146 | fresh.created = System.currentTimeMillis(); 147 | if (expiresIn > 0) { 148 | fresh.expiresIn = expiresIn; 149 | fresh.expires = 0; 150 | } else if (expires > 0) { 151 | fresh.expiresIn = 0; 152 | fresh.expires = expires; 153 | } 154 | 155 | fresh.free = false; 156 | used.addAndGet(payload.length); 157 | ByteBuffer buf = buffer.slice(); 158 | buf.position(fresh.start); 159 | try { 160 | buf.put(payload); 161 | } catch (BufferOverflowException e) { 162 | // RpG not convincing - let's fix it later 163 | goodOne.start = fresh.start; 164 | goodOne.end = buffer.limit(); 165 | return null; 166 | } 167 | pointers.add(fresh); 168 | return fresh; 169 | } 170 | 171 | private QueryResults select(String whereClause) throws QueryParseException, QueryExecutionException { 172 | Query q = new Query (); 173 | q.parse ("SELECT * FROM " + Pointer.class.getCanonicalName() + " WHERE " + whereClause); 174 | QueryResults qr = q.execute (pointers); 175 | return qr; 176 | } 177 | 178 | private QueryResults selectOrderBy(String whereClause, String orderBy, String limit) throws QueryParseException, QueryExecutionException { 179 | Query q = new Query (); 180 | q.parse ("SELECT * FROM " + Pointer.class.getCanonicalName() + " WHERE " + whereClause + " order by " + orderBy + " " + limit); 181 | QueryResults qr = q.execute (pointers); 182 | return qr; 183 | } 184 | 185 | public long collectLFU(int limit) { 186 | if (limit<=0) limit = pointers.size()/10; 187 | QueryResults qr; 188 | try { 189 | qr = selectOrderBy("free=false", "frequency", "limit 1, " + limit); 190 | @SuppressWarnings("unchecked") 191 | List result = qr.getResults(); 192 | return free(result); 193 | } catch (QueryParseException e) { 194 | // TODO Auto-generated catch block 195 | e.printStackTrace(); 196 | } catch (QueryExecutionException e) { 197 | // TODO Auto-generated catch block 198 | e.printStackTrace(); 199 | } 200 | return 0; 201 | } 202 | 203 | 204 | 205 | @SuppressWarnings("unchecked") 206 | private List filter(final String whereClause) { 207 | try { 208 | return select(whereClause).getResults(); 209 | } catch (QueryParseException e) { 210 | e.printStackTrace(); 211 | } catch (QueryExecutionException e) { 212 | e.printStackTrace(); 213 | } 214 | return (List) new ArrayList(); 215 | } 216 | 217 | private long free(List pointers) { 218 | long howMuch = 0; 219 | for (Pointer expired : pointers) { 220 | howMuch += free(expired); 221 | } 222 | return howMuch; 223 | } 224 | 225 | public void disposeExpiredRelative() { 226 | free(filter("free=false and expiresIn > 0 and (expiresIn+created) <= " + System.currentTimeMillis())); 227 | } 228 | 229 | public void disposeExpiredAbsolute() { 230 | free(filter("free=false and expires > 0 and (expires) <= " + System.currentTimeMillis())); 231 | } 232 | 233 | public long collectExpired() { 234 | int limit = 50; 235 | long disposed = free(filter("free=false and expiresIn > 0 and (expiresIn+created) <= " + System.currentTimeMillis() + " limit 1, " + limit)); 236 | disposed += free(filter("free=false and expires > 0 and (expires) <= " + System.currentTimeMillis() + " limit 1, 100" + limit)); 237 | return disposed; 238 | } 239 | 240 | public static long crc32(byte[] payload) { 241 | final Checksum checksum = new CRC32(); 242 | checksum.update(payload,0,payload.length); 243 | return checksum.getValue(); 244 | } 245 | 246 | public Pointer update(Pointer pointer, byte[] payload) { 247 | free(pointer); 248 | return store(payload); 249 | } 250 | 251 | } 252 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/memory/Pointer.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.memory; 2 | 3 | public class Pointer { 4 | public int start; 5 | public int end; 6 | public long created; 7 | public long expires; 8 | public long expiresIn; 9 | public long hits; 10 | public boolean free; 11 | public long lastHit; 12 | public int bufferNumber; 13 | public Class clazz; 14 | 15 | public byte[] content() { 16 | return null; 17 | } 18 | public boolean expired() { 19 | if (expires > 0 || expiresIn > 0) { 20 | return (expiresIn + created < System.currentTimeMillis()); 21 | } else { 22 | return false; 23 | } 24 | } 25 | 26 | public float getFrequency() { 27 | return (float)(System.currentTimeMillis()-created)/hits; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/misc/DummyPojo.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.misc; 2 | import java.io.Serializable; 3 | 4 | 5 | public class DummyPojo implements Serializable { 6 | /** 7 | * A dummy pojo implementation for test purposes 8 | */ 9 | private static final long serialVersionUID = 1L; 10 | public DummyPojo() { 11 | 12 | } 13 | 14 | public DummyPojo(String name, int size) { 15 | this.name = name; 16 | this.size = size; 17 | payLoad = new String(new byte [size]); 18 | } 19 | public String name; 20 | public int size; 21 | public String payLoad; 22 | } 23 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/misc/Format.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.misc; 2 | 3 | public class Format { 4 | 5 | public static String it(String string, Object ... args) { 6 | java.util.Formatter formatter = new java.util.Formatter(); 7 | return formatter.format(string, args).toString(); 8 | } 9 | 10 | public static String logo() { 11 | return 12 | " ____ _ __ __ ___\r\n" + 13 | " / __ \\(_)________ _____/ /_/ |/ /___ ____ ___ ____ _______ __\r\n" + 14 | " / / / / // ___/ _ \\/ ___/ __/ /|_/ // _ \\/ __ `__ \\/ __ \\/ ___/ / / /\r\n" + 15 | " / /_/ / // / / __/ /__/ /_/ / / // __/ / / / / / /_/ / / / /_/ / \r\n" + 16 | " /_____/_//_/ \\___/\\___/\\__/_/ /_/ \\___/_/ /_/ /_/\\____/_/ \\__, /\r\n" + 17 | " /____/ "; 18 | 19 | // return 20 | // " ___ _ _ _\r\n" + 21 | // " ( / \\ o _/_( / ) )\r\n" + 22 | // " / /, _ _ _, / / / / _ _ _ _ __ _ __ ,\r\n" + 23 | // "(/\\_/ (_/ (_(/_(__(__ / / (_(/_/ / / /_(_)/ (_/ (_/_\r\n" + 24 | // " /\r\n" + 25 | // " '"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/serialization/DummyPojoSerializer.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.serialization; 2 | 3 | import java.io.EOFException; 4 | import java.io.IOException; 5 | 6 | import org.directmemory.measures.Ram; 7 | import org.directmemory.misc.DummyPojo; 8 | 9 | import com.dyuproject.protostuff.LinkedBuffer; 10 | import com.dyuproject.protostuff.ProtostuffIOUtil; 11 | import com.dyuproject.protostuff.runtime.RuntimeSchema; 12 | 13 | public final class DummyPojoSerializer implements Serializer 14 | { 15 | 16 | final DummyPojo pojo = new DummyPojo("test", Ram.Kb(2)); 17 | final byte[] data; 18 | 19 | public DummyPojoSerializer() 20 | { 21 | data = ProtostuffIOUtil.toByteArray(pojo, RuntimeSchema.getSchema(DummyPojo.class), LinkedBuffer.allocate(2048)); 22 | } 23 | 24 | @Override 25 | public Object deserialize(byte[] source, @SuppressWarnings({"rawtypes","unchecked"}) Class clazz) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, 26 | EOFException 27 | { 28 | // testing puts only 29 | return pojo; 30 | } 31 | 32 | @Override 33 | public byte[] serialize(Object obj, @SuppressWarnings({"rawtypes","unchecked"}) Class clazz) throws IOException 34 | { 35 | // byte[] ser = new byte[data.length]; 36 | // System.arraycopy(data, 0, ser, 0, data.length); 37 | return data; 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/serialization/ProtoStuffSerializerV1.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.serialization; 2 | 3 | import java.io.IOException; 4 | 5 | import org.directmemory.measures.Ram; 6 | 7 | import com.dyuproject.protostuff.LinkedBuffer; 8 | import com.dyuproject.protostuff.ProtostuffIOUtil; 9 | import com.dyuproject.protostuff.Schema; 10 | import com.dyuproject.protostuff.runtime.RuntimeSchema; 11 | 12 | public class ProtoStuffSerializerV1 implements Serializer { 13 | 14 | static int serBufferSize = Ram.Kb(3); 15 | // static int serBufferSize = 300; 16 | 17 | /* (non-Javadoc) 18 | * @see org.directmemory.utils.Serializer#serialize(java.lang.Object, java.lang.Class) 19 | */ 20 | @SuppressWarnings("unchecked") 21 | public byte[] serialize(Object obj, @SuppressWarnings("rawtypes") Class clazz) throws IOException { 22 | @SuppressWarnings("rawtypes") 23 | Schema schema = RuntimeSchema.getSchema(clazz); 24 | final LinkedBuffer buffer = LinkedBuffer.allocate(serBufferSize); 25 | byte[] protostuff = null; 26 | 27 | try { 28 | protostuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer); 29 | } finally { 30 | buffer.clear(); 31 | } 32 | return protostuff; 33 | } 34 | 35 | /* (non-Javadoc) 36 | * @see org.directmemory.utils.Serializer#deserialize(byte[], java.lang.Class) 37 | */ 38 | @SuppressWarnings("unchecked") 39 | public Object deserialize(byte[] source, @SuppressWarnings("rawtypes") Class clazz) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { 40 | final Object object = clazz.newInstance(); 41 | @SuppressWarnings("rawtypes") 42 | final Schema schema = RuntimeSchema.getSchema(clazz); 43 | ProtostuffIOUtil.mergeFrom(source, object, schema); 44 | return object; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/serialization/ProtoStuffWithLinkedBufferSerializer.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.serialization; 2 | 3 | import java.io.IOException; 4 | 5 | import org.directmemory.measures.Ram; 6 | 7 | import com.dyuproject.protostuff.LinkedBuffer; 8 | import com.dyuproject.protostuff.ProtostuffIOUtil; 9 | import com.dyuproject.protostuff.Schema; 10 | import com.dyuproject.protostuff.runtime.RuntimeSchema; 11 | 12 | public final class ProtoStuffWithLinkedBufferSerializer implements Serializer { 13 | 14 | static int bufferSize = Ram.Kb(3); 15 | 16 | 17 | /* 18 | * 19 | * 20 | * 21 | LinkedBuffer buffer8k = ...; 22 | try 23 | { 24 | ProtostuffIOUtil.writeTo(new ByteBufferOutputStream() { // paging logic }, message, schema, buffer8k) 25 | } 26 | finally 27 | { 28 | buffer8k.clear(); 29 | } 30 | 31 | ProtostuffIOUtil.mergeFrom(new ByteArrayInputStream() { // paging logic}, message, schema, buffer8k); 32 | 33 | */ 34 | 35 | private static final ThreadLocal localBuffer = new ThreadLocal() { 36 | protected LinkedBuffer initialValue() { 37 | return LinkedBuffer.allocate(bufferSize); 38 | } 39 | }; 40 | 41 | public ProtoStuffWithLinkedBufferSerializer() { 42 | 43 | } 44 | 45 | 46 | public ProtoStuffWithLinkedBufferSerializer(int bufferSize) { 47 | ProtoStuffWithLinkedBufferSerializer.bufferSize =bufferSize; 48 | } 49 | 50 | 51 | 52 | /* (non-Javadoc) 53 | * @see org.directmemory.utils.Serializer#serialize(java.lang.Object, java.lang.Class) 54 | */ 55 | @SuppressWarnings("unchecked") 56 | public byte[] serialize(Object obj, @SuppressWarnings("rawtypes") Class clazz) throws IOException { 57 | @SuppressWarnings("rawtypes") 58 | Schema schema = RuntimeSchema.getSchema(clazz); 59 | final LinkedBuffer buffer = localBuffer.get(); 60 | byte[] protostuff = null; 61 | 62 | try { 63 | protostuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer); 64 | } finally { 65 | buffer.clear(); 66 | } 67 | return protostuff; 68 | } 69 | 70 | /* (non-Javadoc) 71 | * @see org.directmemory.utils.Serializer#deserialize(byte[], java.lang.Class) 72 | */ 73 | @SuppressWarnings("unchecked") 74 | public Object deserialize(byte[] source, @SuppressWarnings("rawtypes") Class clazz) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { 75 | Object object = clazz.newInstance(); 76 | @SuppressWarnings("rawtypes") 77 | Schema schema = RuntimeSchema.getSchema(clazz); 78 | ProtostuffIOUtil.mergeFrom(source, object, schema); 79 | return object; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/serialization/Serializer.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.serialization; 2 | 3 | import java.io.EOFException; 4 | import java.io.IOException; 5 | 6 | public interface Serializer { 7 | 8 | public abstract byte[] serialize(Object obj, @SuppressWarnings({"rawtypes","unchecked"}) Class clazz) throws IOException; 9 | 10 | public abstract Object deserialize(byte[] source, @SuppressWarnings({"rawtypes","unchecked"}) Class clazz) throws IOException, 11 | ClassNotFoundException, InstantiationException, IllegalAccessException, EOFException; 12 | 13 | } -------------------------------------------------------------------------------- /DirectMemory-Cache/src/main/java/org/directmemory/serialization/StandardSerializer.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.serialization; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.IOException; 6 | import java.io.ObjectInputStream; 7 | import java.io.ObjectOutputStream; 8 | import java.io.Serializable; 9 | 10 | public class StandardSerializer implements Serializer { 11 | 12 | public byte[] serialize(Object obj, @SuppressWarnings({"rawtypes","unchecked"}) Class clazz) throws IOException { 13 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 14 | ObjectOutputStream oos = new ObjectOutputStream(baos); 15 | oos.writeObject(obj); 16 | oos.flush(); 17 | oos.close(); 18 | return baos.toByteArray(); 19 | } 20 | 21 | public Serializable deserialize(byte[] source, @SuppressWarnings({"rawtypes","unchecked"}) Class clazz) throws IOException, ClassNotFoundException { 22 | ByteArrayInputStream bis = new ByteArrayInputStream(source); 23 | ObjectInputStream ois = new ObjectInputStream(bis); 24 | Serializable obj = (Serializable) ois.readObject(); 25 | ois.close(); 26 | return obj; 27 | }} 28 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/cache/test/CacheConcurrentTests.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.cache.test; 2 | 3 | import java.util.Random; 4 | import java.util.concurrent.atomic.AtomicInteger; 5 | 6 | import org.directmemory.cache.Cache; 7 | import org.directmemory.measures.Monitor; 8 | import org.directmemory.measures.Ram; 9 | import org.directmemory.memory.MemoryManager; 10 | import org.directmemory.memory.Pointer; 11 | import org.junit.AfterClass; 12 | import org.junit.BeforeClass; 13 | import org.junit.Rule; 14 | import org.junit.Test; 15 | import org.junit.rules.MethodRule; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | import com.carrotsearch.junitbenchmarks.BenchmarkOptions; 20 | import com.carrotsearch.junitbenchmarks.BenchmarkRule; 21 | import com.carrotsearch.junitbenchmarks.annotation.AxisRange; 22 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkHistoryChart; 23 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart; 24 | import com.carrotsearch.junitbenchmarks.annotation.LabelType; 25 | 26 | @AxisRange(min = 0, max = 1) 27 | @BenchmarkMethodChart() 28 | @BenchmarkHistoryChart(labelWith = LabelType.CUSTOM_KEY, maxRuns = 5) 29 | 30 | public class CacheConcurrentTests { 31 | 32 | private final static int entries = 100000; 33 | public static AtomicInteger count = new AtomicInteger(); 34 | private static AtomicInteger got = new AtomicInteger(); 35 | private static AtomicInteger missed = new AtomicInteger(); 36 | private static AtomicInteger good = new AtomicInteger(); 37 | private static AtomicInteger bad = new AtomicInteger(); 38 | private static AtomicInteger read = new AtomicInteger(); 39 | private static AtomicInteger disposals = new AtomicInteger(); 40 | 41 | @BenchmarkOptions(benchmarkRounds = 10000, warmupRounds=0, concurrency=1000) 42 | @Test 43 | public void store() { 44 | final String key = "test-" + count.incrementAndGet(); 45 | put(key); 46 | } 47 | 48 | @BenchmarkOptions(benchmarkRounds = 500, warmupRounds=0, concurrency=10) 49 | @Test 50 | public void storeSomeWithExpiry() { 51 | final String key = "test-" + count.incrementAndGet(); 52 | putWithExpiry(key); 53 | } 54 | 55 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=100) 56 | @Test 57 | public void retrieveCatchThemAll() { 58 | String key = "test-" + (rndGen.nextInt(entries)+1); 59 | get(key); 60 | } 61 | 62 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=100) 63 | @Test 64 | public void retrieveCatchHalfOfThem() { 65 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 66 | get(key); 67 | } 68 | 69 | private void get(String key) { 70 | Pointer p = Cache.getPointer(key); 71 | @SuppressWarnings("unused") 72 | byte [] check = Cache.retrieveByteArray(key); 73 | read.incrementAndGet(); 74 | if (p != null) { 75 | got.incrementAndGet(); 76 | byte [] payload = MemoryManager.retrieve(p); 77 | if ((new String(payload)).startsWith(key)) 78 | good.incrementAndGet(); 79 | else 80 | bad.incrementAndGet(); 81 | } else { 82 | missed.incrementAndGet(); 83 | } 84 | } 85 | 86 | private void put(String key) { 87 | final StringBuilder bldr = new StringBuilder(); 88 | for (int i = 0; i < 100; i++) { 89 | bldr.append(key); 90 | } 91 | Cache.putByteArray(key,bldr.toString().getBytes()); 92 | } 93 | 94 | private void putWithExpiry(String key) { 95 | final StringBuilder bldr = new StringBuilder(); 96 | for (int i = 0; i < 100; i++) { 97 | bldr.append(key); 98 | } 99 | Cache.putByteArray(key, bldr.toString().getBytes(), rndGen.nextInt(2000)); 100 | } 101 | 102 | 103 | @BenchmarkOptions(benchmarkRounds = 50000, warmupRounds=0, concurrency=10) 104 | @Test 105 | public void write1Read8AndSomeDisposal() { 106 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 107 | 108 | int what = rndGen.nextInt(10); 109 | 110 | switch (what) { 111 | case 0: 112 | put(key); 113 | break; 114 | case 1: 115 | case 2: 116 | case 3: 117 | case 4: 118 | case 5: 119 | case 6: 120 | case 7: 121 | case 8: 122 | get(key); 123 | break; 124 | default: 125 | final int rndVal = rndGen.nextInt(1000); 126 | if ( rndVal > 995) { 127 | disposals.incrementAndGet(); 128 | final long start = System.currentTimeMillis(); 129 | long howMany = MemoryManager.collectExpired(); 130 | final long end = System.currentTimeMillis(); 131 | logger.info("" + howMany + " disposed in " + (end-start) + " milliseconds"); 132 | } 133 | } 134 | 135 | } 136 | 137 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=10) 138 | @Test 139 | public void write3Read7() { 140 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 141 | 142 | int what = rndGen.nextInt(10); 143 | 144 | switch (what) { 145 | case 0: 146 | case 1: 147 | case 2: 148 | put(key); 149 | break; 150 | default: 151 | get(key); 152 | break; 153 | } 154 | } 155 | 156 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=10) 157 | @Test 158 | public void write1Read9() { 159 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 160 | 161 | int what = rndGen.nextInt(10); 162 | 163 | switch (what) { 164 | case 0: 165 | put(key); 166 | break; 167 | default: 168 | get(key); 169 | break; 170 | 171 | } 172 | 173 | } 174 | 175 | Random rndGen = new Random(); 176 | 177 | @Rule 178 | public MethodRule benchmarkRun = new BenchmarkRule(); 179 | 180 | 181 | private static Logger logger = LoggerFactory.getLogger(CacheConcurrentTests.class); 182 | 183 | @BeforeClass 184 | public static void init() { 185 | Cache.init(1, Ram.Mb(512)); 186 | Cache.dump(); 187 | } 188 | 189 | @AfterClass 190 | public static void dump() { 191 | 192 | Cache.dump(); 193 | Monitor.dump("cache"); 194 | 195 | logger.info("************************************************"); 196 | logger.info("entries: " + entries); 197 | logger.info("inserted: " + Cache.entries()); 198 | logger.info("reads: " + read); 199 | logger.info("count: " + count); 200 | logger.info("got: " + got); 201 | logger.info("missed: " + missed); 202 | logger.info("good: " + good); 203 | logger.info("bad: " + bad); 204 | logger.info("disposals: " + disposals); 205 | logger.info("************************************************"); 206 | } 207 | 208 | } 209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/cache/test/CacheLightConcurrentTest.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.cache.test; 2 | 3 | import java.util.Random; 4 | import java.util.concurrent.atomic.AtomicInteger; 5 | 6 | import org.directmemory.cache.Cache; 7 | import org.directmemory.measures.Every; 8 | import org.directmemory.measures.Monitor; 9 | import org.directmemory.measures.Ram; 10 | import org.directmemory.memory.MemoryManager; 11 | import org.directmemory.memory.Pointer; 12 | import org.josql.QueryExecutionException; 13 | import org.josql.QueryParseException; 14 | import org.junit.AfterClass; 15 | import org.junit.BeforeClass; 16 | import org.junit.Rule; 17 | import org.junit.Test; 18 | import org.junit.rules.MethodRule; 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import com.carrotsearch.junitbenchmarks.BenchmarkOptions; 23 | import com.carrotsearch.junitbenchmarks.BenchmarkRule; 24 | import com.carrotsearch.junitbenchmarks.annotation.AxisRange; 25 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkHistoryChart; 26 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart; 27 | import com.carrotsearch.junitbenchmarks.annotation.LabelType; 28 | 29 | @AxisRange(min = 0, max = 1) 30 | @BenchmarkMethodChart() 31 | @BenchmarkHistoryChart(labelWith = LabelType.CUSTOM_KEY, maxRuns = 5) 32 | 33 | public class CacheLightConcurrentTest { 34 | 35 | private final static int entries = 10000; 36 | public static AtomicInteger count = new AtomicInteger(); 37 | private static AtomicInteger got = new AtomicInteger(); 38 | private static AtomicInteger missed = new AtomicInteger(); 39 | private static AtomicInteger good = new AtomicInteger(); 40 | private static AtomicInteger bad = new AtomicInteger(); 41 | private static AtomicInteger read = new AtomicInteger(); 42 | private static AtomicInteger disposals = new AtomicInteger(); 43 | 44 | @BenchmarkOptions(benchmarkRounds = 10000, warmupRounds=0, concurrency=100) 45 | @Test 46 | public void store() { 47 | final String key = "test-" + count.incrementAndGet(); 48 | put(key); 49 | } 50 | 51 | @BenchmarkOptions(benchmarkRounds = 50, warmupRounds=0, concurrency=10) 52 | @Test 53 | public void storeSomeWithExpiry() { 54 | final String key = "test-" + count.incrementAndGet(); 55 | putWithExpiry(key); 56 | } 57 | 58 | @BenchmarkOptions(benchmarkRounds = 100000, warmupRounds=0, concurrency=100) 59 | @Test 60 | public void retrieveCatchThemAll() { 61 | String key = "test-" + (rndGen.nextInt(entries)+1); 62 | getAndRetrieve(key); 63 | } 64 | 65 | @BenchmarkOptions(benchmarkRounds = 100000, warmupRounds=0, concurrency=100) 66 | @Test 67 | public void retrieveCatchHalfOfThem() { 68 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 69 | getAndRetrieve(key); 70 | } 71 | 72 | @BenchmarkOptions(benchmarkRounds = 1, warmupRounds=0, concurrency=1) 73 | @Test 74 | public void LFUEviction() throws QueryParseException, QueryExecutionException { 75 | Cache.collectAll(); 76 | } 77 | 78 | private void getAndRetrieve(String key) { 79 | Pointer p = Cache.getPointer(key); 80 | @SuppressWarnings("unused") 81 | byte [] check = Cache.retrieveByteArray(key); 82 | read.incrementAndGet(); 83 | if (p != null) { 84 | got.incrementAndGet(); 85 | byte [] payload = MemoryManager.retrieve(p); 86 | if ((new String(payload)).startsWith(key)) 87 | good.incrementAndGet(); 88 | else 89 | bad.incrementAndGet(); 90 | } else { 91 | missed.incrementAndGet(); 92 | } 93 | } 94 | 95 | private void put(String key) { 96 | final StringBuilder bldr = new StringBuilder(); 97 | for (int i = 0; i < 100; i++) { 98 | bldr.append(key); 99 | } 100 | Cache.putByteArray(key,bldr.toString().getBytes()); 101 | } 102 | 103 | private void putWithExpiry(String key) { 104 | final StringBuilder bldr = new StringBuilder(); 105 | for (int i = 0; i < 100; i++) { 106 | bldr.append(key); 107 | } 108 | Cache.putByteArray(key, bldr.toString().getBytes(), rndGen.nextInt(2000)); 109 | } 110 | 111 | 112 | @BenchmarkOptions(benchmarkRounds = 5000, warmupRounds=0, concurrency=10) 113 | @Test 114 | public void write1Read8AndSomeDisposal() { 115 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 116 | 117 | int what = rndGen.nextInt(10); 118 | 119 | switch (what) { 120 | case 0: 121 | put(key); 122 | break; 123 | case 1: 124 | case 2: 125 | case 3: 126 | case 4: 127 | case 5: 128 | case 6: 129 | case 7: 130 | case 8: 131 | getAndRetrieve(key); 132 | break; 133 | default: 134 | final int rndVal = rndGen.nextInt(100); 135 | if ( rndVal > 98) { 136 | disposals.incrementAndGet(); 137 | final long start = System.currentTimeMillis(); 138 | long howMany = MemoryManager.collectExpired(); 139 | final long end = System.currentTimeMillis(); 140 | logger.info("" + howMany + " disposed in " + (end-start) + " milliseconds"); 141 | } 142 | } 143 | 144 | } 145 | 146 | @BenchmarkOptions(benchmarkRounds = 100000, warmupRounds=0, concurrency=10) 147 | @Test 148 | public void write3Read7() { 149 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 150 | 151 | int what = rndGen.nextInt(10); 152 | 153 | switch (what) { 154 | case 0: 155 | case 1: 156 | case 2: 157 | put(key); 158 | break; 159 | default: 160 | getAndRetrieve(key); 161 | break; 162 | } 163 | } 164 | 165 | @BenchmarkOptions(benchmarkRounds = 100000, warmupRounds=0, concurrency=10) 166 | @Test 167 | public void write1Read9() { 168 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 169 | 170 | int what = rndGen.nextInt(10); 171 | 172 | switch (what) { 173 | case 0: 174 | put(key); 175 | break; 176 | default: 177 | getAndRetrieve(key); 178 | break; 179 | 180 | } 181 | 182 | } 183 | 184 | Random rndGen = new Random(); 185 | 186 | @Rule 187 | public MethodRule benchmarkRun = new BenchmarkRule(); 188 | 189 | 190 | private static Logger logger = LoggerFactory.getLogger(CacheLightConcurrentTest.class); 191 | 192 | @BeforeClass 193 | public static void init() { 194 | Cache.init(1, Ram.Mb(128)); 195 | Cache.scheduleDisposalEvery(Every.seconds(1)); 196 | Cache.dump(); 197 | } 198 | 199 | @AfterClass 200 | public static void dump() { 201 | 202 | Cache.dump(); 203 | Monitor.dump("cache"); 204 | 205 | logger.info("************************************************"); 206 | logger.info("entries: " + entries); 207 | logger.info("inserted: " + Cache.entries()); 208 | logger.info("reads: " + read); 209 | logger.info("count: " + count); 210 | logger.info("got: " + got); 211 | logger.info("missed: " + missed); 212 | logger.info("good: " + good); 213 | logger.info("bad: " + bad); 214 | logger.info("disposals: " + disposals); 215 | logger.info("************************************************"); 216 | } 217 | 218 | } 219 | 220 | 221 | 222 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/cache/test/TestCachePlusSerialization.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.cache.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.Random; 6 | 7 | import org.directmemory.cache.Cache; 8 | import org.directmemory.measures.Monitor; 9 | import org.directmemory.measures.Ram; 10 | import org.directmemory.misc.DummyPojo; 11 | import org.junit.AfterClass; 12 | import org.junit.BeforeClass; 13 | import org.junit.Rule; 14 | import org.junit.Test; 15 | import org.junit.rules.MethodRule; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | import com.carrotsearch.junitbenchmarks.BenchmarkOptions; 20 | import com.carrotsearch.junitbenchmarks.BenchmarkRule; 21 | 22 | 23 | public class TestCachePlusSerialization { 24 | @Rule 25 | public MethodRule benchmarkRun = new BenchmarkRule(); 26 | 27 | private static Logger logger = LoggerFactory.getLogger(TestCachePlusSerialization.class); 28 | 29 | Random rnd = new Random(); 30 | 31 | @BeforeClass 32 | public static void init() { 33 | logger.info("test started"); 34 | Cache.init(1, Ram.Mb(100)); 35 | } 36 | 37 | @AfterClass 38 | public static void end() { 39 | Cache.dump(); 40 | Monitor.dump(); 41 | logger.info("test ended"); 42 | } 43 | 44 | @BenchmarkOptions(benchmarkRounds = 50000, warmupRounds=0, concurrency=1) 45 | @Test 46 | public void basicBench() { 47 | 48 | DummyPojo d = new DummyPojo("test-" + rnd.nextInt(100000), 1024 + rnd.nextInt(1024)); 49 | Cache.put(d.name, d); 50 | DummyPojo d2 = (DummyPojo) Cache.retrieve(d.name); 51 | 52 | assertEquals(d.name, d2.name); 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/memory/test/BaseTests.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.memory.test; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import java.util.Date; 7 | import java.util.Map; 8 | import java.util.Random; 9 | import java.util.zip.CRC32; 10 | import java.util.zip.Checksum; 11 | 12 | import org.directmemory.measures.Ram; 13 | import org.directmemory.memory.OffHeapMemoryBuffer; 14 | import org.directmemory.memory.Pointer; 15 | import org.junit.AfterClass; 16 | import org.junit.BeforeClass; 17 | import org.junit.Test; 18 | import org.junit.rules.MethodRule; 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import com.carrotsearch.junitbenchmarks.BenchmarkOptions; 23 | import com.carrotsearch.junitbenchmarks.BenchmarkRule; 24 | import com.google.common.collect.Maps; 25 | 26 | public class BaseTests { 27 | // @Rule 28 | public MethodRule benchmarkRun = new BenchmarkRule(); 29 | 30 | @Test 31 | public void smokeTest() { 32 | OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(1 * 1024 * 1024); 33 | logger.info("buffer size=" + mem.capacity()); 34 | assertNotNull(mem); 35 | 36 | Random rnd = new Random(); 37 | 38 | int size = rnd.nextInt(10) * mem.capacity() / 100; 39 | 40 | logger.info("size=" + size); 41 | 42 | Pointer p = mem.store(new byte[size]); 43 | assertNotNull(p); 44 | assertEquals(size,p.end); 45 | assertEquals(size, mem.used()); 46 | mem.free(p); 47 | assertEquals(0, mem.used()); 48 | } 49 | 50 | 51 | 52 | 53 | private static Logger logger = LoggerFactory.getLogger(MallocTests.class); 54 | private static Random rnd = new Random(); 55 | final static Map test = Maps.newHashMap(); 56 | private static int errors; 57 | 58 | public long crc(String str) { 59 | final Checksum checksum = new CRC32(); 60 | 61 | final byte bytes[] = str.getBytes(); 62 | checksum.update(bytes,0,bytes.length); 63 | return checksum.getValue(); 64 | } 65 | 66 | @BeforeClass 67 | @AfterClass 68 | public static void setup() { 69 | rnd = new Random(); 70 | // logger.info("off-heap allocated: " + Ram.inMb(mem.capacity())); 71 | // logger.info("off-heap used: " + Ram.inMb(mem.used())); 72 | logger.info("test - size: " + test.size()); 73 | logger.info("test - errors: " + errors); 74 | logger.info("heap - max: " + Ram.inMb(Runtime.getRuntime().maxMemory())); 75 | logger.info("heap - allocated: " + Ram.inMb(Runtime.getRuntime().totalMemory())); 76 | logger.info("heap - free : " + Ram.inMb(Runtime.getRuntime().freeMemory())); 77 | logger.info("************************************************"); 78 | } 79 | 80 | @BenchmarkOptions(benchmarkRounds = 10000, warmupRounds = 0, concurrency = 10) 81 | @Test 82 | public void anyDuplicates() { 83 | String key = "test" + rnd.nextInt(100000); 84 | if (test.containsKey(key)) { 85 | logger.error("key " + key + " has already been used"); 86 | errors++; 87 | } 88 | test.put(key, (byte) 0); 89 | } 90 | 91 | @Test 92 | public void aFewEntriesWithRead() { 93 | OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(100 * 1024 * 1024); 94 | logger.info("total capacity=" + Ram.inMb(mem.capacity())); 95 | assertNotNull(mem); 96 | int howMany = 10000; 97 | logger.info("payload size is variable"); 98 | logger.info("entries=" + howMany); 99 | String test = "this is a nicely crafted test"; 100 | for (int i = 0; i < howMany; i++) { 101 | final byte[] payload = (test + " - " + i).getBytes(); 102 | Pointer p = mem.store(payload); 103 | final byte[] check = mem.retrieve(p); 104 | assertNotNull(check); 105 | assertEquals(test + " - " + i, new String(check)); 106 | long crc1 = OffHeapMemoryBuffer.crc32(payload); 107 | long crc2 = OffHeapMemoryBuffer.crc32(check); 108 | assertEquals(crc1, crc2); 109 | } 110 | 111 | logger.info("total used=" + Ram.inMb(mem.used())); 112 | } 113 | 114 | @Test 115 | public void aFewEntriesWithCheck() { 116 | OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(10 * 1024 * 1024); 117 | logger.info("total capacity=" + Ram.inMb(mem.capacity())); 118 | assertNotNull(mem); 119 | int howMany = 10; 120 | logger.info("payload size is variable"); 121 | logger.info("entries=" + howMany); 122 | String test = "this is a nicely crafted test"; 123 | Pointer lastP = null; 124 | for (int i = 0; i < howMany; i++) { 125 | byte[] payload = (test + " - " + i).getBytes(); 126 | Pointer p = mem.store(payload); 127 | logger.info("p.start=" + p.start); 128 | logger.info("p.end=" + p.end); 129 | if (lastP != null) { 130 | assertEquals(lastP.end +1, p.start); 131 | } 132 | assertEquals(p.end-p.start, payload.length); 133 | lastP = p; 134 | logger.info("---"); 135 | } 136 | 137 | logger.info("total used=" + Ram.inMb(mem.used())); 138 | } 139 | 140 | @Test 141 | public void checkExpiration() throws InterruptedException { 142 | OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(10 * 1024 * 1024); 143 | assertNotNull(mem); 144 | int size = 400; 145 | int howMany = 5000; 146 | 147 | logger.info("off-heap capacity=" + Ram.inMb(mem.capacity())); 148 | logger.info("payload size=" + Ram.inKb(size)); 149 | logger.info("entries=" + howMany); 150 | 151 | byte[] payload = new byte[size]; 152 | for (int i = 0; i < howMany; i++) { 153 | mem.store(payload, 2000); 154 | } 155 | 156 | assertEquals(size*howMany, mem.used()); 157 | 158 | logger.info("entries with relative expiration=" + (howMany/2)); 159 | for (int i = 0; i < howMany/2; i++) { 160 | mem.store(payload, 100); 161 | } 162 | assertEquals(size*howMany+size*howMany/2, mem.used()); 163 | 164 | logger.info("entries with absolute expiration=" + (howMany/2)); 165 | for (int i = 0; i < howMany/2; i++) { 166 | mem.store(payload, new Date()); 167 | } 168 | assertEquals(size*howMany*2, mem.used()); 169 | logger.info("total used=" + Ram.inMb(mem.used())); 170 | 171 | Thread.sleep(500); 172 | 173 | logger.info("calling disposeExpiredAbsolute"); 174 | mem.disposeExpiredAbsolute(); 175 | logger.info("total used=" + Ram.inMb(mem.used())); 176 | assertEquals(size*howMany+size*howMany/2, mem.used()); 177 | 178 | logger.info("calling disposeExpiredRelative"); 179 | mem.disposeExpiredRelative(); 180 | logger.info("total used=" + Ram.inMb(mem.used())); 181 | assertEquals(size*howMany, mem.used()); 182 | 183 | Thread.sleep(2000); 184 | 185 | logger.info("calling disposeExpiredRelative again"); 186 | mem.disposeExpiredRelative(); 187 | logger.info("total used=" + Ram.inMb(mem.used())); 188 | assertEquals(0, mem.used()); 189 | 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/memory/test/ConcurrentTests.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.memory.test; 2 | 3 | import java.util.Random; 4 | import java.util.concurrent.ConcurrentMap; 5 | import java.util.concurrent.atomic.AtomicInteger; 6 | 7 | import org.directmemory.measures.Ram; 8 | import org.directmemory.memory.OffHeapMemoryBuffer; 9 | import org.directmemory.memory.Pointer; 10 | import org.junit.AfterClass; 11 | import org.junit.BeforeClass; 12 | import org.junit.Rule; 13 | import org.junit.Test; 14 | import org.junit.rules.MethodRule; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | 18 | import com.carrotsearch.junitbenchmarks.BenchmarkOptions; 19 | import com.carrotsearch.junitbenchmarks.BenchmarkRule; 20 | import com.carrotsearch.junitbenchmarks.annotation.AxisRange; 21 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkHistoryChart; 22 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart; 23 | import com.carrotsearch.junitbenchmarks.annotation.LabelType; 24 | import com.google.common.collect.MapMaker; 25 | 26 | @AxisRange(min = 0, max = 1) 27 | @BenchmarkMethodChart() 28 | @BenchmarkHistoryChart(labelWith = LabelType.CUSTOM_KEY, maxRuns = 5) 29 | 30 | public class ConcurrentTests { 31 | 32 | private final static int entries = 100000; 33 | public static AtomicInteger count = new AtomicInteger(); 34 | private static AtomicInteger got = new AtomicInteger(); 35 | private static AtomicInteger missed = new AtomicInteger(); 36 | private static AtomicInteger good = new AtomicInteger(); 37 | private static AtomicInteger bad = new AtomicInteger(); 38 | private static AtomicInteger read = new AtomicInteger(); 39 | public static OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(512 * 1024 * 1024); 40 | 41 | public static ConcurrentMap map = new MapMaker() 42 | .concurrencyLevel(4) 43 | .initialCapacity(100000) 44 | .makeMap(); 45 | 46 | 47 | @BenchmarkOptions(benchmarkRounds = 100000, warmupRounds=0, concurrency=100) 48 | @Test 49 | public void store() { 50 | final String key = "test-" + count.incrementAndGet(); 51 | map.put(key, mem.store(key.getBytes())); 52 | } 53 | 54 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=100) 55 | @Test 56 | public void retrieveCatchThemAll() { 57 | String key = "test-" + (rndGen.nextInt(entries)+1); 58 | Pointer p = map.get(key); 59 | read.incrementAndGet(); 60 | if (p != null) { 61 | got.incrementAndGet(); 62 | byte [] payload = mem.retrieve(p); 63 | if (key.equals(new String(payload))) 64 | good.incrementAndGet(); 65 | else 66 | bad.incrementAndGet(); 67 | } else { 68 | logger.info("did not find key " + key); 69 | missed.incrementAndGet(); 70 | } 71 | } 72 | 73 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=100) 74 | @Test 75 | public void retrieveCatchHalfOfThem() { 76 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 77 | Pointer p = map.get(key); 78 | read.incrementAndGet(); 79 | if (p != null) { 80 | got.incrementAndGet(); 81 | byte [] payload = mem.retrieve(p); 82 | if (key.equals(new String(payload))) 83 | good.incrementAndGet(); 84 | else 85 | bad.incrementAndGet(); 86 | } else { 87 | missed.incrementAndGet(); 88 | } 89 | } 90 | 91 | private void put(String key) { 92 | map.put(key, mem.store(key.getBytes())); 93 | } 94 | 95 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=10) 96 | @Test 97 | public void write3Read7() { 98 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 99 | 100 | int what = rndGen.nextInt(10); 101 | 102 | switch (what) { 103 | case 0: 104 | case 1: 105 | case 2: 106 | put(key); 107 | break; 108 | default: 109 | get(key); 110 | break; 111 | 112 | } 113 | 114 | } 115 | 116 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=10) 117 | @Test 118 | public void write1Read9() { 119 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 120 | 121 | int what = rndGen.nextInt(10); 122 | 123 | switch (what) { 124 | case 0: 125 | put(key); 126 | break; 127 | default: 128 | get(key); 129 | break; 130 | 131 | } 132 | 133 | } 134 | private void get(String key) { 135 | Pointer p = map.get(key); 136 | read.incrementAndGet(); 137 | if (p != null) { 138 | got.incrementAndGet(); 139 | byte [] payload = mem.retrieve(p); 140 | if (key.equals(new String(payload))) 141 | good.incrementAndGet(); 142 | else 143 | bad.incrementAndGet(); 144 | } else { 145 | missed.incrementAndGet(); 146 | } 147 | } 148 | 149 | Random rndGen = new Random(); 150 | 151 | @Rule 152 | public MethodRule benchmarkRun = new BenchmarkRule(); 153 | 154 | 155 | private static Logger logger = LoggerFactory.getLogger(ConcurrentTests.class); 156 | 157 | @BeforeClass 158 | @AfterClass 159 | public static void dump() { 160 | logger.info("off-heap allocated: " + Ram.inMb(mem.capacity())); 161 | logger.info("off-heap used: " + Ram.inMb(mem.used())); 162 | logger.info("heap - max: " + Ram.inMb(Runtime.getRuntime().maxMemory())); 163 | logger.info("heap - allocated: " + Ram.inMb(Runtime.getRuntime().totalMemory())); 164 | logger.info("heap - free : " + Ram.inMb(Runtime.getRuntime().freeMemory())); 165 | logger.info("************************************************"); 166 | logger.info("entries: " + entries); 167 | logger.info("inserted: " + map.size()); 168 | logger.info("reads: " + read); 169 | logger.info("count: " + count); 170 | logger.info("got: " + got); 171 | logger.info("missed: " + missed); 172 | logger.info("good: " + good); 173 | logger.info("bad: " + bad); 174 | logger.info("************************************************"); 175 | } 176 | 177 | } 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/memory/test/ConcurrentTests2.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.memory.test; 2 | 3 | import java.util.Random; 4 | import java.util.concurrent.ConcurrentMap; 5 | import java.util.concurrent.atomic.AtomicInteger; 6 | 7 | import org.directmemory.measures.Ram; 8 | import org.directmemory.memory.MemoryManager; 9 | import org.directmemory.memory.OffHeapMemoryBuffer; 10 | import org.directmemory.memory.Pointer; 11 | import org.junit.AfterClass; 12 | import org.junit.BeforeClass; 13 | import org.junit.Rule; 14 | import org.junit.Test; 15 | import org.junit.rules.MethodRule; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | import com.carrotsearch.junitbenchmarks.BenchmarkOptions; 20 | import com.carrotsearch.junitbenchmarks.BenchmarkRule; 21 | import com.carrotsearch.junitbenchmarks.annotation.AxisRange; 22 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkHistoryChart; 23 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart; 24 | import com.carrotsearch.junitbenchmarks.annotation.LabelType; 25 | import com.google.common.collect.MapMaker; 26 | 27 | @AxisRange(min = 0, max = 1) 28 | @BenchmarkMethodChart() 29 | @BenchmarkHistoryChart(labelWith = LabelType.CUSTOM_KEY, maxRuns = 5) 30 | 31 | public class ConcurrentTests2 { 32 | 33 | private final static int entries = 100000; 34 | public static AtomicInteger count = new AtomicInteger(); 35 | private static AtomicInteger got = new AtomicInteger(); 36 | private static AtomicInteger missed = new AtomicInteger(); 37 | private static AtomicInteger good = new AtomicInteger(); 38 | private static AtomicInteger bad = new AtomicInteger(); 39 | private static AtomicInteger read = new AtomicInteger(); 40 | 41 | public static ConcurrentMap map = new MapMaker() 42 | .concurrencyLevel(4) 43 | .initialCapacity(100000) 44 | .makeMap(); 45 | 46 | 47 | @BenchmarkOptions(benchmarkRounds = 100000, warmupRounds=0, concurrency=100) 48 | @Test 49 | public void store() { 50 | final String key = "test-" + count.incrementAndGet(); 51 | put(key); 52 | } 53 | 54 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=100) 55 | @Test 56 | public void retrieveCatchThemAll() { 57 | String key = "test-" + (rndGen.nextInt(entries)+1); 58 | Pointer p = map.get(key); 59 | read.incrementAndGet(); 60 | if (p != null) { 61 | got.incrementAndGet(); 62 | byte [] payload = MemoryManager.retrieve(p); 63 | if (key.equals(new String(payload))) 64 | good.incrementAndGet(); 65 | else 66 | bad.incrementAndGet(); 67 | } else { 68 | logger.info("did not find key " + key); 69 | missed.incrementAndGet(); 70 | } 71 | } 72 | 73 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=100) 74 | @Test 75 | public void retrieveCatchHalfOfThem() { 76 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 77 | Pointer p = map.get(key); 78 | read.incrementAndGet(); 79 | if (p != null) { 80 | got.incrementAndGet(); 81 | byte [] payload = MemoryManager.retrieve(p); 82 | if (key.equals(new String(payload))) 83 | good.incrementAndGet(); 84 | else 85 | bad.incrementAndGet(); 86 | } else { 87 | missed.incrementAndGet(); 88 | } 89 | } 90 | 91 | private void put(String key) { 92 | map.put(key, MemoryManager.store(key.getBytes())); 93 | } 94 | 95 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=10) 96 | @Test 97 | public void write3Read7() { 98 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 99 | 100 | int what = rndGen.nextInt(10); 101 | 102 | switch (what) { 103 | case 0: 104 | case 1: 105 | case 2: 106 | put(key); 107 | break; 108 | default: 109 | get(key); 110 | break; 111 | 112 | } 113 | 114 | } 115 | 116 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=10) 117 | @Test 118 | public void write1Read9() { 119 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 120 | 121 | int what = rndGen.nextInt(10); 122 | 123 | switch (what) { 124 | case 0: 125 | put(key); 126 | break; 127 | default: 128 | get(key); 129 | break; 130 | 131 | } 132 | 133 | } 134 | private void get(String key) { 135 | Pointer p = map.get(key); 136 | read.incrementAndGet(); 137 | if (p != null) { 138 | got.incrementAndGet(); 139 | byte [] payload = MemoryManager.retrieve(p); 140 | if (key.equals(new String(payload))) 141 | good.incrementAndGet(); 142 | else 143 | bad.incrementAndGet(); 144 | } else { 145 | missed.incrementAndGet(); 146 | } 147 | } 148 | 149 | Random rndGen = new Random(); 150 | 151 | @Rule 152 | public MethodRule benchmarkRun = new BenchmarkRule(); 153 | 154 | 155 | private static Logger logger = LoggerFactory.getLogger(ConcurrentTests2.class); 156 | 157 | private static void dump(OffHeapMemoryBuffer mem) { 158 | logger.info("off-heap - buffer: " + mem.bufferNumber); 159 | logger.info("off-heap - allocated: " + Ram.inMb(mem.capacity())); 160 | logger.info("off-heap - used: " + Ram.inMb(mem.used())); 161 | logger.info("heap - max: " + Ram.inMb(Runtime.getRuntime().maxMemory())); 162 | logger.info("heap - allocated: " + Ram.inMb(Runtime.getRuntime().totalMemory())); 163 | logger.info("heap - free : " + Ram.inMb(Runtime.getRuntime().freeMemory())); 164 | logger.info("************************************************"); 165 | } 166 | 167 | @BeforeClass 168 | public static void init() { 169 | MemoryManager.init(1, Ram.Mb(512)); 170 | } 171 | 172 | @AfterClass 173 | public static void dump() { 174 | 175 | for (OffHeapMemoryBuffer mem : MemoryManager.buffers) { 176 | dump(mem); 177 | } 178 | 179 | logger.info("************************************************"); 180 | logger.info("entries: " + entries); 181 | logger.info("inserted: " + map.size()); 182 | logger.info("reads: " + read); 183 | logger.info("count: " + count); 184 | logger.info("got: " + got); 185 | logger.info("missed: " + missed); 186 | logger.info("good: " + good); 187 | logger.info("bad: " + bad); 188 | logger.info("************************************************"); 189 | } 190 | 191 | } 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/memory/test/ConcurrentTests3.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.memory.test; 2 | 3 | import java.util.Random; 4 | import java.util.concurrent.ConcurrentMap; 5 | import java.util.concurrent.atomic.AtomicInteger; 6 | 7 | import org.directmemory.measures.Ram; 8 | import org.directmemory.memory.MemoryManager; 9 | import org.directmemory.memory.OffHeapMemoryBuffer; 10 | import org.directmemory.memory.Pointer; 11 | import org.junit.AfterClass; 12 | import org.junit.BeforeClass; 13 | import org.junit.Rule; 14 | import org.junit.Test; 15 | import org.junit.rules.MethodRule; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | import com.carrotsearch.junitbenchmarks.BenchmarkOptions; 20 | import com.carrotsearch.junitbenchmarks.BenchmarkRule; 21 | import com.carrotsearch.junitbenchmarks.annotation.AxisRange; 22 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkHistoryChart; 23 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart; 24 | import com.carrotsearch.junitbenchmarks.annotation.LabelType; 25 | import com.google.common.collect.MapMaker; 26 | 27 | @AxisRange(min = 0, max = 1) 28 | @BenchmarkMethodChart() 29 | @BenchmarkHistoryChart(labelWith = LabelType.CUSTOM_KEY, maxRuns = 5) 30 | 31 | public class ConcurrentTests3 { 32 | 33 | private final static int entries = 100000; 34 | public static AtomicInteger count = new AtomicInteger(); 35 | private static AtomicInteger got = new AtomicInteger(); 36 | private static AtomicInteger missed = new AtomicInteger(); 37 | private static AtomicInteger good = new AtomicInteger(); 38 | private static AtomicInteger bad = new AtomicInteger(); 39 | private static AtomicInteger read = new AtomicInteger(); 40 | private static AtomicInteger disposals = new AtomicInteger(); 41 | 42 | public static ConcurrentMap map = new MapMaker() 43 | .concurrencyLevel(4) 44 | .initialCapacity(100000) 45 | .makeMap(); 46 | 47 | 48 | @BenchmarkOptions(benchmarkRounds = 100000, warmupRounds=0, concurrency=100) 49 | @Test 50 | public void store() { 51 | final String key = "test-" + count.incrementAndGet(); 52 | put(key); 53 | } 54 | 55 | @BenchmarkOptions(benchmarkRounds = 500, warmupRounds=0, concurrency=10) 56 | @Test 57 | public void storeSomeWithExpiry() { 58 | final String key = "test-" + count.incrementAndGet(); 59 | putWithExpiry(key); 60 | } 61 | 62 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=100) 63 | @Test 64 | public void retrieveCatchThemAll() { 65 | String key = "test-" + (rndGen.nextInt(entries)+1); 66 | get(key); 67 | } 68 | 69 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=100) 70 | @Test 71 | public void retrieveCatchHalfOfThem() { 72 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 73 | get(key); 74 | } 75 | 76 | private void get(String key) { 77 | Pointer p = map.get(key); 78 | read.incrementAndGet(); 79 | if (p != null) { 80 | got.incrementAndGet(); 81 | byte [] payload = MemoryManager.retrieve(p); 82 | if ((new String(payload)).startsWith(key)) 83 | good.incrementAndGet(); 84 | else 85 | bad.incrementAndGet(); 86 | } else { 87 | missed.incrementAndGet(); 88 | } 89 | } 90 | 91 | private void put(String key) { 92 | final StringBuilder bldr = new StringBuilder(); 93 | for (int i = 0; i < 100; i++) { 94 | bldr.append(key); 95 | } 96 | map.put(key, MemoryManager.store(bldr.toString().getBytes())); 97 | } 98 | 99 | private void putWithExpiry(String key) { 100 | final StringBuilder bldr = new StringBuilder(); 101 | for (int i = 0; i < 100; i++) { 102 | bldr.append(key); 103 | } 104 | map.put(key, MemoryManager.store(bldr.toString().getBytes(), rndGen.nextInt(2000))); 105 | } 106 | 107 | 108 | @BenchmarkOptions(benchmarkRounds = 50000, warmupRounds=0, concurrency=10) 109 | @Test 110 | public void write1Read8AndSomeDisposal() { 111 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 112 | 113 | int what = rndGen.nextInt(10); 114 | 115 | switch (what) { 116 | case 0: 117 | put(key); 118 | break; 119 | case 1: 120 | case 2: 121 | case 3: 122 | case 4: 123 | case 5: 124 | case 6: 125 | case 7: 126 | case 8: 127 | get(key); 128 | break; 129 | default: 130 | final int rndVal = rndGen.nextInt(1000); 131 | if ( rndVal > 995) { 132 | disposals.incrementAndGet(); 133 | final long start = System.currentTimeMillis(); 134 | long howMany = MemoryManager.collectExpired(); 135 | final long end = System.currentTimeMillis(); 136 | logger.info("" + howMany + " disposed in " + (end-start) + " milliseconds"); 137 | } 138 | } 139 | 140 | } 141 | 142 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=10) 143 | @Test 144 | public void write3Read7() { 145 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 146 | 147 | int what = rndGen.nextInt(10); 148 | 149 | switch (what) { 150 | case 0: 151 | case 1: 152 | case 2: 153 | put(key); 154 | break; 155 | default: 156 | get(key); 157 | break; 158 | } 159 | } 160 | 161 | @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds=0, concurrency=10) 162 | @Test 163 | public void write1Read9() { 164 | String key = "test-" + (rndGen.nextInt(entries*2)+1); 165 | 166 | int what = rndGen.nextInt(10); 167 | 168 | switch (what) { 169 | case 0: 170 | put(key); 171 | break; 172 | default: 173 | get(key); 174 | break; 175 | 176 | } 177 | 178 | } 179 | 180 | Random rndGen = new Random(); 181 | 182 | @Rule 183 | public MethodRule benchmarkRun = new BenchmarkRule(); 184 | 185 | 186 | private static Logger logger = LoggerFactory.getLogger(ConcurrentTests3.class); 187 | 188 | private static void dump(OffHeapMemoryBuffer mem) { 189 | logger.info("off-heap - buffer: " + mem.bufferNumber); 190 | logger.info("off-heap - allocated: " + Ram.inMb(mem.capacity())); 191 | logger.info("off-heap - used: " + Ram.inMb(mem.used())); 192 | logger.info("heap - max: " + Ram.inMb(Runtime.getRuntime().maxMemory())); 193 | logger.info("heap - allocated: " + Ram.inMb(Runtime.getRuntime().totalMemory())); 194 | logger.info("heap - free : " + Ram.inMb(Runtime.getRuntime().freeMemory())); 195 | logger.info("************************************************"); 196 | } 197 | 198 | @BeforeClass 199 | public static void init() { 200 | MemoryManager.init(1, Ram.Mb(512)); 201 | } 202 | 203 | @AfterClass 204 | public static void dump() { 205 | 206 | for (OffHeapMemoryBuffer mem : MemoryManager.buffers) { 207 | dump(mem); 208 | } 209 | 210 | logger.info("************************************************"); 211 | logger.info("entries: " + entries); 212 | logger.info("inserted: " + map.size()); 213 | logger.info("reads: " + read); 214 | logger.info("count: " + count); 215 | logger.info("got: " + got); 216 | logger.info("missed: " + missed); 217 | logger.info("good: " + good); 218 | logger.info("bad: " + bad); 219 | logger.info("disposals: " + disposals); 220 | logger.info("************************************************"); 221 | } 222 | 223 | } 224 | 225 | 226 | 227 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/memory/test/MallocTests.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.memory.test; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import java.util.Random; 7 | import java.util.concurrent.ConcurrentMap; 8 | 9 | import org.directmemory.measures.Ram; 10 | import org.directmemory.memory.OffHeapMemoryBuffer; 11 | import org.directmemory.memory.Pointer; 12 | import org.junit.After; 13 | import org.junit.Before; 14 | import org.junit.Rule; 15 | import org.junit.Test; 16 | import org.junit.rules.MethodRule; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | 20 | import com.carrotsearch.junitbenchmarks.BenchmarkOptions; 21 | import com.carrotsearch.junitbenchmarks.BenchmarkRule; 22 | import com.carrotsearch.junitbenchmarks.annotation.AxisRange; 23 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkHistoryChart; 24 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart; 25 | import com.carrotsearch.junitbenchmarks.annotation.LabelType; 26 | import com.google.common.collect.MapMaker; 27 | 28 | @AxisRange(min = 0, max = 1) 29 | @BenchmarkMethodChart() 30 | @BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0) 31 | @BenchmarkHistoryChart(labelWith = LabelType.CUSTOM_KEY, maxRuns = 5) 32 | 33 | public class MallocTests { 34 | 35 | @Rule 36 | public MethodRule benchmarkRun = new BenchmarkRule(); 37 | 38 | Random rnd = new Random(); 39 | 40 | private static Logger logger = LoggerFactory.getLogger(MallocTests.class); 41 | 42 | @After 43 | public void dump() { 44 | logger.info("off-heap allocated: " + Ram.inMb(mem.capacity())); 45 | logger.info("off-heap used: " + Ram.inMb(mem.used())); 46 | logger.info("heap - max: " + Ram.inMb(Runtime.getRuntime().maxMemory())); 47 | logger.info("heap - allocated: " + Ram.inMb(Runtime.getRuntime().totalMemory())); 48 | logger.info("heap - free : " + Ram.inMb(Runtime.getRuntime().freeMemory())); 49 | logger.info("************************************************"); 50 | } 51 | 52 | OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(512 * 1024 * 1024); 53 | 54 | @Test 55 | public void oneMillionEntries() { 56 | assertNotNull(mem); 57 | int howMany = 1000000; 58 | int size = mem.capacity() / (howMany); 59 | size -= size / 100 * 1; 60 | logger.info("payload size=" + size); 61 | logger.info("entries=" + howMany); 62 | 63 | logger.info("starting..."); 64 | 65 | long start = System.currentTimeMillis(); 66 | 67 | byte[] payload = new byte[size]; 68 | for (int i = 0; i < howMany; i++) { 69 | mem.store(payload); 70 | } 71 | 72 | logger.info("...done in " + (System.currentTimeMillis() - start) + " msecs."); 73 | } 74 | 75 | @Test 76 | public void twoMillionEntries() { 77 | 78 | assertNotNull(mem); 79 | int howMany = 2000000; 80 | int size = mem.capacity() / (howMany); 81 | size -= size / 100 * 1; 82 | logger.info("payload size=" + size); 83 | logger.info("entries=" + howMany); 84 | 85 | logger.info("starting..."); 86 | long start = System.currentTimeMillis(); 87 | 88 | byte[] payload = new byte[size]; 89 | for (int i = 0; i < howMany; i++) { 90 | mem.store(payload); 91 | } 92 | 93 | logger.info("...done in " + (System.currentTimeMillis() - start) + " msecs."); 94 | } 95 | 96 | @Test 97 | public void fiveMillionEntries() { 98 | 99 | assertNotNull(mem); 100 | int howMany = 5000000; 101 | int size = mem.capacity() / (howMany); 102 | size -= size / 100 * 1; 103 | logger.info("payload size=" + size); 104 | logger.info("entries=" + howMany); 105 | 106 | logger.info("starting..."); 107 | long start = System.currentTimeMillis(); 108 | 109 | byte[] payload = new byte[size]; 110 | for (int i = 0; i < howMany; i++) { 111 | mem.store(payload); 112 | } 113 | 114 | logger.info("...done in " + (System.currentTimeMillis() - start) + " msecs."); 115 | } 116 | 117 | 118 | @Test 119 | public void withMap() { 120 | 121 | ConcurrentMap map = new MapMaker() 122 | .concurrencyLevel(4) 123 | .initialCapacity(500000) 124 | .makeMap(); 125 | 126 | String str = "This is the string to store into the off-heap memory"; 127 | 128 | int size = str.length(); 129 | int howMany = 1000000; 130 | byte[] payload = str.getBytes(); 131 | 132 | logger.info("adding " + howMany + " strings of " + size + " bytes..."); 133 | for (long i = 0; i < howMany; i++) { 134 | Pointer p = mem.store(payload); 135 | map.put(i, p); 136 | } 137 | logger.info("...done"); 138 | 139 | } 140 | 141 | @Before 142 | public void before(){ 143 | mem.clear(); 144 | } 145 | 146 | 147 | 148 | 149 | @Test 150 | public void oneMillionEntriesWithRead() { 151 | 152 | logger.info("total capacity=" + Ram.inMb(mem.capacity())); 153 | assertNotNull(mem); 154 | int size = 400; 155 | int howMany = 1000000; 156 | logger.info("payload size=" + Ram.inKb(size)); 157 | logger.info("entries=" + howMany); 158 | String test = "this is a nicely crafted test"; 159 | byte[] payload = test.getBytes(); 160 | for (int i = 0; i < howMany; i++) { 161 | Pointer p = mem.store(payload); 162 | byte[] check = mem.retrieve(p); 163 | assertNotNull(check); 164 | assertEquals(test, new String(check)); 165 | } 166 | 167 | logger.info("total used=" + Ram.inMb(mem.used())); 168 | } 169 | } 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/memory/test/MemoryManagerTests.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.memory.test; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import java.util.Map; 7 | import java.util.Random; 8 | 9 | import org.directmemory.measures.Ram; 10 | import org.directmemory.memory.MemoryManager; 11 | import org.directmemory.memory.OffHeapMemoryBuffer; 12 | import org.directmemory.memory.Pointer; 13 | import org.junit.BeforeClass; 14 | import org.junit.Test; 15 | import org.junit.rules.MethodRule; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | import com.carrotsearch.junitbenchmarks.BenchmarkRule; 20 | import com.google.common.collect.Maps; 21 | 22 | public class MemoryManagerTests { 23 | // @Rule 24 | public MethodRule benchmarkRun = new BenchmarkRule(); 25 | 26 | 27 | @BeforeClass 28 | public static void init() { 29 | logger.info("init"); 30 | MemoryManager.init(1, Ram.Mb(100)); 31 | } 32 | 33 | @Test 34 | public void smokeTest() { 35 | Random rnd = new Random(); 36 | int size = rnd.nextInt(10) * (int)MemoryManager.capacity() / 100; 37 | logger.info("payload size=" + Ram.inKb(size)); 38 | Pointer p = MemoryManager.store(new byte[size]); 39 | logger.info("stored"); 40 | assertNotNull(p); 41 | assertEquals(size,p.end); 42 | assertEquals(size, MemoryManager.activeBuffer.used()); 43 | MemoryManager.free(p); 44 | assertEquals(0, MemoryManager.activeBuffer.used()); 45 | logger.info("end"); 46 | } 47 | 48 | byte[] payload = "012345678901234567890123456789012345678901234567890123456789".getBytes(); 49 | 50 | @Test 51 | public void fillupTest() { 52 | MemoryManager.clear(); 53 | logger.info("payload size=" + Ram.inKb(payload.length)); 54 | long howMany = (MemoryManager.capacity() / payload.length); 55 | howMany=(howMany*90)/100; 56 | 57 | 58 | for (int i = 0; i < howMany ; i++) { 59 | Pointer p = MemoryManager.store(payload); 60 | assertNotNull(p); 61 | } 62 | 63 | logger.info("" + howMany + " items stored"); 64 | } 65 | 66 | 67 | @Test 68 | public void readTest() { 69 | for (OffHeapMemoryBuffer buffer : MemoryManager.buffers) { 70 | for (Pointer ptr : buffer.pointers) { 71 | if (!ptr.free) { 72 | byte[] res = MemoryManager.retrieve(ptr); 73 | assertNotNull(res); 74 | assertEquals(new String(payload), new String(res)); 75 | } 76 | } 77 | } 78 | } 79 | 80 | 81 | private static Logger logger = LoggerFactory.getLogger(MallocTests.class); 82 | 83 | final static Map test = Maps.newHashMap(); 84 | 85 | } 86 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/memory/test/Starter.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.memory.test; 2 | 3 | import static org.junit.Assert.assertNotNull; 4 | 5 | import org.directmemory.measures.Ram; 6 | import org.directmemory.memory.MemoryManager; 7 | import org.directmemory.memory.OffHeapMemoryBuffer; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | public class Starter { 12 | 13 | private static Logger logger = LoggerFactory.getLogger(MallocTests.class); 14 | 15 | /** 16 | * @param args 17 | */ 18 | public static void main(String[] args) { 19 | 20 | if (args.length < 3) { 21 | System.out.println("DirectMemory (for real testers only!) - usage:"); 22 | System.out.println(" java -XX:MaxDirectMemorySize=XXXXm -XmxXXXXm -XmsXXXXm -jar dm-test.jar "); 23 | return; 24 | } 25 | 26 | int buffers = new Integer(args[0]); 27 | int mb = new Integer(args[1]); 28 | int entries = new Integer(args[2]); 29 | 30 | logger.info("buffers: " + buffers); 31 | logger.info("mb: " + mb); 32 | logger.info("entries: " + entries); 33 | 34 | Starter starter = new Starter(); 35 | starter.rawInsertMultipleBuffers(buffers, mb, entries); 36 | } 37 | 38 | public void dump(OffHeapMemoryBuffer mem) { 39 | logger.info("off-heap - buffer: " + mem.pointers.get(1).bufferNumber); 40 | logger.info("off-heap - allocated: " + Ram.inMb(mem.capacity())); 41 | logger.info("off-heap - used: " + Ram.inMb(mem.used())); 42 | logger.info("heap - max: " + Ram.inMb(Runtime.getRuntime().maxMemory())); 43 | logger.info("heap - allocated: " + Ram.inMb(Runtime.getRuntime().totalMemory())); 44 | logger.info("heap - free : " + Ram.inMb(Runtime.getRuntime().freeMemory())); 45 | logger.info("************************************************"); 46 | } 47 | 48 | public void rawInsert(int megabytes, int howMany) { 49 | OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(megabytes * 1024 * 1024); 50 | assertNotNull(mem); 51 | int size = mem.capacity() / (howMany); 52 | size -= size / 100 * 1; 53 | logger.info("payload size=" + size); 54 | logger.info("entries=" + howMany); 55 | 56 | logger.info("starting..."); 57 | 58 | long start = System.currentTimeMillis(); 59 | 60 | byte[] payload = new byte[size]; 61 | for (int i = 0; i < howMany; i++) { 62 | mem.store(payload); 63 | } 64 | 65 | logger.info("...done in " + (System.currentTimeMillis() - start) + " msecs."); 66 | logger.info("---------------------------------"); 67 | dump(mem); 68 | } 69 | 70 | 71 | public void rawInsertMultipleBuffers(int buffers, int megabytes, int howMany) { 72 | MemoryManager.init(buffers, Ram.Mb(megabytes)); 73 | int size = (int)(MemoryManager.capacity() / (howMany)); 74 | size -= size / 100 * 1; 75 | logger.info("payload size=" + size); 76 | logger.info("entries=" + howMany); 77 | 78 | logger.info("starting..."); 79 | 80 | long start = System.currentTimeMillis(); 81 | 82 | byte[] payload = new byte[size]; 83 | for (int i = 0; i < howMany; i++) { 84 | MemoryManager.store(payload); 85 | } 86 | 87 | logger.info("...done in " + (System.currentTimeMillis() - start) + " msecs."); 88 | logger.info("---------------------------------"); 89 | 90 | for (OffHeapMemoryBuffer buf : MemoryManager.buffers) { 91 | dump(buf); 92 | } 93 | } 94 | 95 | 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/preliminary/test/MicroBenchmarks.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.preliminary.test; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.util.Map; 5 | import java.util.concurrent.ConcurrentMap; 6 | 7 | import org.directmemory.measures.Ram; 8 | import org.junit.Before; 9 | import org.junit.Rule; 10 | import org.junit.Test; 11 | import org.junit.rules.MethodRule; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import com.carrotsearch.junitbenchmarks.BenchmarkOptions; 16 | import com.carrotsearch.junitbenchmarks.BenchmarkRule; 17 | import com.carrotsearch.junitbenchmarks.annotation.AxisRange; 18 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkHistoryChart; 19 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart; 20 | import com.carrotsearch.junitbenchmarks.annotation.LabelType; 21 | import com.google.common.collect.MapMaker; 22 | import com.google.common.collect.Maps; 23 | 24 | @AxisRange(min = 0, max = 1) 25 | @BenchmarkMethodChart(filePrefix = "latest-microbench") 26 | @BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0) 27 | @BenchmarkHistoryChart(labelWith = LabelType.CUSTOM_KEY, maxRuns = 5) 28 | 29 | public class MicroBenchmarks { 30 | 31 | @Rule 32 | public MethodRule benchmarkRun = new BenchmarkRule(); 33 | 34 | 35 | 36 | private static Logger logger = LoggerFactory.getLogger(MicroBenchmarks.class); 37 | 38 | 39 | private int many = 3000000; 40 | private int less = 300000; 41 | 42 | @Before 43 | public void cleanup() { 44 | dump("Before cleanup"); 45 | //Runtime.getRuntime().gc(); 46 | //dump("After cleanup"); 47 | logger.info("************************************************"); 48 | } 49 | 50 | private void dump(String message) { 51 | logger.info(message); 52 | logger.info("Memory - max: " + Ram.inMb(Runtime.getRuntime().maxMemory())); 53 | logger.info("Memory - allocated: " + Ram.inMb(Runtime.getRuntime().totalMemory())); 54 | logger.info("Memory - free : " + Ram.inMb(Runtime.getRuntime().freeMemory())); 55 | } 56 | 57 | @Test 58 | public void manySmallInHeapWithHashmap() { 59 | final Map test = Maps.newHashMap(); 60 | final byte payload[] = new byte[450]; 61 | long ops = many; 62 | for (int i = 0; i < ops; i++) { 63 | final String key = "test-"+i; 64 | test.put(key, payload.clone()); 65 | } 66 | logger.info("many=" + ops); 67 | logger.info("payload.length=" + payload.length); 68 | logger.info("stored " + Ram.inMb(payload.length * ops)); 69 | } 70 | 71 | 72 | 73 | @Test 74 | public void manySmallInHeapWithMapMaker() { 75 | final byte payload[] = new byte[450]; 76 | int ops = many; 77 | 78 | logger.info("many=" + ops); 79 | logger.info("payload.length=" + payload.length); 80 | pumpTheHeap(ops, payload); 81 | 82 | } 83 | 84 | @Test 85 | public void manySmallOffHeap() { 86 | 87 | final byte payload[] = new byte[450]; 88 | int ops = many; 89 | 90 | logger.info("many=" + ops); 91 | logger.info("payload.length=" + payload.length); 92 | pumpOffHeap(ops, payload); 93 | 94 | } 95 | 96 | 97 | @Test 98 | public void lessButLargerOffHeap() { 99 | 100 | final byte payload[] = new byte[5120]; 101 | int ops = less; 102 | 103 | logger.info("less=" + ops); 104 | logger.info("payload.length=" + payload.length); 105 | pumpOffHeap(ops, payload); 106 | 107 | } 108 | 109 | @Test 110 | public void lessButLargerInHeap() { 111 | 112 | final byte payload[] = new byte[5120]; 113 | int ops = less; 114 | 115 | logger.info("less=" + ops); 116 | logger.info("payload.length=" + payload.length); 117 | pumpTheHeap(ops, payload); 118 | 119 | } 120 | 121 | /* 122 | * 123 | * 124 | * ExecutorService executor = Executors.newCachedThreadPool(); 125 | Callable task = new Callable() { 126 | public Object call() { 127 | return something.blockingMethod(); 128 | } 129 | } 130 | Future future = executor.submit(task); 131 | try { 132 | Object result = future.get(5, TimeUnit.SECONDS); 133 | } catch (TimeoutException ex) { 134 | // handle the timeout 135 | } finally { 136 | future.cancel(); // may or may not desire this 137 | } 138 | */ 139 | 140 | 141 | private void pumpOffHeap(int ops, byte[] payload) { 142 | 143 | ConcurrentMap test = new MapMaker() 144 | .concurrencyLevel(4) 145 | .makeMap(); 146 | 147 | logger.info(Ram.inMb(ops*payload.length) + " in " + ops + " slices to store"); 148 | 149 | ByteBuffer bulk = ByteBuffer.allocateDirect(ops * payload.length); 150 | 151 | double started = System.currentTimeMillis(); 152 | 153 | for (int i = 0; i < ops; i++) { 154 | bulk.position(i*payload.length); 155 | final ByteBuffer buf = bulk.duplicate(); 156 | buf.put(payload); 157 | test.put("test-"+i, buf); 158 | } 159 | 160 | double finished = System.currentTimeMillis(); 161 | 162 | logger.info("done in " + (finished-started)/1000 + " seconds"); 163 | 164 | for (ByteBuffer buf : test.values()) { 165 | buf.clear(); 166 | } 167 | } 168 | 169 | private void pumpTheHeap(int ops, byte[] payload) { 170 | 171 | ConcurrentMap test = new MapMaker() 172 | .concurrencyLevel(4) 173 | .makeMap(); 174 | 175 | logger.info(Ram.inMb(ops*payload.length) + " in " + ops + " slices to store"); 176 | 177 | double started = System.currentTimeMillis(); 178 | 179 | for (int i = 0; i < ops; i++) { 180 | test.put("test-"+i, payload.clone()); 181 | } 182 | 183 | double finished = System.currentTimeMillis(); 184 | 185 | logger.info("done in " + (finished-started)/1000 + " seconds"); 186 | } 187 | 188 | 189 | } 190 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/preliminary/test/PreliminarBenchmarks.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.preliminary.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.nio.ByteBuffer; 6 | import java.util.Map; 7 | import java.util.concurrent.ConcurrentMap; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | import org.directmemory.measures.Ram; 11 | import org.junit.Test; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import com.carrotsearch.junitbenchmarks.AbstractBenchmark; 16 | import com.carrotsearch.junitbenchmarks.BenchmarkOptions; 17 | import com.google.common.collect.MapMaker; 18 | import com.google.common.collect.Maps; 19 | 20 | public class PreliminarBenchmarks extends AbstractBenchmark { 21 | 22 | private static Logger logger = LoggerFactory.getLogger(PreliminarBenchmarks.class); 23 | final static byte payload[] = new byte[1024]; 24 | 25 | // @Before 26 | // @After 27 | public void cleanup() { 28 | dump("Before cleanup"); 29 | Runtime.getRuntime().gc(); 30 | dump("After cleanup"); 31 | logger.info("************************************************"); 32 | } 33 | 34 | private void dump(String message) { 35 | logger.info(message); 36 | logger.info("Memory - max: " + Ram.inMb(Runtime.getRuntime().maxMemory())); 37 | logger.info("Memory - allocated: " + Ram.inMb(Runtime.getRuntime().totalMemory())); 38 | logger.info("Memory - free : " + Ram.inMb(Runtime.getRuntime().freeMemory())); 39 | } 40 | 41 | @BenchmarkOptions(benchmarkRounds = 5, warmupRounds = 0) 42 | @Test 43 | public void justMap() { 44 | final Map test = Maps.newHashMap(); 45 | long ops = 100000; 46 | for (int i = 0; i < ops; i++) { 47 | final String key = "test-"+i; 48 | test.put(key, payload.clone()); 49 | } 50 | logger.info("stored " + Ram.inMb(payload.length * ops)); 51 | } 52 | 53 | @BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0) 54 | @Test 55 | public void oneMillionSmallWithDirectBuffersOneAllocation() { 56 | 57 | logger.info("payload is " + payload.length + " bytes"); 58 | final byte payload[] = new byte[500]; 59 | int ops = 1000000; 60 | 61 | pumpWithOneAllocation(ops, payload); 62 | 63 | } 64 | 65 | @BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0) 66 | @Test 67 | public void lessButLargerWithDirectBuffersOneAllocation() { 68 | 69 | logger.info("payload is " + payload.length + " bytes"); 70 | final byte payload[] = new byte[2048]; 71 | int ops = 210000; 72 | 73 | pumpWithOneAllocation(ops, payload); 74 | 75 | } 76 | 77 | 78 | /* 79 | * 80 | * 81 | * ExecutorService executor = Executors.newCachedThreadPool(); 82 | Callable task = new Callable() { 83 | public Object call() { 84 | return something.blockingMethod(); 85 | } 86 | } 87 | Future future = executor.submit(task); 88 | try { 89 | Object result = future.get(5, TimeUnit.SECONDS); 90 | } catch (TimeoutException ex) { 91 | // handle the timeout 92 | } finally { 93 | future.cancel(); // may or may not desire this 94 | } 95 | */ 96 | 97 | @BenchmarkOptions(benchmarkRounds = 5, warmupRounds = 0) 98 | @Test 99 | public void withDirectBuffers150k() { 100 | 101 | logger.info("payload is " + payload.length + " bytes"); 102 | int ops = 150000; 103 | 104 | pump(ops); 105 | } 106 | 107 | @BenchmarkOptions(benchmarkRounds = 5, warmupRounds = 0) 108 | @Test 109 | public void withDirectBuffers180k() { 110 | 111 | logger.info("payload is " + payload.length + " bytes"); 112 | int ops = 180000; 113 | 114 | pump(ops); 115 | } 116 | 117 | @BenchmarkOptions(benchmarkRounds = 5, warmupRounds = 0) 118 | @Test 119 | public void withDirectBuffers150kAgain() { 120 | 121 | logger.info("payload is " + payload.length + " bytes"); 122 | int ops = 150000; 123 | 124 | pump(ops); 125 | } 126 | 127 | @BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0) 128 | @Test 129 | public void testAllocation() { 130 | 131 | logger.info("payload is " + payload.length + " bytes"); 132 | logger.info("allocating " + Ram.inMb(payload.length * 200000) ); 133 | ByteBuffer buf = ByteBuffer.allocateDirect(payload.length * 200000); 134 | assertNotNull(buf); 135 | logger.info("done"); 136 | } 137 | 138 | 139 | private void pumpWithOneAllocation(int ops, byte[] payload) { 140 | 141 | ConcurrentMap test = new MapMaker() 142 | .concurrencyLevel(4) 143 | .maximumSize(ops) 144 | .expireAfterWrite(10, TimeUnit.MINUTES) 145 | .makeMap(); 146 | 147 | logger.info(Ram.inMb(ops*payload.length) + " in " + ops + " slices to store"); 148 | 149 | ByteBuffer bulk = ByteBuffer.allocateDirect(ops * payload.length); 150 | 151 | double started = System.currentTimeMillis(); 152 | 153 | for (int i = 0; i < ops; i++) { 154 | bulk.position(i*payload.length); 155 | final ByteBuffer buf = bulk.duplicate(); 156 | buf.put(payload); 157 | test.put("test-"+i, buf); 158 | } 159 | 160 | double finished = System.currentTimeMillis(); 161 | 162 | logger.info("done in " + (finished-started)/1000 + " seconds"); 163 | 164 | for (ByteBuffer buf : test.values()) { 165 | buf.clear(); 166 | } 167 | } 168 | 169 | @BenchmarkOptions(benchmarkRounds = 5, warmupRounds = 0) 170 | @Test 171 | public void withDirectBuffers100k() { 172 | 173 | logger.info("payload is " + payload.length + " bytes"); 174 | int ops = 100000; 175 | 176 | pump(ops); 177 | } 178 | 179 | private void pump(int ops) { 180 | ConcurrentMap test = new MapMaker() 181 | .concurrencyLevel(4) 182 | .maximumSize(ops) 183 | .expireAfterWrite(10, TimeUnit.MINUTES) 184 | .makeMap(); 185 | 186 | logger.info(Ram.inMb(ops*payload.length) + " to store"); 187 | 188 | double started = System.currentTimeMillis(); 189 | 190 | for (int i = 0; i < ops; i++) { 191 | ByteBuffer buf = ByteBuffer.allocateDirect(payload.length); 192 | buf.put(payload); 193 | test.put("test-"+i, buf); 194 | } 195 | 196 | double finished = System.currentTimeMillis(); 197 | 198 | logger.info("done in " + (finished-started)/1000 + " seconds"); 199 | 200 | for (ByteBuffer buf : test.values()) { 201 | buf.clear(); 202 | } 203 | } 204 | 205 | } 206 | -------------------------------------------------------------------------------- /DirectMemory-Cache/src/test/java/org/directmemory/serialization/test/SerializerTest.java: -------------------------------------------------------------------------------- 1 | package org.directmemory.serialization.test; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import java.io.IOException; 7 | 8 | import org.directmemory.measures.Monitor; 9 | import org.directmemory.measures.Ram; 10 | import org.directmemory.misc.DummyPojo; 11 | import org.directmemory.serialization.ProtoStuffSerializerV1; 12 | import org.directmemory.serialization.ProtoStuffWithLinkedBufferSerializer; 13 | import org.directmemory.serialization.Serializer; 14 | import org.directmemory.serialization.StandardSerializer; 15 | import org.junit.Rule; 16 | import org.junit.Test; 17 | import org.junit.rules.MethodRule; 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import com.carrotsearch.junitbenchmarks.BenchmarkOptions; 22 | import com.carrotsearch.junitbenchmarks.BenchmarkRule; 23 | import com.carrotsearch.junitbenchmarks.annotation.AxisRange; 24 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkHistoryChart; 25 | import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart; 26 | import com.carrotsearch.junitbenchmarks.annotation.LabelType; 27 | 28 | @AxisRange(min = 0, max = 1) 29 | @BenchmarkMethodChart() 30 | @BenchmarkHistoryChart(labelWith = LabelType.CUSTOM_KEY, maxRuns = 5) 31 | @BenchmarkOptions(benchmarkRounds = 2, warmupRounds=1, concurrency=1) 32 | 33 | public class SerializerTest { 34 | 35 | @Rule 36 | public MethodRule benchmarkRun = new BenchmarkRule(); 37 | 38 | private static Logger logger=LoggerFactory.getLogger(SerializerTest.class); 39 | private void testSerializer(String name, Serializer serializer, int size, int howMany) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { 40 | logger.info("begin " + serializer.getClass().toString()); 41 | Monitor stopWatch = Monitor.get("serializer." + name + "." + size + "bytes"); 42 | Monitor stopWatch2 = Monitor.get("deserializer." + name + "." + size + "bytes"); 43 | DummyPojo pojo = new DummyPojo("test", size); 44 | for (int i = 0; i < howMany; i++) { 45 | long split = stopWatch.start(); 46 | final byte[] array = serializer.serialize(pojo, pojo.getClass()); 47 | stopWatch.stop(split); 48 | long split2 = stopWatch2.start(); 49 | DummyPojo check = (DummyPojo) serializer.deserialize(array, pojo.getClass()); 50 | stopWatch2.stop(split2); 51 | assertNotNull("object has not been serialized", check); 52 | assertEquals(pojo.name, check.name); 53 | } 54 | logger.info("end serialize " + serializer.getClass().toString() + "\r\n" + stopWatch.toString()); 55 | logger.info("end deserialize " + serializer.getClass().toString() + "\r\n" + stopWatch2.toString()); 56 | } 57 | 58 | @Test 59 | public void ProtostuffTest() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { 60 | testSerializer("protostuff-old", new ProtoStuffSerializerV1(), Ram.Kb(1), 20000); 61 | testSerializer("protostuff-old", new ProtoStuffSerializerV1(), Ram.Kb(2), 20000); 62 | testSerializer("protostuff-old", new ProtoStuffSerializerV1(), Ram.Kb(3), 20000); 63 | testSerializer("protostuff-old", new ProtoStuffSerializerV1(), Ram.Kb(4), 20000); 64 | } 65 | @Test 66 | public void ProtostuffV2Test() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { 67 | testSerializer("protostuff-new", new ProtoStuffWithLinkedBufferSerializer(), Ram.Kb(1), 20000); 68 | testSerializer("protostuff-new", new ProtoStuffWithLinkedBufferSerializer(), Ram.Kb(2), 20000); 69 | testSerializer("protostuff-new", new ProtoStuffWithLinkedBufferSerializer(), Ram.Kb(3), 20000); 70 | testSerializer("protostuff-new", new ProtoStuffWithLinkedBufferSerializer(), Ram.Kb(4), 20000); 71 | testSerializer("cinquantamila", new ProtoStuffWithLinkedBufferSerializer(), Ram.Kb(3), 50000); 72 | } 73 | @Test 74 | public void StandardTest() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { 75 | testSerializer("java-serialization", new StandardSerializer(), Ram.Kb(1), 20000); 76 | testSerializer("java-serialization", new StandardSerializer(), Ram.Kb(2), 20000); 77 | testSerializer("java-serialization", new StandardSerializer(), Ram.Kb(3), 20000); 78 | testSerializer("java-serialization", new StandardSerializer(), Ram.Kb(4), 20000); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Misc/Artwork/Apache-DirectMemory-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/Apache-DirectMemory-2.png -------------------------------------------------------------------------------- /Misc/Artwork/Apache-DirectMemory-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/Apache-DirectMemory-3.png -------------------------------------------------------------------------------- /Misc/Artwork/Apache-DirectMemory-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/Apache-DirectMemory-4.png -------------------------------------------------------------------------------- /Misc/Artwork/Apache-DirectMemory-logo-medium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/Apache-DirectMemory-logo-medium.png -------------------------------------------------------------------------------- /Misc/Artwork/Apache-DirectMemory-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/Apache-DirectMemory-logo.png -------------------------------------------------------------------------------- /Misc/Artwork/Apache-DirectMemory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/Apache-DirectMemory.png -------------------------------------------------------------------------------- /Misc/Artwork/Benchmark data/Benchmark.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/Benchmark data/Benchmark.xls -------------------------------------------------------------------------------- /Misc/Artwork/Benchmark data/ConcurrentHashMap benchmark.txt: -------------------------------------------------------------------------------- 1 | 2 | ******************************************************* 3 | 21:21:35.656 [main] DEBUG fillAndGet - inserting 1000000 entries 4 | heapSize 757,9Mb heapMaxSize 757,9Mb heapFreeSize 745,3Mb 5 | 21:21:37.390 [main] DEBUG fillAndGet - test single get 6 | 21:21:37.390 [main] DEBUG fillAndGet - finished test single get 7 | 21:21:37.390 [main] DEBUG fillAndGet - inserted 1000000 entries 8 | heapSize 757,9Mb heapMaxSize 757,9Mb heapFreeSize 619,9Mb 9 | 21:21:37.390 [main] DEBUG fillAndGet - test get 10 | 21:21:37.656 [main] DEBUG fillAndGet - 1000000 entries retrieved 11 | 21:21:37.656 [main] DEBUG fillAndGet - clearing and forcing garbage collection 12 | 21:21:37.765 [main] DEBUG fillAndGet - garbage collection ended 13 | 14 | ******************************************************* 15 | 21:21:37.765 [main] DEBUG fillAndGet - inserting 2000000 entries 16 | heapSize 757,9Mb heapMaxSize 757,9Mb heapFreeSize 753,1Mb 17 | 21:21:41.281 [main] DEBUG fillAndGet - test single get 18 | 21:21:41.281 [main] DEBUG fillAndGet - finished test single get 19 | 21:21:41.281 [main] DEBUG fillAndGet - inserted 2000000 entries 20 | heapSize 757,9Mb heapMaxSize 757,9Mb heapFreeSize 482,0Mb 21 | 21:21:41.281 [main] DEBUG fillAndGet - test get 22 | 21:21:41.984 [main] DEBUG fillAndGet - 2000000 entries retrieved 23 | 21:21:41.984 [main] DEBUG fillAndGet - clearing and forcing garbage collection 24 | 21:21:42.109 [main] DEBUG fillAndGet - garbage collection ended 25 | 26 | ******************************************************* 27 | 21:21:42.109 [main] DEBUG fillAndGet - inserting 3000000 entries 28 | heapSize 757,9Mb heapMaxSize 757,9Mb heapFreeSize 753,1Mb 29 | 21:21:47.359 [main] DEBUG fillAndGet - test single get 30 | 21:21:47.359 [main] DEBUG fillAndGet - finished test single get 31 | 21:21:47.359 [main] DEBUG fillAndGet - inserted 3000000 entries 32 | heapSize 757,9Mb heapMaxSize 757,9Mb heapFreeSize 358,0Mb 33 | 21:21:47.359 [main] DEBUG fillAndGet - test get 34 | 21:21:49.609 [main] DEBUG fillAndGet - 3000000 entries retrieved 35 | 21:21:49.609 [main] DEBUG fillAndGet - clearing and forcing garbage collection 36 | 21:21:49.828 [main] DEBUG fillAndGet - garbage collection ended 37 | 38 | ******************************************************* 39 | 21:21:49.828 [main] DEBUG fillAndGet - inserting 4000000 entries 40 | heapSize 757,9Mb heapMaxSize 757,9Mb heapFreeSize 753,1Mb 41 | 21:21:58.468 [main] DEBUG fillAndGet - test single get 42 | 21:21:58.468 [main] DEBUG fillAndGet - finished test single get 43 | 21:21:58.468 [main] DEBUG fillAndGet - inserted 4000000 entries 44 | heapSize 757,9Mb heapMaxSize 757,9Mb heapFreeSize 178,8Mb 45 | 21:21:58.468 [main] DEBUG fillAndGet - test get 46 | 21:22:05.187 [main] DEBUG fillAndGet - 4000000 entries retrieved 47 | 21:22:05.187 [main] DEBUG fillAndGet - clearing and forcing garbage collection 48 | 21:22:05.468 [main] DEBUG fillAndGet - garbage collection ended 49 | 50 | ******************************************************* 51 | 21:22:05.468 [main] DEBUG fillAndGet - inserting 5000000 entries 52 | heapSize 757,9Mb heapMaxSize 757,9Mb heapFreeSize 712,1Mb 53 | 21:22:18.250 [main] DEBUG fillAndGet - test single get 54 | 21:22:18.250 [main] DEBUG fillAndGet - finished test single get 55 | 21:22:18.250 [main] DEBUG fillAndGet - inserted 5000000 entries 56 | heapSize 757,9Mb heapMaxSize 757,9Mb heapFreeSize 50,0Mb 57 | 21:22:18.250 [main] DEBUG fillAndGet - test get 58 | 21:22:47.828 [main] DEBUG fillAndGet - 5000000 entries retrieved 59 | 21:22:47.828 [main] DEBUG fillAndGet - clearing and forcing garbage collection 60 | 21:22:48.140 [main] DEBUG fillAndGet - garbage collection ended 61 | 62 | 63 | 5.5 seconds to insert 3 million entries and 393mb to store them 64 | only 1 second to retrieve 3 million entries 65 | -------------------------------------------------------------------------------- /Misc/Artwork/Benchmark data/Serialization comparison 2.txt: -------------------------------------------------------------------------------- 1 | 2 | protostuff 3 | -------------------------------------------------- 4 | Starting test 10000 entries 5 | HeapStore: entries 0/100 with a 15,5Mb/247,5Mb heap usage 6 | SimpleOffHeapStore: entries 0/-1 with a 0,0Mb off-heap usage 7 | put 10000 entries in 891 milliseconds 8 | HeapStore: entries 100/100 with a 15,5Mb/247,5Mb heap usage 9 | SimpleOffHeapStore: entries 9900/-1 with a 29,1Mb off-heap usage 10 | HeapStore: entries 100/100 with a 15,6Mb/247,5Mb heap usage 11 | SimpleOffHeapStore: entries 9900/-1 with a 58,6Mb off-heap usage 12 | got 10000 entries in 765 milliseconds 13 | 14 | Starting test 50000 entries 15 | HeapStore: entries 0/500 with a 15,5Mb/247,5Mb heap usage 16 | SimpleOffHeapStore: entries 0/-1 with a 0,0Mb off-heap usage 17 | put 50000 entries in 4875 milliseconds 18 | HeapStore: entries 500/500 with a 45,1Mb/247,5Mb heap usage 19 | SimpleOffHeapStore: entries 49500/-1 with a 145,7Mb off-heap usage 20 | HeapStore: entries 500/500 with a 56,6Mb/247,5Mb heap usage 21 | SimpleOffHeapStore: entries 49500/-1 with a 293,0Mb off-heap usage 22 | got 50000 entries in 3969 milliseconds 23 | 24 | Starting test 100000 entries 25 | HeapStore: entries 0/1000 with a 15,5Mb/247,5Mb heap usage 26 | SimpleOffHeapStore: entries 0/-1 with a 0,0Mb off-heap usage 27 | put 100000 entries in 9547 milliseconds 28 | HeapStore: entries 1000/1000 with a 87,9Mb/247,5Mb heap usage 29 | SimpleOffHeapStore: entries 99000/-1 with a 291,4Mb off-heap usage 30 | HeapStore: entries 1000/1000 with a 112,8Mb/247,5Mb heap usage 31 | SimpleOffHeapStore: entries 99000/-1 with a 586,1Mb off-heap usage 32 | got 100000 entries in 7500 milliseconds 33 | 34 | java serialization 35 | -------------------------------------------------- 36 | Starting test 10000 entries 37 | HeapStore: entries 0/100 with a 15,5Mb/247,5Mb heap usage 38 | SimpleOffHeapStore: entries 0/-1 with a 0,0Mb off-heap usage 39 | put 10000 entries in 1407 milliseconds 40 | HeapStore: entries 100/100 with a 15,6Mb/247,5Mb heap usage 41 | SimpleOffHeapStore: entries 9900/-1 with a 59,1Mb off-heap usage 42 | HeapStore: entries 100/100 with a 15,6Mb/247,5Mb heap usage 43 | SimpleOffHeapStore: entries 9900/-1 with a 118,8Mb off-heap usage 44 | got 10000 entries in 2156 milliseconds 45 | 46 | Starting test 50000 entries 47 | HeapStore: entries 0/500 with a 15,5Mb/247,5Mb heap usage 48 | SimpleOffHeapStore: entries 0/-1 with a 0,0Mb off-heap usage 49 | put 50000 entries in 7797 milliseconds 50 | HeapStore: entries 500/500 with a 48,0Mb/247,5Mb heap usage 51 | SimpleOffHeapStore: entries 49500/-1 with a 295,4Mb off-heap usage 52 | HeapStore: entries 500/500 with a 54,5Mb/247,5Mb heap usage 53 | SimpleOffHeapStore: entries 49500/-1 with a 594,2Mb off-heap usage 54 | got 50000 entries in 10531 milliseconds 55 | 56 | Starting test 100000 entries 57 | HeapStore: entries 0/1000 with a 15,5Mb/247,5Mb heap usage 58 | SimpleOffHeapStore: entries 0/-1 with a 0,0Mb off-heap usage 59 | put 100000 entries in 17406 milliseconds 60 | HeapStore: entries 1000/1000 with a 102,3Mb/247,5Mb heap usage 61 | SimpleOffHeapStore: entries 99000/-1 with a 590,9Mb off-heap usage 62 | HeapStore: entries 1000/1000 with a 107,2Mb/247,5Mb heap usage 63 | SimpleOffHeapStore: entries 99000/-1 with a 1.188,4Mb off-heap usage 64 | got 100000 entries in 58594 milliseconds -------------------------------------------------------------------------------- /Misc/Artwork/Benchmark data/Serialization comparison.txt: -------------------------------------------------------------------------------- 1 | 2kb buffer old vs new 2 | 3 | Simon Stopwatch: [serializer.protostuff-old.1024bytes INHERIT] total 518 ms, counter 1, max 518 ms, min 518 ms 4 | Simon Stopwatch: [serializer.protostuff-old.2048bytes INHERIT] total 720 ms, counter 1, max 720 ms, min 720 ms 5 | Simon Stopwatch: [serializer.protostuff-old.3072bytes INHERIT] total 1.05 s, counter 1, max 1.05 s, min 1.05 s 6 | Simon Stopwatch: [serializer.protostuff-old.4096bytes INHERIT] total 1.35 s, counter 1, max 1.35 s, min 1.35 s 7 | 8 | Simon Stopwatch: [serializer.protostuff-new.1024bytes INHERIT] total 292 ms, counter 1, max 292 ms, min 292 ms 9 | Simon Stopwatch: [serializer.protostuff-new.2048bytes INHERIT] total 690 ms, counter 1, max 690 ms, min 690 ms 10 | Simon Stopwatch: [serializer.protostuff-new.3072bytes INHERIT] total 1.00 s, counter 1, max 1.00 s, min 1.00 s 11 | Simon Stopwatch: [serializer.protostuff-new.4096bytes INHERIT] total 1.36 s, counter 1, max 1.36 s, min 1.36 s 12 | 13 | 3kb buffer old vs new 14 | 15 | Simon Stopwatch: [serializer.protostuff-old.1024bytes INHERIT] total 523 ms, counter 1, max 523 ms, min 523 ms 16 | Simon Stopwatch: [serializer.protostuff-old.2048bytes INHERIT] total 720 ms, counter 1, max 720 ms, min 720 ms 17 | Simon Stopwatch: [serializer.protostuff-old.3072bytes INHERIT] total 1.01 s, counter 1, max 1.01 s, min 1.01 s 18 | Simon Stopwatch: [serializer.protostuff-old.4096bytes INHERIT] total 1.34 s, counter 1, max 1.34 s, min 1.34 s 19 | 20 | Simon Stopwatch: [serializer.protostuff-new.1024bytes INHERIT] total 295 ms, counter 1, max 295 ms, min 295 ms 21 | Simon Stopwatch: [serializer.protostuff-new.2048bytes INHERIT] total 489 ms, counter 1, max 489 ms, min 489 ms 22 | Simon Stopwatch: [serializer.protostuff-new.3072bytes INHERIT] total 989 ms, counter 1, max 989 ms, min 989 ms 23 | Simon Stopwatch: [serializer.protostuff-new.4096bytes INHERIT] total 1.36 s, counter 1, max 1.36 s, min 1.36 s 24 | 25 | 5kb buffer old vs new 26 | 27 | Simon Stopwatch: [serializer.protostuff-old.1024bytes INHERIT] total 514 ms, counter 1, max 514 ms, min 514 ms 28 | Simon Stopwatch: [serializer.protostuff-old.2048bytes INHERIT] total 712 ms, counter 1, max 712 ms, min 712 ms 29 | Simon Stopwatch: [serializer.protostuff-old.3072bytes INHERIT] total 1.02 s, counter 1, max 1.02 s, min 1.02 s 30 | Simon Stopwatch: [serializer.protostuff-old.4096bytes INHERIT] total 1.37 s, counter 1, max 1.37 s, min 1.37 s 31 | 32 | Simon Stopwatch: [serializer.protostuff-new.1024bytes INHERIT] total 303 ms, counter 1, max 303 ms, min 303 ms 33 | Simon Stopwatch: [serializer.protostuff-new.2048bytes INHERIT] total 505 ms, counter 1, max 505 ms, min 505 ms 34 | Simon Stopwatch: [serializer.protostuff-new.3072bytes INHERIT] total 760 ms, counter 1, max 760 ms, min 760 ms 35 | Simon Stopwatch: [serializer.protostuff-new.4096bytes INHERIT] total 925 ms, counter 1, max 925 ms, min 925 ms 36 | 37 | 38 | Before (300bytes buffer) and after (with 10kb buffer) 39 | 40 | Simon Stopwatch: [serializer.protostuff-old.1024bytes INHERIT] total 532 ms, counter 1, max 532 ms, min 532 ms 41 | Simon Stopwatch: [serializer.protostuff-old.2048bytes INHERIT] total 714 ms, counter 1, max 714 ms, min 714 ms 42 | Simon Stopwatch: [serializer.protostuff-old.3072bytes INHERIT] total 1.08 s, counter 1, max 1.08 s, min 1.08 s 43 | Simon Stopwatch: [serializer.protostuff-old.4096bytes INHERIT] total 1.37 s, counter 1, max 1.37 s, min 1.37 s 44 | 45 | Simon Stopwatch: [serializer.protostuff-new.1024bytes INHERIT] total 296 ms, counter 1, max 296 ms, min 296 ms 46 | Simon Stopwatch: [serializer.protostuff-new.2048bytes INHERIT] total 501 ms, counter 1, max 501 ms, min 501 ms 47 | Simon Stopwatch: [serializer.protostuff-new.3072bytes INHERIT] total 745 ms, counter 1, max 745 ms, min 745 ms 48 | Simon Stopwatch: [serializer.protostuff-new.4096bytes INHERIT] total 953 ms, counter 1, max 953 ms, min 953 ms 49 | 50 | 51 | Standard serialization 52 | 53 | Simon Stopwatch: [serializer.java-serialization.1024bytes INHERIT] total 1.40 s, counter 1, max 1.40 s, min 1.40 s 54 | Simon Stopwatch: [serializer.java-serialization.2048bytes INHERIT] total 1.87 s, counter 1, max 1.87 s, min 1.87 s 55 | Simon Stopwatch: [serializer.java-serialization.3072bytes INHERIT] total 2.67 s, counter 1, max 2.67 s, min 2.67 s 56 | Simon Stopwatch: [serializer.java-serialization.4096bytes INHERIT] total 3.22 s, counter 1, max 3.22 s, min 3.22 s 57 | -------------------------------------------------------------------------------- /Misc/Artwork/Benchmark data/average.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/Benchmark data/average.PNG -------------------------------------------------------------------------------- /Misc/Artwork/Benchmark data/cachemanager2-directmemory.log: -------------------------------------------------------------------------------- 1 | 16:23:46.432 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - Done 2 | 16:27:12.468 [main] INFO org.directmemory.demo.DemoApp.main - DirectMemory Cache - Standalone Demo Starting 3 | 16:27:12.468 [main] INFO org.directmemory.demo.DemoApp.main - Log check - if you see this as INFO it is fine 4 | 16:27:12.468 [main] WARN org.directmemory.demo.DemoApp.main - Log check - if you see this as WARNING it is fine 5 | 16:27:12.468 [main] DEBUG org.directmemory.demo.DemoApp.main - Log check - if you see this as DEBUG it is fine 6 | 16:27:12.468 [main] ERROR org.directmemory.demo.DemoApp.main - Log check - if you see this as ERROR it is fine 7 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - loading file 'C:\Development\DirectMemory\Demo\DirectMemory-StandaloneDemo\target\DirectMemory-Demo\conf\demo.properties' 8 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - loaded file 'conf/demo.properties' 9 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.demoToRun=cachemanager2 10 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.numberOfEntries=100000 11 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.threadCount=10 12 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.entriesInHeap=1000 13 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.entriesOffHeap=-1 14 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.payload=2048 15 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.pstuffBufferSize=3072 16 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.pageSize=5242880 17 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.maxPages=2 18 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.batchSize=1 19 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.logEvery=100 20 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.loadProperties - demo.showStatusEvery=1000 21 | 16:27:12.484 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - Starting test with 100000 entries 22 | 16:27:12.515 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - DirectMemory Cache status: { 23 | uptime: 0ms 24 | stores: { 25 | HeapStore: entries 0/1000 with a 123,8Mb/123,8Mb heap usage and 117,6Mb of free heap 26 | SimpleOffHeapStore: entries 0/-1 with a 0,0Mb off-heap usage 27 | } 28 | } 29 | 16:27:17.499 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - Created, serialized and put 100000 DummyPojos in 4984 milliseconds 30 | 16:27:17.515 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - DirectMemory Cache status: { 31 | uptime: 5000ms 32 | stores: { 33 | HeapStore: entries 1000/1000 with a 123,8Mb/123,8Mb heap usage and 59,8Mb of free heap 34 | SimpleOffHeapStore: entries 99000/-1 with a 194,9Mb off-heap usage 35 | } 36 | } 37 | 16:27:17.515 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - DirectMemory Cache performance: { 38 | put hits: 100000 average time: 0,03ms total time: 3020ms 39 | get hits: 0 average time: n/a total time: 0ms 40 | remove hits: 0 average time: n/a total time: 0ms 41 | } 42 | 16:27:22.484 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - DirectMemory Cache status: { 43 | uptime: 9969ms 44 | stores: { 45 | HeapStore: entries 1000/1000 with a 123,8Mb/123,8Mb heap usage and 42,2Mb of free heap 46 | SimpleOffHeapStore: entries 99000/-1 with a 194,9Mb off-heap usage 47 | } 48 | } 49 | 16:27:22.484 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - DirectMemory Cache performance: { 50 | put hits: 100000 average time: 0,03ms total time: 3020ms 51 | get hits: 100000 average time: 0,05ms total time: 4922ms 52 | remove hits: 0 average time: n/a total time: 0ms 53 | } 54 | 16:27:22.484 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - Got and deserialized 100000 entries in 4985 milliseconds 55 | 16:27:22.484 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - Disposing... 56 | 16:27:22.515 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - DirectMemory Cache status: { 57 | uptime: 10000ms 58 | stores: { 59 | HeapStore: entries 0/1000 with a 123,8Mb/123,8Mb heap usage and 42,2Mb of free heap 60 | SimpleOffHeapStore: entries 0/-1 with a 0,0Mb off-heap usage 61 | } 62 | } 63 | 16:27:22.515 [main] INFO org.directmemory.demo.DemoApp.cacheManager2Test - DirectMemory Cache performance: { 64 | put hits: 100000 average time: 0,03ms total time: 3020ms 65 | get hits: 100000 average time: 0,05ms total time: 4922ms 66 | remove hits: 0 average time: n/a total time: 0ms 67 | } -------------------------------------------------------------------------------- /Misc/Artwork/Benchmark data/orient doc vs binary.txt: -------------------------------------------------------------------------------- 1 | Massive insert with 50000 entries 2 | --------------------------------- 3 | 4 | OrientDBDoc 5 | Total test time: 135.8 6 | put max 11.4 s, min 201 us - average 0,81 7 | get max 13.7 s, min 331 us - average 1,17 8 | 9 | OrientDBBinary 10 | Total test time: 106.6 seconds 11 | put max 12.3 s, min 53.9 us - average 0,55 12 | get max 7.77 s, min 64.3 us - average 0,64 13 | 14 | 14:34:19.321 [main] DEBUG repeatedInsert - overall performance: { 15 | cache.detail.moveToOrientDB 50000 hits - average 0,81 - max active:1 total time 40631 - Simon Stopwatch: [cache.detail.moveToOrientDB INHERIT] total 40.6 s, counter 50000, max 11.4 s, min 201 us 16 | cache.detail.moveInHeapfromOrientDB 50000 hits - average 1,17 - max active:1 total time 58531 - Simon Stopwatch: [cache.detail.moveInHeapfromOrientDB INHERIT] total 58.5 s, counter 50000, max 13.7 s, min 331 us 17 | cache.detail.moveToOrientDBBinary 50000 hits - average 0,55 - max active:1 total time 27519 - Simon Stopwatch: [cache.detail.moveToOrientDBBinary INHERIT] total 27.5 s, counter 50000, max 12.3 s, min 53.9 us 18 | cache.detail.moveInHeapfromOrientDBBinary 50000 hits - average 0,64 - max active:1 total time 32116 - Simon Stopwatch: [cache.detail.moveInHeapfromOrientDBBinary INHERIT] total 32.1 s, counter 50000, max 7.77 s, min 64.3 us 19 | } 20 | -------------------------------------------------------------------------------- /Misc/Artwork/Benchmark data/totalTestTime.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/Benchmark data/totalTestTime.PNG -------------------------------------------------------------------------------- /Misc/Artwork/DirectMemory-Cache-logo-medium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/DirectMemory-Cache-logo-medium.png -------------------------------------------------------------------------------- /Misc/Artwork/DirectMemory-Cache-logo-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/DirectMemory-Cache-logo-small.png -------------------------------------------------------------------------------- /Misc/Artwork/DirectMemory-Cache-logo-with-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/DirectMemory-Cache-logo-with-banner.png -------------------------------------------------------------------------------- /Misc/Artwork/DirectMemory-Cache-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/DirectMemory-Cache-logo.png -------------------------------------------------------------------------------- /Misc/Artwork/DirectMemory-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/DirectMemory-icon.png -------------------------------------------------------------------------------- /Misc/Artwork/apache penna.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/Artwork/apache penna.png -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.125705-2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.125705-2.jar -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.125705-2.jar.md5: -------------------------------------------------------------------------------- 1 | 2a3b1f4e8a33a8e3b2c0a1d7d4f5e37c -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.125705-2.jar.sha1: -------------------------------------------------------------------------------- 1 | 2be50335fdaaf263b990f0df05969783850e538f -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.125705-2.pom: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | UTF-8 9 | 10 | 11 | 4.0.0 12 | org.directmemory 13 | DirectMemory-Cache 14 | jar 15 | DirectMemory Cache 16 | 0.5.5-SNAPSHOT 17 | DirectMemory Cache is a multi layered cache implementation featuring off-heap memory management (a-la BigMemory) to enable efficient handling of a large number of java objects without affecting jvm garbage collection performance 18 | http://github.com/raffaeleguidi/DirectMemory 19 | 20 | Github 21 | http://github.com/raffaeleguidi/DirectMemory/issues 22 | 23 | 24 | Raffaele P. Guidi 25 | http://twitter.com/raffaeleguidi 26 | 27 | 28 | src/main/java 29 | 30 | 31 | src/test/java 32 | 33 | 34 | . 35 | false 36 | config 37 | 38 | * 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-compiler-plugin 47 | 2.3.2 48 | 49 | 1.6 50 | 1.6 51 | 52 | 53 | 54 | 55 | org.codehaus.mojo 56 | aspectj-maven-plugin 57 | 1.4 58 | 59 | 1.6 60 | 1.6 61 | 62 | 63 | 64 | 65 | compile 66 | test-compile 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 2.9 75 | org.apache.maven.plugins 76 | maven-surefire-plugin 77 | 78 | -Xmx512m -Xms512m -XX:MaxDirectMemorySize=512m 79 | 80 | 81 | 82 | 107 | 108 | 109 | 110 | 111 | sonatype-nexus-public 112 | SonaType public snapshots and releases repository 113 | https://oss.sonatype.org/content/groups/public/ 114 | 115 | 116 | false 117 | 118 | 119 | true 120 | 121 | 122 | 129 | 130 | http://repo.fusesource.com/maven2 131 | fusesource 132 | 133 | 134 | 135 | 136 | 137 | 147 | 148 | 149 | org.apache.servicemix.bundles 150 | org.apache.servicemix.bundles.josql 151 | 1.5_5 152 | 153 | 154 | net.sf.josql 155 | gentlyweb-utils 156 | 1.5 157 | 158 | 165 | 166 | com.h2database 167 | h2 168 | 1.3.158 169 | test 170 | 171 | 172 | com.carrotsearch 173 | junit-benchmarks 174 | 0.3.1-SNAPSHOT 175 | test 176 | 177 | 178 | com.google.guava 179 | guava 180 | r09 181 | 182 | 183 | org.aspectj 184 | aspectjrt 185 | 1.6.11 186 | 187 | 188 | junit 189 | junit 190 | 4.8.2 191 | test 192 | 193 | 194 | com.dyuproject.protostuff 195 | protostuff-runtime 196 | 1.0.1 197 | jar 198 | false 199 | 200 | 201 | com.dyuproject.protostuff 202 | protostuff-core 203 | 1.0.1 204 | 205 | 206 | com.dyuproject.protostuff 207 | protostuff-api 208 | 1.0.1 209 | 210 | 211 | ch.qos.logback 212 | logback-core 213 | 0.9.26 214 | jar 215 | false 216 | 217 | 218 | ch.qos.logback 219 | logback-classic 220 | 0.9.26 221 | jar 222 | false 223 | 224 | 225 | org.slf4j 226 | slf4j-api 227 | 1.6.1 228 | jar 229 | false 230 | 231 | 232 | 233 | 234 | 235 | repo 236 | https://raw.github.com/raffaeleguidi/DirectMemory/master/Misc/mvn-repo/releases 237 | 238 | 239 | snapshot-repo 240 | https://raw.github.com/raffaeleguidi/DirectMemory/master/Misc/mvn-repo/snapshots 241 | 242 | 243 | 244 | 245 | -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.125705-2.pom.md5: -------------------------------------------------------------------------------- 1 | 42ee77865633d02af11ef87796c08a0b -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.125705-2.pom.sha1: -------------------------------------------------------------------------------- 1 | 6a9d9b79ff86a30691c117dfb06c36700583f072 -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.163520-3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.163520-3.jar -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.163520-3.jar.md5: -------------------------------------------------------------------------------- 1 | 94c36e052eb53307ccd567c29c650ca7 -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.163520-3.jar.sha1: -------------------------------------------------------------------------------- 1 | 17ee16e46c476dfb1b4908b42077b697d0238ff7 -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.163520-3.pom: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | UTF-8 9 | 10 | 11 | 4.0.0 12 | org.directmemory 13 | DirectMemory-Cache 14 | jar 15 | DirectMemory Cache 16 | 0.5.5-SNAPSHOT 17 | DirectMemory Cache is a multi layered cache implementation featuring off-heap memory management (a-la BigMemory) to enable efficient handling of a large number of java objects without affecting jvm garbage collection performance 18 | http://github.com/raffaeleguidi/DirectMemory 19 | 20 | Github 21 | http://github.com/raffaeleguidi/DirectMemory/issues 22 | 23 | 24 | Raffaele P. Guidi 25 | http://twitter.com/raffaeleguidi 26 | 27 | 28 | src/main/java 29 | 30 | 31 | src/test/java 32 | 33 | 34 | . 35 | false 36 | config 37 | 38 | * 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-compiler-plugin 47 | 2.3.2 48 | 49 | 1.6 50 | 1.6 51 | 52 | 53 | 54 | 55 | org.codehaus.mojo 56 | aspectj-maven-plugin 57 | 1.4 58 | 59 | 1.6 60 | 1.6 61 | 62 | 63 | 64 | 65 | compile 66 | test-compile 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 2.9 75 | org.apache.maven.plugins 76 | maven-surefire-plugin 77 | 78 | -Xmx512m -Xms512m -XX:MaxDirectMemorySize=512m 79 | 80 | 81 | 82 | 107 | 108 | 109 | 110 | 111 | sonatype-nexus-public 112 | SonaType public snapshots and releases repository 113 | https://oss.sonatype.org/content/groups/public/ 114 | 115 | 116 | false 117 | 118 | 119 | true 120 | 121 | 122 | 129 | 130 | http://repo.fusesource.com/maven2 131 | fusesource 132 | 133 | 134 | 135 | 136 | 137 | 147 | 148 | 149 | org.apache.servicemix.bundles 150 | org.apache.servicemix.bundles.josql 151 | 1.5_5 152 | 153 | 154 | net.sf.josql 155 | gentlyweb-utils 156 | 1.5 157 | 158 | 165 | 166 | com.h2database 167 | h2 168 | 1.3.158 169 | test 170 | 171 | 172 | com.carrotsearch 173 | junit-benchmarks 174 | 0.3.1-SNAPSHOT 175 | test 176 | 177 | 178 | com.google.guava 179 | guava 180 | r09 181 | 182 | 183 | org.aspectj 184 | aspectjrt 185 | 1.6.11 186 | 187 | 188 | junit 189 | junit 190 | 4.8.2 191 | test 192 | 193 | 194 | com.dyuproject.protostuff 195 | protostuff-runtime 196 | 1.0.1 197 | jar 198 | false 199 | 200 | 201 | com.dyuproject.protostuff 202 | protostuff-core 203 | 1.0.1 204 | 205 | 206 | com.dyuproject.protostuff 207 | protostuff-api 208 | 1.0.1 209 | 210 | 211 | ch.qos.logback 212 | logback-core 213 | 0.9.26 214 | jar 215 | false 216 | 217 | 218 | ch.qos.logback 219 | logback-classic 220 | 0.9.26 221 | jar 222 | false 223 | 224 | 225 | org.slf4j 226 | slf4j-api 227 | 1.6.1 228 | jar 229 | false 230 | 231 | 232 | 233 | 234 | 235 | repo 236 | https://raw.github.com/raffaeleguidi/DirectMemory/master/Misc/mvn-repo/releases 237 | 238 | 239 | snapshot-repo 240 | https://raw.github.com/raffaeleguidi/DirectMemory/master/Misc/mvn-repo/snapshots 241 | 242 | 243 | 244 | 245 | -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.163520-3.pom.md5: -------------------------------------------------------------------------------- 1 | 42ee77865633d02af11ef87796c08a0b -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110917.163520-3.pom.sha1: -------------------------------------------------------------------------------- 1 | 6a9d9b79ff86a30691c117dfb06c36700583f072 -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110922.062228-4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raffaeleguidi/DirectMemory/f129b94a89b3ce291f7b01c78b8809870a265daf/Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110922.062228-4.jar -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110922.062228-4.jar.md5: -------------------------------------------------------------------------------- 1 | 9ed0de4550f5cc8dde8e33ce6ad559c6 -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110922.062228-4.jar.sha1: -------------------------------------------------------------------------------- 1 | da4a07bd0139399aae90198f47e775c4845e557f -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110922.062228-4.pom: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | UTF-8 9 | 10 | 11 | 4.0.0 12 | org.directmemory 13 | DirectMemory-Cache 14 | jar 15 | DirectMemory Cache 16 | 0.5.5-SNAPSHOT 17 | DirectMemory Cache is a multi layered cache implementation featuring off-heap memory management (a-la BigMemory) to enable efficient handling of a large number of java objects without affecting jvm garbage collection performance 18 | http://github.com/raffaeleguidi/DirectMemory 19 | 20 | Github 21 | http://github.com/raffaeleguidi/DirectMemory/issues 22 | 23 | 24 | Raffaele P. Guidi 25 | http://twitter.com/raffaeleguidi 26 | 27 | 28 | src/main/java 29 | 30 | 31 | src/test/java 32 | 33 | 34 | . 35 | false 36 | config 37 | 38 | * 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-compiler-plugin 47 | 2.3.2 48 | 49 | 1.6 50 | 1.6 51 | 52 | 53 | 54 | 55 | org.codehaus.mojo 56 | aspectj-maven-plugin 57 | 1.4 58 | 59 | 1.6 60 | 1.6 61 | 62 | 63 | 64 | 65 | compile 66 | test-compile 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 2.9 75 | org.apache.maven.plugins 76 | maven-surefire-plugin 77 | 78 | -Xmx512m -Xms512m -XX:MaxDirectMemorySize=512m 79 | 80 | 81 | 82 | 107 | 108 | 109 | 110 | 111 | sonatype-nexus-public 112 | SonaType public snapshots and releases repository 113 | https://oss.sonatype.org/content/groups/public/ 114 | 115 | 116 | false 117 | 118 | 119 | true 120 | 121 | 122 | 129 | 130 | http://repo.fusesource.com/maven2 131 | fusesource 132 | 133 | 134 | 135 | 136 | 137 | 147 | 148 | 149 | org.apache.servicemix.bundles 150 | org.apache.servicemix.bundles.josql 151 | 1.5_5 152 | 153 | 154 | net.sf.josql 155 | gentlyweb-utils 156 | 1.5 157 | 158 | 165 | 166 | com.h2database 167 | h2 168 | 1.3.158 169 | test 170 | 171 | 172 | com.carrotsearch 173 | junit-benchmarks 174 | 0.3.0-SNAPSHOT 175 | test 176 | 177 | 178 | com.google.guava 179 | guava 180 | r09 181 | 182 | 183 | org.aspectj 184 | aspectjrt 185 | 1.6.11 186 | 187 | 188 | junit 189 | junit 190 | 4.8.2 191 | test 192 | 193 | 194 | com.dyuproject.protostuff 195 | protostuff-runtime 196 | 1.0.1 197 | jar 198 | false 199 | 200 | 201 | com.dyuproject.protostuff 202 | protostuff-core 203 | 1.0.1 204 | 205 | 206 | com.dyuproject.protostuff 207 | protostuff-api 208 | 1.0.1 209 | 210 | 211 | ch.qos.logback 212 | logback-core 213 | 0.9.26 214 | jar 215 | false 216 | 217 | 218 | ch.qos.logback 219 | logback-classic 220 | 0.9.26 221 | jar 222 | false 223 | 224 | 225 | org.slf4j 226 | slf4j-api 227 | 1.6.1 228 | jar 229 | false 230 | 231 | 232 | 233 | 234 | 235 | repo 236 | https://raw.github.com/raffaeleguidi/DirectMemory/master/Misc/mvn-repo/releases 237 | 238 | 239 | snapshot-repo 240 | https://raw.github.com/raffaeleguidi/DirectMemory/master/Misc/mvn-repo/snapshots 241 | 242 | 243 | 244 | 245 | -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110922.062228-4.pom.md5: -------------------------------------------------------------------------------- 1 | 9ac2e835ca728fedcafe9aa0b41c30e2 -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/DirectMemory-Cache-0.5.5-20110922.062228-4.pom.sha1: -------------------------------------------------------------------------------- 1 | 2e8327b7188ddcc4a6c1b79a78a91fd059303460 -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/maven-metadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.directmemory 4 | DirectMemory-Cache 5 | 0.5.5-SNAPSHOT 6 | 7 | 8 | 20110922.062228 9 | 4 10 | 11 | 20110922062228 12 | 13 | 14 | jar 15 | 0.5.5-20110922.062228-4 16 | 20110922062228 17 | 18 | 19 | pom 20 | 0.5.5-20110922.062228-4 21 | 20110922062228 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/maven-metadata.xml.md5: -------------------------------------------------------------------------------- 1 | 0f64676ef065d2f102ce3f5a14d6d5c2 -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/0.5.5-SNAPSHOT/maven-metadata.xml.sha1: -------------------------------------------------------------------------------- 1 | 87e3c51eaec1c9c2d90162aeb55a1a3a74e3eea2 -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/maven-metadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.directmemory 4 | DirectMemory-Cache 5 | 6 | 7 | 0.5.5-SNAPSHOT 8 | 9 | 20110922062228 10 | 11 | 12 | -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/maven-metadata.xml.md5: -------------------------------------------------------------------------------- 1 | 3bf560dd65f89fff67f67fbb67284115 -------------------------------------------------------------------------------- /Misc/mvn-repo/snapshots/org/directmemory/DirectMemory-Cache/maven-metadata.xml.sha1: -------------------------------------------------------------------------------- 1 | 3f51d3fcd9a5a30e4fc46180cbe874b8a9cd0a09 -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | DirectMemory is a multi layered cache implementation featuring off-heap memory storage (a-la BigMemory) to enable caching of java objects without degrading jvm performance. Its main purpose is to act as a second level cache (after a heap based one) to collect large amounts of data without filling up the java heap and thus avoiding long garbage collection cycles. Included in the box is a small set of utility classes to easily handle off-heap memory buffers. --------------------------------------------------------------------------------