Replace per-call log threads with queued background writer#30
Open
harbor208199 wants to merge 1 commit intomichal-kapala:masterfrom
Open
Replace per-call log threads with queued background writer#30harbor208199 wants to merge 1 commit intomichal-kapala:masterfrom
harbor208199 wants to merge 1 commit intomichal-kapala:masterfrom
Conversation
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.
Previously each WriteLine / WriteRmcLine spun up a brand-new thread to flush logBuffer / logPackets. Under real traffic this caused hundreds of short-lived threads, wasted CPU, and risked dropping log data when multiple workers raced to clear the shared buffer. This update moves logging to a single background worker that drains a queue, so disk writes are serialized and log entries are preserved without thread storms.
Added a BlockingCollection-backed queue and one background worker to handle all log and packet writes.
Removed per-call new Thread(tSaveLog) usage, logging now enqueues work and returns immediately.
Kept existing outputs ( log.txt , packetLog.bin ) and synchronized file appends inside the worker.
Cleans up queued items on clear and avoids buffer races that could lose log entries.
Background thread is marked as a daemon so it won't block shutdown.