Skip to content

Conversation

@kewang1024
Copy link
Contributor

Summary:
New metrics added to monitor time spent waiting for shard mutexes:

  • kMetricMemoryCacheNumShardMutexWaitClocks: Total clocks waiting for shard mutexes.
  • kMetricMemoryCacheShardMutexWaitTimeMs: Milliseconds waited, based on ~3GHz CPU.

Differential Revision: D92068037

@netlify
Copy link

netlify bot commented Feb 2, 2026

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit fd8bda8
🔍 Latest deploy log https://app.netlify.com/projects/meta-velox/deploys/6981262dc26fc3000896f410

@meta-codesync
Copy link

meta-codesync bot commented Feb 2, 2026

@kewang1024 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D92068037.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 2, 2026
…6203)

Summary:

New metrics added to monitor time spent waiting for shard mutexes:

- `kMetricMemoryCacheNumShardMutexWaitClocks`: Total clocks waiting for shard mutexes.
- `kMetricMemoryCacheShardMutexWaitTimeMs`: Milliseconds waited, based on ~3GHz CPU.

Differential Revision: D92068037
Copy link
Contributor

@xiaoxmeng xiaoxmeng left a comment

Choose a reason for hiding this comment

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

@kewang1024 thanks for the change. Left some comments. Do we really need to count these stats?


// Clocks spent waiting to acquire shard mutexes, since last counter retrieval
DEFINE_METRIC(
kMetricMemoryCacheNumShardMutexWaitClocks,
Copy link
Contributor

Choose a reason for hiding this comment

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

can you update metrics.rst for the new metrics?

kMetricMemoryCacheNumShardMutexWaitClocks,
facebook::velox::StatType::SUM);

// Time in milliseconds spent waiting to acquire shard mutexes, since last
Copy link
Contributor

Choose a reason for hiding this comment

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

I think walltime is sufficient.

s/kMetricMemoryCacheShardMutexWaitTimeMs/kMetricMemoryCacheLockWaitTimeUs/?

std::atomic<uint64_t> allocClocks_{0};
// Tracker of cumulative clocks spent waiting to acquire shard mutex.
// Mutable to allow updating from const methods like exists().
mutable std::atomic<uint64_t> shardMutexWaitClocks_{0};
Copy link
Contributor

Choose a reason for hiding this comment

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

std::atomic_uint64_t shardLockWaitUs_

/// lifetime for entries in cache.
int64_t sumEvictScore{0};
/// Cumulative clocks spent waiting to acquire shard mutexes.
uint64_t shardMutexWaitClocks{0};
Copy link
Contributor

Choose a reason for hiding this comment

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

s/shardMutexWaitClocks/shardLockWaitUs/

public:
TimedLockGuard(std::mutex& mutex, std::atomic<uint64_t>& waitClocks)
: lock_(mutex, std::defer_lock) {
ClockTimer timer(waitClocks);
Copy link
Contributor

Choose a reason for hiding this comment

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

use NanosecondTimer?

// Helper that uses ClockTimer to measure the lock acquisition time.
class TimedLockGuard {
public:
TimedLockGuard(std::mutex& mutex, std::atomic<uint64_t>& waitClocks)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's have a per-thread local counter for this? Like use ConcurrentCounter in velox/common/base/ConcurrentCounter.h?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants