Skip to content

Make log level checks lock-free via permanent loggers. - #5349

Merged
graydon merged 1 commit into
stellar:masterfrom
dmkozh:logging_opt
Jul 24, 2026
Merged

Make log level checks lock-free via permanent loggers.#5349
graydon merged 1 commit into
stellar:masterfrom
dmkozh:logging_opt

Conversation

@dmkozh

@dmkozh dmkozh commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Description

Make log level checks lock-free via permanent loggers.

Every CLOG_* invocation fetches its respective logger instance in order to check if we should log this line, and the getter used to be guarded by a recursive mutex lock. So we kept serializing every disabled log statement, which hindered parallelization for the code paths with frequent trace/debug logs.

Now each partition has a single permanent logger, created on first use and never destroyed or replaced (logging rotations/reconfigurations now are done at the sink level, instead of the logger level). Additionally, we avoid a shared ptr copy on every logger access, as we now we can just safely return a non-owning pointer to it.

The logging level checks per logger still have to be thread-safe, as the level may be changed in the middle of the app lifetime. We remove SPDLOG_NO_ATOMIC_LEVELS to achieve that, which simply uses very fast relaxed atomic checks.

This doesn't have too large impact right now (~-3ms on the local benchmarks), but it will become more meaningful as we land more apply path parallelization.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

Copilot AI review requested due to automatic review settings July 14, 2026 23:21
@dmkozh
dmkozh force-pushed the logging_opt branch 2 times, most recently from 1165292 to 6b85eb5 Compare July 14, 2026 23:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Makes disabled log-level checks lock-free by retaining permanent logger instances and reconfiguring their sinks.

Changes:

  • Adds permanent per-partition loggers with mutable distribution sinks.
  • Returns non-owning logger pointers to avoid shared-pointer copies.
  • Enables atomic runtime log-level updates.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/util/SpdlogTweaks.h Enables atomic logger levels.
src/util/Logging.h Documents permanent loggers and updates getter APIs.
src/util/Logging.cpp Implements permanent loggers and sink reconfiguration.

Comment thread src/util/Logging.cpp
Every CLOG_* invocation fetches its respective logger instance in order to check if we should log this line, and the getter used to be guarded by a recursive mutex lock. So we kept serializing every disabled log statement, which hindered parallelization for the code paths with frequent trace/debug logs.

Now each partition has a single permanent logger, created on first use and never destroyed or replaced (logging rotations/reconfigurations now are done at the sink level, instead of the logger level). Additionally, we avoid a shared ptr copy on every logger access, as we now we can just safely return a non-owning pointer to it.

The logging level checks per logger still have to be thread-safe, as the level may be changed in the middle of the app lifetime. We remove SPDLOG_NO_ATOMIC_LEVELS to achieve that, which simply uses very fast relaxed atomic checks.

@graydon graydon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@dmkozh
dmkozh enabled auto-merge July 22, 2026 21:55
@dmkozh
dmkozh added this pull request to the merge queue Jul 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jul 23, 2026
@graydon
graydon added this pull request to the merge queue Jul 24, 2026
Merged via the queue into stellar:master with commit e83c922 Jul 24, 2026
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants