Make JsonLogger writes asynchronous
- Dominant language
- C++
- Stars
- 14
- Forks
- 12
- Avg merge
- 1h 27m
- Merged PRs (30d)
- 3
Description
## 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.
Contributor guide
Research direction
Start with core/utils/JsonLogger.h and inspect its mutex, ofstream, and existing write path, then review the codebase's lock-free queue style. Define bounded-queue overflow behavior, asynchronous serialization and file I/O, and clean shutdown draining; add the requested before/after log-call latency benchmark. Afterward, update the JSON Data Export documentation wording to describe the async design.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100