summaryrefslogtreecommitdiff
path: root/src/Server
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2026-01-10 16:08:23 -0500
committerRobby Zambito <contact@robbyzambito.me>2026-01-10 16:42:43 -0500
commit0861703ddce8c46b732cfb773aabe9daa9c5da48 (patch)
tree7b40b541547da898546a1f2e62f86dadf1dd441e /src/Server
parent99ea7556581a678684e30202a8eee654a001588a (diff)
Sleep to go faster
The problem was I was basically flushing twice for every message when doing request reply. This gives the sender the opportunity to finish writing a full message to the queue, which we then check for before flushing. This makes request reply latency benchmarks go down from like 90ms to 200us.
Diffstat (limited to 'src/Server')
-rw-r--r--src/Server/Client.zig10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Server/Client.zig b/src/Server/Client.zig
index 77034fd..6ad1804 100644
--- a/src/Server/Client.zig
+++ b/src/Server/Client.zig
@@ -40,6 +40,16 @@ pub fn start(self: *Client, io: std.Io) !void {
std.debug.assert(self.to_client.end == 0);
while (true) {
self.to_client.end = try self.recv_queue.get(io, self.to_client.buffer, 1);
+ // Wait 1 nanosecond to see if more data is in the queue.
+ // If there is, add it to the write buffer before sending it.
+ // The reason for this is because if we send the first chunk as soon as we get it,
+ // we will likely be sending a partial message, which will end up being way slower.
+ try io.sleep(.fromNanoseconds(1), .awake);
+ self.to_client.end += try self.recv_queue.get(
+ io,
+ self.to_client.buffer[self.to_client.end..],
+ 0,
+ );
try self.to_client.flush();
}
}