You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In rocksdbjni, I would expect the misses to be less expensive than the hits, or at least as expensive.
I have tested v9.5.2, but the last v9.6.1 has no change in java/rocksjni/rocksjni.cc so the issue remains.
Actual behavior
The misses are far more expensive than the hits due to a C++ exception which is thrown then caught a few lines after.
// throws a rocksdb::KVException...ROCKSDB_NAMESPACE::KVException::ThrowOnError(
env,
db->Get(ROCKSDB_NAMESPACE::ReadOptions(), db->DefaultColumnFamily(),
key.slice(), &value.pinnable_slice()));
return value.NewByteArray();
} catch (ROCKSDB_NAMESPACE::KVException&) {
// ... which is caught a few lines afterreturnnullptr;
}
Just changing the above code to the following speeds up a lot the misses:
In this reproducer, we create a DB with 1M entries, then we perform:
1M hits with all the keys in the DB (method App.readDatabaseHits())
1M misses (method App.readDatabaseMisses())
loop
I don't compare vanilla vs patched as the compilation parameters are different, but only the CPU time spent on hits vs misses in each case. The following tests are done on an AWS m5d.4xlarge machine (linux/x84_64), but I have also been able to reproduce an a M1 Mac (MacOS/aarch64 and qemu+linux/aarch64).
On the vanilla version, in case of miss, we can see that a lot of CPU time is spent in rocksdb::KVException::ThrowOnError(). This makes the misses slower than the hits by far:
With the small patch above, as we don't throw exceptions, the misses are a bit less expensive than the hits:
The text was updated successfully, but these errors were encountered:
thank you for amazing report. I agree that using exceptions for misses is probably not the best. I will check with my colleagues and see how we can optimize this. Probably leave exception on for error cases.
Expected behavior
This is only for rocksdbjni.
In rocksdbjni, I would expect the misses to be less expensive than the hits, or at least as expensive.
I have tested
v9.5.2
, but the lastv9.6.1
has no change injava/rocksjni/rocksjni.cc
so the issue remains.Actual behavior
The misses are far more expensive than the hits due to a C++ exception which is thrown then caught a few lines after.
For instance in
java/rocksjni/rocksjni.cc
in Java_org_rocksdb_RocksDB_get__J_3BII():Just changing the above code to the following speeds up a lot the misses:
Steps to reproduce the behavior
I have created a small reproducer in trazfr/rocksdbjni-miss-perfs which runs the two following rocksdbjni jar and send the results to the Datadog profiler:
9.5.2
In this reproducer, we create a DB with 1M entries, then we perform:
App.readDatabaseHits()
)App.readDatabaseMisses()
)I don't compare vanilla vs patched as the compilation parameters are different, but only the CPU time spent on hits vs misses in each case. The following tests are done on an AWS
m5d.4xlarge
machine (linux/x84_64), but I have also been able to reproduce an a M1 Mac (MacOS/aarch64 and qemu+linux/aarch64).On the vanilla version, in case of miss, we can see that a lot of CPU time is spent in
rocksdb::KVException::ThrowOnError()
. This makes the misses slower than the hits by far:With the small patch above, as we don't throw exceptions, the misses are a bit less expensive than the hits:
The text was updated successfully, but these errors were encountered: