mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-27 11:43:49 +00:00
17bc27741f
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
57 lines
1.8 KiB
C++
57 lines
1.8 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#pragma once
|
|
|
|
#include <cinttypes>
|
|
|
|
#include "cache/typed_cache.h"
|
|
#include "db/blob/blob_file_reader.h"
|
|
#include "rocksdb/rocksdb_namespace.h"
|
|
#include "util/mutexlock.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
class Cache;
|
|
struct ImmutableOptions;
|
|
struct FileOptions;
|
|
class HistogramImpl;
|
|
class Status;
|
|
class Slice;
|
|
class IOTracer;
|
|
|
|
class BlobFileCache {
|
|
public:
|
|
BlobFileCache(Cache* cache, const ImmutableOptions* immutable_options,
|
|
const FileOptions* file_options, uint32_t column_family_id,
|
|
HistogramImpl* blob_file_read_hist,
|
|
const std::shared_ptr<IOTracer>& io_tracer);
|
|
|
|
BlobFileCache(const BlobFileCache&) = delete;
|
|
BlobFileCache& operator=(const BlobFileCache&) = delete;
|
|
|
|
Status GetBlobFileReader(const ReadOptions& read_options,
|
|
uint64_t blob_file_number,
|
|
CacheHandleGuard<BlobFileReader>* blob_file_reader);
|
|
|
|
private:
|
|
using CacheInterface =
|
|
BasicTypedCacheInterface<BlobFileReader, CacheEntryRole::kMisc>;
|
|
using TypedHandle = CacheInterface::TypedHandle;
|
|
CacheInterface cache_;
|
|
// Note: mutex_ below is used to guard against multiple threads racing to open
|
|
// the same file.
|
|
Striped<CacheAlignedWrapper<port::Mutex>> mutex_;
|
|
const ImmutableOptions* immutable_options_;
|
|
const FileOptions* file_options_;
|
|
uint32_t column_family_id_;
|
|
HistogramImpl* blob_file_read_hist_;
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
|
|
|
static constexpr size_t kNumberOfMutexStripes = 1 << 7;
|
|
};
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|