Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMH Benchmarks: Avoid byte array copy for reads in NMA valueSerializer #13

Merged
merged 3 commits into from
Feb 7, 2023

Conversation

aaronriekenberg
Copy link
Contributor

@aaronriekenberg aaronriekenberg commented Feb 6, 2023

GCP VM Perf results with this change are below, compare with baseline: https://github.com/target/native_memory_allocator/wiki/Benchmark-results-in-GCP-VM

  • NMA tps is 3.7x more in read_only test (257K -> 970K)
  • NMA tps is 2.1x more in readwrite test (256K -> 555K)
  • Results for RocksDB do not change.

~/jdk-17.0.6/bin/java -jar ./benchmarks-jmh.jar -wi 10 -i 20 -f 1 -gc true -foe true -tg 32 -jvmArgs '-Xmx4G -Drocksdb.dir=/tmp/tmpfs/rocksdb' read_only

Benchmark                         (cacheType)   Mode  Cnt       Score      Error  Units
OffHeapGetPutBenchmark.read_only          NMA  thrpt   20  970632.328 ± 8836.803  ops/s
OffHeapGetPutBenchmark.read_only      RocksDB  thrpt   20  120857.160 ± 1444.857  ops/s


~/jdk-17.0.6/bin/java -jar ./benchmarks-jmh.jar -wi 10 -i 20 -f 1 -gc true -foe true -tg 32 -jvmArgs '-Xmx4G -Drocksdb.dir=/tmp/tmpfs/rocksdb' write_only

Benchmark                          (cacheType)   Mode  Cnt       Score      Error  Units
OffHeapGetPutBenchmark.write_only          NMA  thrpt   20  199977.906 ± 6923.452  ops/s
OffHeapGetPutBenchmark.write_only      RocksDB  thrpt   20    2466.037 ±  492.823  ops/s


~/jdk-17.0.6/bin/java -jar ./benchmarks-jmh.jar -wi 10 -i 20 -f 1 -gc true -foe true -tg 24,8 -jvmArgs '-Xmx4G -Drocksdb.dir=/tmp/tmpfs/rocksdb'   readwrite

Benchmark                                       (cacheType)   Mode  Cnt       Score       Error  Units
OffHeapGetPutBenchmark.readwrite                        NMA  thrpt   20  555568.405 ± 30179.022  ops/s
OffHeapGetPutBenchmark.readwrite:readwrite_get          NMA  thrpt   20  481717.573 ± 26025.353  ops/s
OffHeapGetPutBenchmark.readwrite:readwrite_put          NMA  thrpt   20   73850.832 ±  4198.050  ops/s
OffHeapGetPutBenchmark.readwrite                    RocksDB  thrpt   20  109377.958 ± 17557.734  ops/s
OffHeapGetPutBenchmark.readwrite:readwrite_get      RocksDB  thrpt   20  107904.098 ± 17242.323  ops/s
OffHeapGetPutBenchmark.readwrite:readwrite_put      RocksDB  thrpt   20    1473.860 ±   429.475  ops/s

return onHeapMemoryBuffer.toTrimmedArray()
private val valueSerializer = object : NativeMemoryMapSerializer<ByteBuffer> {
override fun deserializeFromOnHeapMemoryBuffer(onHeapMemoryBuffer: OnHeapMemoryBuffer): ByteBuffer {
return onHeapMemoryBuffer.asByteBuffer()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toTrimmedArray makes a copy of the byte array on every read, asByteBuffer does not make a copy - this takes advantage of the thread-local read buffer in NativeMemoryMap

@aaronriekenberg aaronriekenberg changed the title Avoid byte array copy for reads in NMA valueSerializer. JMH Benchmarks: Avoid byte array copy for reads in NMA valueSerializer Feb 6, 2023
Copy link
Collaborator

@kellar kellar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aaronriekenberg aaronriekenberg merged commit 0547d75 into target:main Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants