rocksdb/utilities/transactions
Peter Dillinger 17bc27741f Improve memory efficiency of many OptimisticTransactionDBs (#11439)
Summary:
Currently it's easy to use a ton of memory with many small OptimisticTransactionDB instances, because each one by default allocates a million mutexes (40 bytes each on my compiler) for validating transactions. It even puts a lot of pressure on the allocator by allocating each one individually!

In this change:
* Create a new object and option that enables sharing these buckets of mutexes between instances. This is generally good for load balancing potential contention as various DBs become hotter or colder with txn writes. About the only cases where this sharing wouldn't make sense (e.g. each DB usually written by one thread) are cases that would be better off with OccValidationPolicy::kValidateSerial which doesn't use the buckets anyway.
* Allocate the mutexes in a contiguous array, for efficiency
* Add an option to ensure the mutexes are cache-aligned. In several other places we use cache-aligned mutexes but OptimisticTransactionDB historically does not. It should be a space-time trade-off the user can choose.
* Provide some visibility into the memory used by the mutex buckets with an ApproximateMemoryUsage() function (also used in unit testing)
* Share code with other users of "striped" mutexes, appropriate refactoring for customization & efficiency (e.g. using FastRange instead of modulus)

Pull Request resolved: https://github.com/facebook/rocksdb/pull/11439

Test Plan: unit tests added. Ran sized-up versions of stress test in unit test, including a before-and-after performance test showing no consistent difference. (NOTE: OptimisticTransactionDB not currently covered by db_stress!)

Reviewed By: ltamasi

Differential Revision: D45796393

Pulled By: pdillinger

fbshipit-source-id: ae2b3a26ad91ceeec15debcdc63ff48df6736a54
2023-05-24 11:57:15 -07:00
..
lock Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
optimistic_transaction.cc Improve memory efficiency of many OptimisticTransactionDBs (#11439) 2023-05-24 11:57:15 -07:00
optimistic_transaction.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
optimistic_transaction_db_impl.cc Improve memory efficiency of many OptimisticTransactionDBs (#11439) 2023-05-24 11:57:15 -07:00
optimistic_transaction_db_impl.h Improve memory efficiency of many OptimisticTransactionDBs (#11439) 2023-05-24 11:57:15 -07:00
optimistic_transaction_test.cc Improve memory efficiency of many OptimisticTransactionDBs (#11439) 2023-05-24 11:57:15 -07:00
pessimistic_transaction.cc Group rocksdb.sst.read.micros stat by IOActivity flush and compaction (#11288) 2023-04-21 09:07:18 -07:00
pessimistic_transaction.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
pessimistic_transaction_db.cc Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
pessimistic_transaction_db.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
snapshot_checker.cc Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
timestamped_snapshot_test.cc Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
transaction_base.cc Group rocksdb.sst.read.micros stat by IOActivity flush and compaction (#11288) 2023-04-21 09:07:18 -07:00
transaction_base.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
transaction_db_mutex_impl.cc Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
transaction_db_mutex_impl.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
transaction_test.cc Remove wait_unscheduled from waitForCompact internal API (#11443) 2023-05-17 18:13:50 -07:00
transaction_test.h Replace member variable lambda with methods (#10924) 2022-11-07 12:31:48 -08:00
transaction_util.cc Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
transaction_util.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
write_committed_transaction_ts_test.cc Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
write_prepared_transaction_test.cc Remove wait_unscheduled from waitForCompact internal API (#11443) 2023-05-17 18:13:50 -07:00
write_prepared_txn.cc Group rocksdb.sst.read.micros stat by IOActivity flush and compaction (#11288) 2023-04-21 09:07:18 -07:00
write_prepared_txn.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
write_prepared_txn_db.cc Group rocksdb.sst.read.micros stat by IOActivity flush and compaction (#11288) 2023-04-21 09:07:18 -07:00
write_prepared_txn_db.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
write_unprepared_transaction_test.cc Refactor WriteUnpreparedStressTest to be a unit test (#11424) 2023-05-22 12:31:52 -07:00
write_unprepared_txn.cc Group rocksdb.sst.read.micros stat by IOActivity flush and compaction (#11288) 2023-04-21 09:07:18 -07:00
write_unprepared_txn.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
write_unprepared_txn_db.cc Group rocksdb.sst.read.micros stat by IOActivity flush and compaction (#11288) 2023-04-21 09:07:18 -07:00
write_unprepared_txn_db.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00