Skip to content

Make JsonLogger writes asynchronous #80

Description

@chizy7

Context

JsonLogger (core/utils/JsonLogger.h) serializes every write behind m_mutex and writes synchronously to an std::ofstream. Any thread that logs, including strategy and market data paths when --json-log is enabled, pays mutex contention plus file I/O on the calling thread. The docs were recently corrected to say exactly this (PR #73), but the better fix is removing the overhead.

What to do

  • Move serialization and file I/O to a dedicated writer thread fed by a bounded queue (an SPSC or MPSC ring buffer fits the existing lock-free style of the codebase).
  • Define overflow behavior explicitly (drop with a counter, or block) so the hot path never does unbounded work.
  • Flush and drain the queue on shutdown so no events are lost on clean exit.
  • Add a benchmark comparing log-call latency before and after.

Notes

After this lands, update the JSON Data Export doc's thread-safety wording again to describe the async design.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestperformanceLatency, throughput, or resource usage

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions