Skip to content

[Medium] Synchronous disk I/O on every log write — blocks the event loop #84

@ether-btc

Description

@ether-btc

Severity: Medium

Location: src/agent.ts:165 (readTodayLog), src/heartbeat.ts:165-166 (all heartbeat logging calls)

Description:
readTodayLog() is called on every /api/logs request with no caching. Additionally, all appendLog() calls throughout heartbeat.ts are synchronous fs.appendFileSync operations that block the event loop. Under high task volume, these synchronous disk writes can add latency to heartbeat ticks and WebSocket message handling.

For example in heartbeat.ts:237-252 (the tick() function), every poll cycle writes 2-3 log entries synchronously. With polling at 10s intervals, that's 14,000+ synchronous disk writes per day.

Suggested Fix:

  1. Add a write buffer/batch for log entries — collect entries in memory, flush every 5-10 seconds or N entries
  2. Add an LRU read cache for readTodayLog() with a 5-second TTL
  3. Make appendLog asynchronous or use a worker thread for disk I/O

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions