Gemma 4 26B-A4B inference in ~2 GB of RAM on any M-series MacBook
Swift apple-silicongemmagemma4gemma4-26b-a4bgpgpullmllm-inferencelocal-aimacosmetalon-device-aion-device-llmswift
Size the server listen backlog to the connection cap (#153)
Andrey Mikhaylov1206ff24f5da
diff --git a/Sources/TurboFieldfareServer/Core/HTTPServer.swift b/Sources/TurboFieldfareServer/Core/HTTPServer.swiftindex 539d9218..2bf92b17 100644--- a/Sources/TurboFieldfareServer/Core/HTTPServer.swift+++ b/Sources/TurboFieldfareServer/Core/HTTPServer.swift@@ -56,7 +56,12 @@ public actor TurboFieldfareHTTPServer {let attachmentRoot = self.attachmentRootlet idleTimeout = self.idleTimeoutlet bootstrap = ServerBootstrap(group: group)- .serverChannelOption(ChannelOptions.backlog, value: 16)+ // The listen queue is sized to the connection cap so a burst of+ // connects up to the cap waits for the accept loop instead of+ // overflowing, which macOS 27 answers with RST (issue #151).+ .serverChannelOption(+ ChannelOptions.backlog,+ value: Int32(TurboFieldfareHTTPServer.maximumConnections)).serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1).childChannelInitializer { channel inchildChannels.insert(channel)diff --git a/Tests/TurboFieldfareServer/ServerIngressHardeningTests.swift b/Tests/TurboFieldfareServer/ServerIngressHardeningTests.swiftindex 7a997143..42ff7111 100644--- a/Tests/TurboFieldfareServer/ServerIngressHardeningTests.swift+++ b/Tests/TurboFieldfareServer/ServerIngressHardeningTests.swift@@ -332,6 +332,20 @@ private actor EchoBackend: ServerInferenceBackend {#expect(await server.acceptedConnectionCount == cap)try await server.shutdown()}++ /// Pins the listen backlog to the connection cap. With a backlog of 16+ /// under a cap of 128, a burst of connects overflowed the listen queue;+ /// macOS 27 answers that with RST, so `connectionsBeyondTheCapAreClosed`+ /// failed there with ECONNRESET on connect (issue #151), while macOS 26+ /// only stalls the burst and the race stays invisible.+ @Test func listenBacklogCoversTheConnectionCap() async throws {+ let server = TurboFieldfareHTTPServer(+ modelID: "test-model", queueLimit: 1, backend: EchoBackend())+ let channel = try await server.start(port: 0)+ let backlog = try await channel.getOption(ChannelOptions.backlog)+ #expect(backlog >= Int32(TurboFieldfareHTTPServer.maximumConnections))+ try await server.shutdown()+ }}/// The sweep is what reclaims staging directories left by a process that died