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

Use SystemClock* instead of std::shared_ptr<SystemClock> in lower level routines #8033

Closed
wants to merge 7 commits into from

Conversation

mrambacher
Copy link
Contributor

For performance purposes, the lower level routines were changed to use a SystemClock* instead of a std::shared_ptr. The shared ptr has some performance degradation on certain hardware classes.

For most of the system, there is no risk of the pointer being deleted/invalid because the shared_ptr will be stored elsewhere. For example, the ImmutableDBOptions stores the Env which has a std::shared_ptr in it. The SystemClock* within the ImmutableDBOptions is essentially a "short cut" to gain access to this constant resource.

There were a few classes (PeriodicWorkScheduler?) where the "short cut" property did not hold. In those cases, the shared pointer was preserved.

Using db_bench readrandom perf_level=3 on my EC2 box, this change performed as well or better than 6.17:

6.17: readrandom : 28.046 micros/op 854902 ops/sec; 61.3 MB/s (355999 of 355999 found)
6.18: readrandom : 32.615 micros/op 735306 ops/sec; 52.7 MB/s (290999 of 290999 found)
PR: readrandom : 27.500 micros/op 871909 ops/sec; 62.5 MB/s (367999 of 367999 found)

(Note that the times for 6.18 are prior to revert of the SystemClock).

@pdillinger
Copy link
Contributor

pdillinger commented Mar 5, 2021

Remaining shared_ptr<SystemClock> (git grep shared_ptr.SystemClock | grep -v test.cc)

db/flush_job.h:  const std::shared_ptr<SystemClock> clock_;
db/internal_stats.h:  InternalStats(int num_levels, const std::shared_ptr<SystemClock>& clock,
db/internal_stats.h:  const std::shared_ptr<SystemClock> clock_;
db/internal_stats.h:                const std::shared_ptr<SystemClock>& /*clock*/,
db/periodic_work_scheduler.cc:    const std::shared_ptr<SystemClock>& clock) {
db/periodic_work_scheduler.cc:    const std::shared_ptr<SystemClock>& clock) {
db/periodic_work_scheduler.cc:    const std::shared_ptr<SystemClock>& clock)
db/periodic_work_scheduler.h:  explicit PeriodicWorkScheduler(const std::shared_ptr<SystemClock>& clock);
db/periodic_work_scheduler.h:      const std::shared_ptr<SystemClock>& clock);
db/periodic_work_scheduler.h:  explicit PeriodicWorkTestScheduler(const std::shared_ptr<SystemClock>& clock);
env/composite_env_wrapper.h:                        const std::shared_ptr<SystemClock>& clock)
env/composite_env_wrapper.h:  explicit CompositeEnvWrapper(Env* env, const std::shared_ptr<SystemClock>& sc)
env/composite_env_wrapper.h:                               const std::shared_ptr<SystemClock>& sc)
env/env.cc:         const std::shared_ptr<SystemClock>& clock)
env/env.cc:const std::shared_ptr<SystemClock>& Env::GetSystemClock() const {
env/env_posix.cc:const std::shared_ptr<SystemClock>& SystemClock::Default() {
env/env_posix.cc:  static std::shared_ptr<SystemClock> default_clock =
file/delete_scheduler.cc:DeleteScheduler::DeleteScheduler(const std::shared_ptr<SystemClock>& clock,
file/delete_scheduler.h:  DeleteScheduler(const std::shared_ptr<SystemClock>& clock, FileSystem* fs,
file/delete_scheduler.h:  const std::shared_ptr<SystemClock> clock_;
file/sst_file_manager_impl.cc:    const std::shared_ptr<SystemClock>& clock,
file/sst_file_manager_impl.h:  explicit SstFileManagerImpl(const std::shared_ptr<SystemClock>& clock,
file/sst_file_manager_impl.h:  std::shared_ptr<SystemClock> clock_;
include/rocksdb/env.h:      const std::shared_ptr<SystemClock>& clock);
include/rocksdb/env.h:  const std::shared_ptr<SystemClock>& GetSystemClock() const;
include/rocksdb/env.h:  std::shared_ptr<SystemClock> system_clock_;
include/rocksdb/system_clock.h:  static const std::shared_ptr<SystemClock>& Default();
include/rocksdb/system_clock.h:  explicit SystemClockWrapper(const std::shared_ptr<SystemClock>& t)
include/rocksdb/system_clock.h:  std::shared_ptr<SystemClock> target_;
logging/auto_roll_logger.cc:                               const std::shared_ptr<SystemClock>& clock,
logging/auto_roll_logger.h:                 const std::shared_ptr<SystemClock>& clock,
logging/auto_roll_logger.h:  std::shared_ptr<SystemClock> clock_;
monitoring/histogram_windowing.h:  void TEST_UpdateClock(const std::shared_ptr<SystemClock>& clock) {
monitoring/histogram_windowing.h:  std::shared_ptr<SystemClock> clock_;
port/win/env_win.cc:WinFileSystem::WinFileSystem(const std::shared_ptr<SystemClock>& clock)
port/win/env_win.cc:const std::shared_ptr<SystemClock>& SystemClock::Default() {
port/win/env_win.cc:  static std::shared_ptr<SystemClock> clock =
port/win/env_win.h:  WinFileSystem(const std::shared_ptr<SystemClock>& clock);
port/win/env_win.h:  std::shared_ptr<SystemClock> clock_;
port/win/win_logger.cc:                     const std::shared_ptr<SystemClock>& clock, HANDLE file,
port/win/win_logger.h:  WinLogger(uint64_t (*gettid)(), const std::shared_ptr<SystemClock>& clock,
port/win/win_logger.h:  std::shared_ptr<SystemClock> clock_;
test_util/mock_time_env.h:  explicit MockSystemClock(const std::shared_ptr<SystemClock>& base)
trace_replay/io_tracer.cc:IOTraceWriter::IOTraceWriter(const std::shared_ptr<SystemClock>& clock,
trace_replay/io_tracer.cc:Status IOTracer::StartIOTrace(const std::shared_ptr<SystemClock>& clock,
trace_replay/io_tracer.h:  IOTraceWriter(const std::shared_ptr<SystemClock>& clock,
trace_replay/io_tracer.h:  std::shared_ptr<SystemClock> clock_;
trace_replay/io_tracer.h:  StartIOTrace(const std::shared_ptr<SystemClock>& clock,
util/rate_limiter.cc:    RateLimiter::Mode mode, const std::shared_ptr<SystemClock>& clock,
util/rate_limiter.h:                     const std::shared_ptr<SystemClock>& clock,
util/rate_limiter.h:  uint64_t NowMicrosMonotonic(const std::shared_ptr<SystemClock>& clock) {
util/rate_limiter.h:  std::shared_ptr<SystemClock> clock_;

Compare to shared_ptr<Env>:

db/db_test_util.h:  std::shared_ptr<Env> env_guard_;
db_stress_tool/db_stress_tool.cc:  static std::shared_ptr<Env> composite_env = NewCompositeEnv(fs);
env/env.cc:                    std::shared_ptr<Env>* guard) {
include/rocksdb/env.h:                        std::shared_ptr<Env>* guard);
include/rocksdb/utilities/ldb_cmd.h:  std::shared_ptr<Env> env_guard_;
tools/ldb_cmd_impl.h:  std::shared_ptr<Env> backup_env_guard_;

@pdillinger
Copy link
Contributor

pdillinger commented Mar 5, 2021

Perhaps a better analog is shared_ptr<FileSystem>:

db/db_impl/db_impl.cc:  const std::shared_ptr<FileSystem>& fs = db_options.env->GetFileSystem();
db/db_impl/db_impl_readonly.cc:    const std::shared_ptr<FileSystem>& fs = db_options.env->GetFileSystem();
db/version_set.cc:    const std::shared_ptr<FileSystem>& fs = options.env->GetFileSystem();
db_stress_tool/db_stress_tool.cc:static Env* GetCompositeEnv(std::shared_ptr<FileSystem> fs) {
db_stress_tool/db_stress_tool.cc:    std::shared_ptr<FileSystem> fs;
env/composite_env_wrapper.h:  explicit CompositeEnv(const std::shared_ptr<FileSystem>& fs,
env/composite_env_wrapper.h:  explicit CompositeEnvWrapper(Env* env, const std::shared_ptr<FileSystem>& fs)
env/composite_env_wrapper.h:  explicit CompositeEnvWrapper(Env* env, const std::shared_ptr<FileSystem>& fs,
env/env.cc:Env::Env(const std::shared_ptr<FileSystem>& fs)
env/env.cc:Env::Env(const std::shared_ptr<FileSystem>& fs,
env/env.cc:const std::shared_ptr<FileSystem>& Env::GetFileSystem() const {
env/env_posix.cc:  PosixEnv(const PosixEnv* default_env, const std::shared_ptr<FileSystem>& fs);
env/env_posix.cc:                   const std::shared_ptr<FileSystem>& fs)
env/env_posix.cc:  std::shared_ptr<FileSystem> fs = FileSystem::Default();
env/env_posix.cc:std::unique_ptr<Env> NewCompositeEnv(const std::shared_ptr<FileSystem>& fs) {
env/file_system.cc:                        std::shared_ptr<FileSystem>* result) {
env/file_system_tracer.h:  FileSystemTracingWrapper(const std::shared_ptr<FileSystem>& t,
env/file_system_tracer.h:  FileSystemPtr(std::shared_ptr<FileSystem> fs,
env/file_system_tracer.h:  std::shared_ptr<FileSystem> operator->() const {
env/file_system_tracer.h:  std::shared_ptr<FileSystem> fs_;
env/file_system_tracer.h:  std::shared_ptr<FileSystemTracingWrapper> fs_tracer_;
env/fs_posix.cc:std::shared_ptr<FileSystem> FileSystem::Default() {
file/file_util.h:inline IOStatus CopyFile(const std::shared_ptr<FileSystem>& fs,
file/file_util.h:inline IOStatus CreateFile(const std::shared_ptr<FileSystem>& fs,
file/file_util.h:    const std::shared_ptr<FileSystem>& fs, const std::string& file_path,
file/filename.cc:Status GetInfoLogFiles(const std::shared_ptr<FileSystem>& fs,
file/filename.h:extern Status GetInfoLogFiles(const std::shared_ptr<FileSystem>& fs,
file/random_access_file_reader.cc:    const std::shared_ptr<FileSystem>& fs, const std::string& fname,
file/random_access_file_reader.h:  static Status Create(const std::shared_ptr<FileSystem>& fs,
file/sequence_file_reader.cc:    const std::shared_ptr<FileSystem>& fs, const std::string& fname,
file/sequence_file_reader.h:  static Status Create(const std::shared_ptr<FileSystem>& fs,
file/sst_file_manager_impl.cc:    const std::shared_ptr<FileSystem>& fs,
file/sst_file_manager_impl.cc:SstFileManager* NewSstFileManager(Env* env, std::shared_ptr<FileSystem> fs,
file/sst_file_manager_impl.h:                              const std::shared_ptr<FileSystem>& fs,
file/sst_file_manager_impl.h:  std::shared_ptr<FileSystem> fs_;
file/writable_file_writer.cc:Status WritableFileWriter::Create(const std::shared_ptr<FileSystem>& fs,
file/writable_file_writer.h:  static Status Create(const std::shared_ptr<FileSystem>& fs,
include/rocksdb/env.h:  explicit Env(const std::shared_ptr<FileSystem>& fs);
include/rocksdb/env.h:  Env(const std::shared_ptr<FileSystem>& fs,
include/rocksdb/env.h:  const std::shared_ptr<FileSystem>& GetFileSystem() const;
include/rocksdb/env.h:  std::shared_ptr<FileSystem> file_system_;
include/rocksdb/env.h:std::unique_ptr<Env> NewCompositeEnv(const std::shared_ptr<FileSystem>& fs);
include/rocksdb/file_system.h:                     std::shared_ptr<FileSystem>* result);
include/rocksdb/file_system.h:  static std::shared_ptr<FileSystem> Default();
include/rocksdb/file_system.h:  explicit FileSystemWrapper(const std::shared_ptr<FileSystem>& t)
include/rocksdb/file_system.h:  std::shared_ptr<FileSystem> target_;
include/rocksdb/sst_file_manager.h:    Env* env, std::shared_ptr<FileSystem> fs,
logging/auto_roll_logger.cc:AutoRollLogger::AutoRollLogger(const std::shared_ptr<FileSystem>& fs,
logging/auto_roll_logger.h:  AutoRollLogger(const std::shared_ptr<FileSystem>& fs,
logging/auto_roll_logger.h:  std::shared_ptr<FileSystem> fs_;
options/db_options.h:  std::shared_ptr<FileSystem> fs;
port/win/env_win.cc:std::shared_ptr<FileSystem> FileSystem::Default() {
port/win/env_win.cc:std::unique_ptr<Env> NewCompositeEnv(const std::shared_ptr<FileSystem>& fs) {
test_util/testutil.cc:bool IsPrefetchSupported(const std::shared_ptr<FileSystem>& fs,
test_util/testutil.h:  explicit StringFS(const std::shared_ptr<FileSystem>& t)
test_util/testutil.h:bool IsPrefetchSupported(const std::shared_ptr<FileSystem>& fs,
tools/db_bench_tool.cc:    std::shared_ptr<FileSystem> fs;
util/file_checksum_helper.cc:    const std::shared_ptr<FileSystem>& fs = src_env->GetFileSystem();
utilities/blob_db/blob_file.cc:Status BlobFile::ReadMetadata(const std::shared_ptr<FileSystem>& fs,
utilities/blob_db/blob_file.h:  Status ReadMetadata(const std::shared_ptr<FileSystem>& fs,
utilities/fault_injection_fs.h:  explicit FaultInjectionTestFS(const std::shared_ptr<FileSystem>& base)
utilities/persistent_cache/block_cache_tier_file.cc:Status NewRandomAccessCacheFile(const std::shared_ptr<FileSystem>& fs,

So potentially concerning for SystemClock:

flush_job
internal_stats
periodic_work_scheduler
delete_scheduler
histogram_windowing (is this code used anywhere?)
io_tracer
rate_limiter

I will review each of these in some more detail.

Copy link
Contributor

@pdillinger pdillinger left a comment

Choose a reason for hiding this comment

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

flush_job
internal_stats
io_tracer

These are internal objects that AFAIK should not be shared by DBs nor outlive them. Although they are probably long-lived enough not to be a concern, I would (on first assessment) prefer to see raw pointers for these.

io_tracer has additional concerns perhaps beyond the scope here (@akankshamahajan15):

  • DB::StartIOTrace takes an Env, which is only used for its system clock. Why can't it use the DB's Env? Maybe needed in future?
  • It uses a std::atomic pointer but in StartIOTrace it is accessed in a way that could generate race conditions (independent check and set).

periodic_work_scheduler

Singleton. Not a concern.

delete_scheduler

Could arguably be made raw ptr because DeleteScheduler owned by SstFileManager, but ownership is singleton, so not really a concern.

rate_limiter

NowMicrosMonotonic is fishy because we have a non-static member function taking a parameter that is the same as a field. Since it's const shared_ptr&, it's not a performance concern, but worth cleaning up.

This is also a weird case because from the public API, we always construct with default SystemClock. Swapping out the implementation is only needed for testing, where object lifetime safety is less concerning. But it's hard to imagine lots of rate limiters being constructed. OK to keep shared_ptr.

histogram_windowing

This appears to be test-only code. ¯\_(ツ)_/¯

@akankshamahajan15
Copy link
Contributor

flush_job
internal_stats
io_tracer

These are internal objects that AFAIK should not be shared by DBs nor outlive them. Although they are probably long-lived enough not to be a concern, I would (on first assessment) prefer to see raw pointers for these.

io_tracer has additional concerns perhaps beyond the scope here (@akankshamahajan15):

  • DB::StartIOTrace takes an Env, which is only used for its system clock. Why can't it use the DB's Env? Maybe needed in future?
  • It uses a std::atomic pointer but in StartIOTrace it is accessed in a way that could generate race conditions (independent check and set).

periodic_work_scheduler

Singleton. Not a concern.

delete_scheduler

Could arguably be made raw ptr because DeleteScheduler owned by SstFileManager, but ownership is singleton, so not really a concern.

rate_limiter

NowMicrosMonotonic is fishy because we have a non-static member function taking a parameter that is the same as a field. Since it's const shared_ptr&, it's not a performance concern, but worth cleaning up.

This is also a weird case because from the public API, we always construct with default SystemClock. Swapping out the implementation is only needed for testing, where object lifetime safety is less concerning. But it's hard to imagine lots of rate limiters being constructed. OK to keep shared_ptr.

histogram_windowing

This appears to be test-only code. ¯\_(ツ)_/¯

For IOTracer, we don't need env_ separate currently. Env was added because I was planning to call it before DB::Open but that didn't happen and I didn't change the signature of StartIOTracer. I had this discussion with Mark today and he said he will make the required changes.

Removes more vestiges of where the SystemClock was accessed via a shared_ptr when it was not required.  Some "hidden" calls were also cleaned up, where the clock was accessed via the associated Env methods.  After this checkin, the remaining uses of shared_ptr<SystemClock> should be:
- Periodic Work Scheduler
- Rate Limiter
- Some Logger implementations (auto roll logger, Posix, ??)
- SST File Manager
- Backupable DB (via calls to backup_env_)
@mdcallag
Copy link
Contributor

mdcallag commented Mar 7, 2021

Is the problem that shared_ptr was passed by value and the ref count was being incremented/decremented too much? That can be a big problem when done with concurrency.

Copy link
Contributor

@pdillinger pdillinger left a comment

Choose a reason for hiding this comment

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

I suggest adding something like this to class SystemClock:

// At a high level, SystemClocks are tracked by shared_ptr, but some short-lived objects and functions
// (e.g. PerfStepTime) need to use a raw pointer for speed, when a longer-lived object
// (e.g. ImmutableDBOptions) is known to hold a shared_ptr.

uint64_t NowMicrosMonotonic(const std::shared_ptr<SystemClock>& clock) {
return clock->NowNanos() / std::milli::den;
}
uint64_t NowMicrosMonotonic() { return clock_->NowNanos() / std::milli::den; }
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher merged this pull request in 3dff28c.

levichen94 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 18, 2021
…el routines (#8033)

Summary:
For performance purposes, the lower level routines were changed to use a SystemClock* instead of a std::shared_ptr<SystemClock>.  The shared ptr has some performance degradation on certain hardware classes.

For most of the system, there is no risk of the pointer being deleted/invalid because the shared_ptr will be stored elsewhere.  For example, the ImmutableDBOptions stores the Env which has a std::shared_ptr<SystemClock> in it.  The SystemClock* within the ImmutableDBOptions is essentially a "short cut" to gain access to this constant resource.

There were a few classes (PeriodicWorkScheduler?) where the "short cut" property did not hold.  In those cases, the shared pointer was preserved.

Using db_bench readrandom perf_level=3 on my EC2 box, this change performed as well or better than 6.17:

6.17: readrandom   :      28.046 micros/op 854902 ops/sec;   61.3 MB/s (355999 of 355999 found)
6.18: readrandom   :      32.615 micros/op 735306 ops/sec;   52.7 MB/s (290999 of 290999 found)
PR: readrandom   :      27.500 micros/op 871909 ops/sec;   62.5 MB/s (367999 of 367999 found)

(Note that the times for 6.18 are prior to revert of the SystemClock).

Pull Request resolved: facebook/rocksdb#8033

Reviewed By: pdillinger

Differential Revision: D27014563

Pulled By: mrambacher

fbshipit-source-id: ad0459eba03182e454391b5926bf5cdd45657b67
Signed-off-by: Changlong Chen <levisonchen@live.cn>
levichen94 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 18, 2021
…el routines (#8033)

Summary:
For performance purposes, the lower level routines were changed to use a SystemClock* instead of a std::shared_ptr<SystemClock>.  The shared ptr has some performance degradation on certain hardware classes.

For most of the system, there is no risk of the pointer being deleted/invalid because the shared_ptr will be stored elsewhere.  For example, the ImmutableDBOptions stores the Env which has a std::shared_ptr<SystemClock> in it.  The SystemClock* within the ImmutableDBOptions is essentially a "short cut" to gain access to this constant resource.

There were a few classes (PeriodicWorkScheduler?) where the "short cut" property did not hold.  In those cases, the shared pointer was preserved.

Using db_bench readrandom perf_level=3 on my EC2 box, this change performed as well or better than 6.17:

6.17: readrandom   :      28.046 micros/op 854902 ops/sec;   61.3 MB/s (355999 of 355999 found)
6.18: readrandom   :      32.615 micros/op 735306 ops/sec;   52.7 MB/s (290999 of 290999 found)
PR: readrandom   :      27.500 micros/op 871909 ops/sec;   62.5 MB/s (367999 of 367999 found)

(Note that the times for 6.18 are prior to revert of the SystemClock).

Pull Request resolved: facebook/rocksdb#8033

Reviewed By: pdillinger

Differential Revision: D27014563

Pulled By: mrambacher

fbshipit-source-id: ad0459eba03182e454391b5926bf5cdd45657b67
Signed-off-by: Changlong Chen <levisonchen@live.cn>
levichen94 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 18, 2021
…el routines (#8033)

Summary:
For performance purposes, the lower level routines were changed to use a SystemClock* instead of a std::shared_ptr<SystemClock>.  The shared ptr has some performance degradation on certain hardware classes.

For most of the system, there is no risk of the pointer being deleted/invalid because the shared_ptr will be stored elsewhere.  For example, the ImmutableDBOptions stores the Env which has a std::shared_ptr<SystemClock> in it.  The SystemClock* within the ImmutableDBOptions is essentially a "short cut" to gain access to this constant resource.

There were a few classes (PeriodicWorkScheduler?) where the "short cut" property did not hold.  In those cases, the shared pointer was preserved.

Using db_bench readrandom perf_level=3 on my EC2 box, this change performed as well or better than 6.17:

6.17: readrandom   :      28.046 micros/op 854902 ops/sec;   61.3 MB/s (355999 of 355999 found)
6.18: readrandom   :      32.615 micros/op 735306 ops/sec;   52.7 MB/s (290999 of 290999 found)
PR: readrandom   :      27.500 micros/op 871909 ops/sec;   62.5 MB/s (367999 of 367999 found)

(Note that the times for 6.18 are prior to revert of the SystemClock).

Pull Request resolved: facebook/rocksdb#8033

Reviewed By: pdillinger

Differential Revision: D27014563

Pulled By: mrambacher

fbshipit-source-id: ad0459eba03182e454391b5926bf5cdd45657b67
Signed-off-by: Changlong Chen <levisonchen@live.cn>
levichen94 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 18, 2021
…el routines (#8033)

Summary:
For performance purposes, the lower level routines were changed to use a SystemClock* instead of a std::shared_ptr<SystemClock>.  The shared ptr has some performance degradation on certain hardware classes.

For most of the system, there is no risk of the pointer being deleted/invalid because the shared_ptr will be stored elsewhere.  For example, the ImmutableDBOptions stores the Env which has a std::shared_ptr<SystemClock> in it.  The SystemClock* within the ImmutableDBOptions is essentially a "short cut" to gain access to this constant resource.

There were a few classes (PeriodicWorkScheduler?) where the "short cut" property did not hold.  In those cases, the shared pointer was preserved.

Using db_bench readrandom perf_level=3 on my EC2 box, this change performed as well or better than 6.17:

6.17: readrandom   :      28.046 micros/op 854902 ops/sec;   61.3 MB/s (355999 of 355999 found)
6.18: readrandom   :      32.615 micros/op 735306 ops/sec;   52.7 MB/s (290999 of 290999 found)
PR: readrandom   :      27.500 micros/op 871909 ops/sec;   62.5 MB/s (367999 of 367999 found)

(Note that the times for 6.18 are prior to revert of the SystemClock).

Pull Request resolved: facebook/rocksdb#8033

Reviewed By: pdillinger

Differential Revision: D27014563

Pulled By: mrambacher

fbshipit-source-id: ad0459eba03182e454391b5926bf5cdd45657b67
Signed-off-by: Changlong Chen <levisonchen@live.cn>
mm304321141 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 23, 2021
…el routines (#8033)

Summary:
For performance purposes, the lower level routines were changed to use a SystemClock* instead of a std::shared_ptr<SystemClock>.  The shared ptr has some performance degradation on certain hardware classes.

For most of the system, there is no risk of the pointer being deleted/invalid because the shared_ptr will be stored elsewhere.  For example, the ImmutableDBOptions stores the Env which has a std::shared_ptr<SystemClock> in it.  The SystemClock* within the ImmutableDBOptions is essentially a "short cut" to gain access to this constant resource.

There were a few classes (PeriodicWorkScheduler?) where the "short cut" property did not hold.  In those cases, the shared pointer was preserved.

Using db_bench readrandom perf_level=3 on my EC2 box, this change performed as well or better than 6.17:

6.17: readrandom   :      28.046 micros/op 854902 ops/sec;   61.3 MB/s (355999 of 355999 found)
6.18: readrandom   :      32.615 micros/op 735306 ops/sec;   52.7 MB/s (290999 of 290999 found)
PR: readrandom   :      27.500 micros/op 871909 ops/sec;   62.5 MB/s (367999 of 367999 found)

(Note that the times for 6.18 are prior to revert of the SystemClock).

Pull Request resolved: facebook/rocksdb#8033

Reviewed By: pdillinger

Differential Revision: D27014563

Pulled By: mrambacher

fbshipit-source-id: ad0459eba03182e454391b5926bf5cdd45657b67
Signed-off-by: Changlong Chen <levisonchen@live.cn>
mm304321141 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 23, 2021
…el routines (#8033)

Summary:
For performance purposes, the lower level routines were changed to use a SystemClock* instead of a std::shared_ptr<SystemClock>.  The shared ptr has some performance degradation on certain hardware classes.

For most of the system, there is no risk of the pointer being deleted/invalid because the shared_ptr will be stored elsewhere.  For example, the ImmutableDBOptions stores the Env which has a std::shared_ptr<SystemClock> in it.  The SystemClock* within the ImmutableDBOptions is essentially a "short cut" to gain access to this constant resource.

There were a few classes (PeriodicWorkScheduler?) where the "short cut" property did not hold.  In those cases, the shared pointer was preserved.

Using db_bench readrandom perf_level=3 on my EC2 box, this change performed as well or better than 6.17:

6.17: readrandom   :      28.046 micros/op 854902 ops/sec;   61.3 MB/s (355999 of 355999 found)
6.18: readrandom   :      32.615 micros/op 735306 ops/sec;   52.7 MB/s (290999 of 290999 found)
PR: readrandom   :      27.500 micros/op 871909 ops/sec;   62.5 MB/s (367999 of 367999 found)

(Note that the times for 6.18 are prior to revert of the SystemClock).

Pull Request resolved: facebook/rocksdb#8033

Reviewed By: pdillinger

Differential Revision: D27014563

Pulled By: mrambacher

fbshipit-source-id: ad0459eba03182e454391b5926bf5cdd45657b67
Signed-off-by: Changlong Chen <levisonchen@live.cn>
mm304321141 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 23, 2021
…el routines (#8033)

Summary:
For performance purposes, the lower level routines were changed to use a SystemClock* instead of a std::shared_ptr<SystemClock>.  The shared ptr has some performance degradation on certain hardware classes.

For most of the system, there is no risk of the pointer being deleted/invalid because the shared_ptr will be stored elsewhere.  For example, the ImmutableDBOptions stores the Env which has a std::shared_ptr<SystemClock> in it.  The SystemClock* within the ImmutableDBOptions is essentially a "short cut" to gain access to this constant resource.

There were a few classes (PeriodicWorkScheduler?) where the "short cut" property did not hold.  In those cases, the shared pointer was preserved.

Using db_bench readrandom perf_level=3 on my EC2 box, this change performed as well or better than 6.17:

6.17: readrandom   :      28.046 micros/op 854902 ops/sec;   61.3 MB/s (355999 of 355999 found)
6.18: readrandom   :      32.615 micros/op 735306 ops/sec;   52.7 MB/s (290999 of 290999 found)
PR: readrandom   :      27.500 micros/op 871909 ops/sec;   62.5 MB/s (367999 of 367999 found)

(Note that the times for 6.18 are prior to revert of the SystemClock).

Pull Request resolved: facebook/rocksdb#8033

Reviewed By: pdillinger

Differential Revision: D27014563

Pulled By: mrambacher

fbshipit-source-id: ad0459eba03182e454391b5926bf5cdd45657b67
Signed-off-by: Changlong Chen <levisonchen@live.cn>
mm304321141 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 23, 2021
…el routines (#8033)

Summary:
For performance purposes, the lower level routines were changed to use a SystemClock* instead of a std::shared_ptr<SystemClock>.  The shared ptr has some performance degradation on certain hardware classes.

For most of the system, there is no risk of the pointer being deleted/invalid because the shared_ptr will be stored elsewhere.  For example, the ImmutableDBOptions stores the Env which has a std::shared_ptr<SystemClock> in it.  The SystemClock* within the ImmutableDBOptions is essentially a "short cut" to gain access to this constant resource.

There were a few classes (PeriodicWorkScheduler?) where the "short cut" property did not hold.  In those cases, the shared pointer was preserved.

Using db_bench readrandom perf_level=3 on my EC2 box, this change performed as well or better than 6.17:

6.17: readrandom   :      28.046 micros/op 854902 ops/sec;   61.3 MB/s (355999 of 355999 found)
6.18: readrandom   :      32.615 micros/op 735306 ops/sec;   52.7 MB/s (290999 of 290999 found)
PR: readrandom   :      27.500 micros/op 871909 ops/sec;   62.5 MB/s (367999 of 367999 found)

(Note that the times for 6.18 are prior to revert of the SystemClock).

Pull Request resolved: facebook/rocksdb#8033

Reviewed By: pdillinger

Differential Revision: D27014563

Pulled By: mrambacher

fbshipit-source-id: ad0459eba03182e454391b5926bf5cdd45657b67
Signed-off-by: Changlong Chen <levisonchen@live.cn>
facebook-github-bot pushed a commit that referenced this pull request Aug 31, 2021
…cutionHandler` (#8729)

Summary:
All/most trace related APIs directly use `SystemClock*` (#8033). Do the same in `TraceExecutionHandler`.

Pull Request resolved: #8729

Test Plan: None

Reviewed By: zhichao-cao

Differential Revision: D30672159

Pulled By: autopear

fbshipit-source-id: 017db4912c6ac1cfede842b8b122cf569a394f25
yoori pushed a commit to yoori/rocksdb that referenced this pull request Nov 26, 2023
…cutionHandler` (#8729)

Summary:
All/most trace related APIs directly use `SystemClock*` (facebook/rocksdb#8033). Do the same in `TraceExecutionHandler`.

Pull Request resolved: facebook/rocksdb#8729

Test Plan: None

Reviewed By: zhichao-cao

Differential Revision: D30672159

Pulled By: autopear

fbshipit-source-id: 017db4912c6ac1cfede842b8b122cf569a394f25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants