Skip to content

Add outbound writer thread with batching and non-blocking send; extract Connection write/flush#132

Open
ArtifactForms wants to merge 2 commits intomasterfrom
codex/analyze-voxel-server-performance-improvements
Open

Add outbound writer thread with batching and non-blocking send; extract Connection write/flush#132
ArtifactForms wants to merge 2 commits intomasterfrom
codex/analyze-voxel-server-performance-improvements

Conversation

@ArtifactForms
Copy link
Owner

Motivation

  • Reduce contention and avoid blocking the read thread by moving packet writes off the read path and batching outbound packets.
  • Make low-level packet write and flush operations overridable/extractable for reuse and testing.

Description

  • Extracted writePacket(Packet) and flushOutput() protected methods from Connection.send and replaced the inlined write/flush calls with delegations to those methods in Connection.
  • Reworked ServerConnection to use a non-blocking outbound queue (LinkedBlockingQueue<Packet>) and a dedicated writer thread that polls the queue, batches up to MAX_OUTBOUND_BATCH_SIZE packets, and writes them via writeBatch.
  • Implemented a writeLoop that polls with a timeout (WRITER_POLL_TIMEOUT_MS) to allow graceful shutdown and drains available packets into batches for efficient network writes.
  • Overrode send(Packet) in ServerConnection to enqueue outbound packets instead of performing synchronous I/O, and updated close() to interrupt the writer thread and unregister the connection from the PlayerManager.

Testing

  • Ran the project's automated unit test suite and server integration tests against the modified networking code and observed all tests passing.
  • Performed basic concurrency and shutdown validation by exercising client connect/send/close flows in integration tests which completed without deadlocks or uncaught exceptions.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant