src: add locksCounters() to monitor Web Locks usage#60502
src: add locksCounters() to monitor Web Locks usage#60502IlyasShabi wants to merge 1 commit intonodejs:mainfrom
Conversation
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #60502 +/- ##
==========================================
+ Coverage 88.05% 88.57% +0.51%
==========================================
Files 704 704
Lines 207857 207941 +84
Branches 39964 40054 +90
==========================================
+ Hits 183030 184182 +1152
+ Misses 16806 15803 -1003
+ Partials 8021 7956 -65
🚀 New features to boost your workflow:
|
|
@Qard I put it on process because Locks are shared across the entire process and It follows the same pattern as |
|
I think if we want to add a usage counter to process, it should ideally be generic, e.g. something like Also, it would be nicer if the usage counter can be cleared/started/stopped at some given time instead of being recorded throughout the lifetime of the application. |
|
@joyeecheung I looked at the debug counters pattern, but I think it's better suited for internal testing rather than public API. I'm more with moving this to
IMO I don't think they're a good fit for lock counters. These are lifetime counters, and adding Also, |
| Use [`process.locksCounters()`][] to monitor lock acquisitions, contention, and | ||
| queue sizes across the process. |
There was a problem hiding this comment.
Should be either all singular or all plural no ?
| Use [`process.locksCounters()`][] to monitor lock acquisitions, contention, and | |
| queue sizes across the process. | |
| Use [`process.locksCounters()`][] to monitor lock acquisitions, contentions, and | |
| queue sizes across the process. |
| threadCpuUsage: _threadCpuUsage, | ||
| memoryUsage: _memoryUsage, | ||
| rss, | ||
| locksCounters: _locksCounters, |
There was a problem hiding this comment.
We have cpuUsage, threadCpuUsage, memoryUsage, resourceUsage... maybe we should call it lockUsage instead ?
|
@Qard @joyeecheung I would like to continue on this. Any thought how we can make a decision? |
I meant that it would be nice to have individual counters that can be independently started/paused/stopped, so that e.g. you can use it in tests, as opposed to only having one global counter. For example, if one library A does diagnostics and another library B uses locks in some way, A can start its own counter to monitor code that depends on B, B won't be able to clear that counter unless it gets the handle of it somehow. |
|
I think a better approach is to use DC to get locks metrics #62123 |
Description
This PR introduces
process.locksCounters()to provide real time visibility into Web Locks API usage and contention metrics across the Node.js process.Motivation
Lock contention can be difficult to diagnose in concurrent applications. Other platforms already make this easier,.NET has lock performance counters, Java has JMX for checking thread locks, and Go has mutex profiling.
Node.js added the Web Locks API in v24, but there’s currently no built-in way to see how locks are behaving. The new
process.locksCounters()provide metrics to help developers monitor and debug lock related performance problems.