Skip to content

Replace per-call log threads with queued background writer#30

Open
harbor208199 wants to merge 1 commit intomichal-kapala:masterfrom
harbor208199:log-queue-worker
Open

Replace per-call log threads with queued background writer#30
harbor208199 wants to merge 1 commit intomichal-kapala:masterfrom
harbor208199:log-queue-worker

Conversation

@harbor208199
Copy link
Copy Markdown
Contributor

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.

@michal-kapala michal-kapala self-requested a review November 23, 2025 14:52
@michal-kapala michal-kapala added the enhancement New feature or request label Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants