diff options
| author | babenko <[email protected]> | 2026-06-06 23:52:00 +0300 |
|---|---|---|
| committer | babenko <[email protected]> | 2026-06-07 00:16:49 +0300 |
| commit | f10c7206fb31af8057446bceef9707aabaa9456e (patch) | |
| tree | e3283bfe824beda100b4a598006fdbc2fe221725 /library/cpp/yt/system/benchmarks/process.cpp | |
| parent | 51122ce7f1b07aa13c32b9977a8aad5759854b15 (diff) | |
Cache process/thread id getters and use them in TError origin capture
## Motivation
Profiling the YT master Automaton thread showed TOriginAttributes::Capture (run on every non-OK TError) spending ~60% of its time in a getpid() syscall — uncached on glibc >= 2.25. NYT::GetCurrentThreadId() (gettid) feeds hot thread-affinity / log-manager checks on the same thread.
## Changes
- New library/cpp/yt/system/process_id.* with cached GetProcessId(); GetSystemThreadId() now caches the kernel tid in TLS. Both caches reset in the child after fork.
- Moved thread_name.{h,cpp} from misc to system.
- Removed GetCurrentProcessId/GetCurrentThreadId shims from yt/yt/core/misc/proc.{h,cpp}; migrated all callers to NYT::GetProcessId / NYT::GetSystemThreadId.
- TOriginAttributes::Capture uses the cached getters; recorded Tid is now the real kernel tid (matches perf/ps).
- Added microbenchmarks (library/cpp/yt/system/benchmarks, yt/yt/core/benchmarks/error.cpp).
## Microbenchmarks (release)
| | before | after |
|---|---|---|
| getpid | 101 ns | 0.33 ns |
| gettid | 102 ns | 1.64 ns |
| Capture | 161 ns | 50 ns |
| failed TError | 221 ns | 74 ns |
commit_hash:ee37ae57d61a5a2dd33daee935270f4bb93b7ff9
Diffstat (limited to 'library/cpp/yt/system/benchmarks/process.cpp')
| -rw-r--r-- | library/cpp/yt/system/benchmarks/process.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/library/cpp/yt/system/benchmarks/process.cpp b/library/cpp/yt/system/benchmarks/process.cpp new file mode 100644 index 00000000000..74b4b6b1e13 --- /dev/null +++ b/library/cpp/yt/system/benchmarks/process.cpp @@ -0,0 +1,35 @@ +#include <benchmark/benchmark.h> + +#include <library/cpp/yt/system/process_id.h> + +#include <util/system/getpid.h> + +namespace NYT { +namespace { + +//////////////////////////////////////////////////////////////////////////////// + +void BM_GetProcessId(benchmark::State& state) +{ + // Cached getpid: only the first call hits the kernel. + for (auto _ : state) { + benchmark::DoNotOptimize(GetProcessId()); + } +} + +BENCHMARK(BM_GetProcessId); + +void BM_RawGetPid(benchmark::State& state) +{ + // Uncached getpid syscall (uncached on glibc >= 2.25), for comparison. + for (auto _ : state) { + benchmark::DoNotOptimize(::GetPID()); + } +} + +BENCHMARK(BM_RawGetPid); + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace +} // namespace NYT |
