Skip to content

Add async batched writer to ServerConnection and extract write/flush hooks in Connection#133

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

Add async batched writer to ServerConnection and extract write/flush hooks in Connection#133
ArtifactForms wants to merge 2 commits intomasterfrom
codex/analyze-voxel-server-performance-improvements-7flk0w

Conversation

@ArtifactForms
Copy link
Owner

Motivation

  • Reduce contention and risk of packet corruption by moving outgoing writes off the caller thread into a dedicated writer thread.
  • Improve throughput by batching outbound packets and minimizing per-packet flushes.
  • Provide handover points for subclasses to customize packet serialization and flushing via writePacket and flushOutput.

Description

  • Extracted writePacket(Packet) and flushOutput() from Connection.send() and delegated the original send implementation to call those helpers.
  • Implemented an asynchronous outbound pipeline in ServerConnection with a LinkedBlockingQueue<Packet> outboundQueue, a daemon writerThread and a writeLoop() that polls and batches packets.
  • Overrode ServerConnection.send(Packet) to enqueue packets instead of writing synchronously, and added writeBatch(...) for synchronized batched writes that call writePacket and flushOutput.
  • Ensure clean shutdown by interrupting the writer thread in close() and handling write failures by logging and closing the connection.

Testing

  • Ran the project's automated test suite with ./gradlew test, which completed successfully.
  • Executed automated network integration smoke tests that start the server, establish client connections, exchange packets under load, and verify delivery and clean shutdown; these tests passed.
  • Ran the connection-level unit tests exercising send/write batching and graceful close behavior, which passed.

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