fix(backtest): bound every log tail to the final 256 KB - #19
Open
Marinski wants to merge 1 commit into
Open
Conversation
The live /tail endpoint read entire log files into memory on every poll:
_tail_dir_log and get_tail's run.log block called a whole-file reader,
then decoded and split the result. A Strategy Tester log grows to
gigabytes WHILE the run that is being polled writes it, so each poll
allocated the file plus a decoded copy plus a line list — 45-65 s per
call measured against a 1.9 GB log, with the GIL held through the decode.
Every thread in the process stalled behind it: /ping took 25-50 s, the
container healthcheck flapped, clients timed out, and a healthy terminal
was indistinguishable from a wedged one. (_tail_terminal_log, the
failure-path tail, had the same unbounded read.)
_read_tail_text seeks to the final 256 KB, aligned to a 2-byte boundary
so UTF-16 code units stay intact, sniffs UTF-16 from a BOM or a NUL
second byte, and drops the truncated first line of a mid-file window.
Both tail helpers and the run.log block now use it; whole-file reads
remain only where the whole file is genuinely needed (INI parse, report
parse).
_tail_dir_log also inherits the two picker rules _tail_terminal_log
already had and it predated: newest by mtime, never metaeditor.log —
the alphabetical pick returned a stale compile log ('m' > '2') instead
of the run being polled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The live
/tailendpoint read entire log files into memory on every poll:_tail_dir_logandget_tail's run.log block called a whole-file reader, then decoded and split the result.A Strategy Tester log grows to gigabytes while the run being polled writes it, so each poll allocated the file + a decoded copy + a line list — measured 45–65 s per call against a 1.9 GB log, with the GIL held through the decode. Every thread in the process stalled behind it:
/pingtook 25–50 s, the container healthcheck flapped, clients timed out, and a healthy terminal was indistinguishable from a wedged one._tail_terminal_log(the failure-path tail) had the same unbounded read.Fix
_read_tail_text: seek to the final 256 KB, 2-byte aligned so UTF-16 code units stay intact; sniff UTF-16 from a BOM or NUL second byte; drop the truncated first line of a mid-file window. Used by both tail helpers and the run.log block._tail_dir_loginherits the two picker rules_tail_terminal_logalready had and it predated: newest by mtime, nevermetaeditor.log(the alphabetical pick returned a stale compile log — 'm' > '2' — instead of the run being polled).Tests
12 new tests: bounded-window correctness (truncated first line dropped, UTF-16 alignment via a non-ASCII log, small-file passthrough, missing file), bounded
_tail_terminal_log, and_tail_dir_log's mtime pick / metaeditor exclusion / bounded read / empty dir. Full suite: 432 passed.