stablise 1000 TCP connections alloc test (#1566)

Motivation:

The 1000 TCP connections allocation counter test did way too many thread
crosses and other things that allocated for unrelated reasons.

Modifications:

Remove those.

Result:

Much more stable
This commit is contained in:
Johannes Weiss 2020-06-23 13:11:43 +01:00 committed by GitHub
parent c03dd9c5f1
commit 01e0e0cef4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 18 deletions

View File

@ -23,14 +23,23 @@ fileprivate final class ReceiveAndCloseHandler: ChannelInboundHandler {
precondition(byteBuffer.readableBytes == 1) precondition(byteBuffer.readableBytes == 1)
context.channel.close(promise: nil) context.channel.close(promise: nil)
} }
func errorCaught(context: ChannelHandlerContext, error: Error) {
fatalError("unexpected \(error)")
}
} }
func run(identifier: String) { func run(identifier: String) {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer {
try! group.syncShutdownGracefully()
}
let serverChannel = try! ServerBootstrap(group: group) let serverChannel = try! ServerBootstrap(group: group)
.serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1)
.childChannelInitializer { channel in .childChannelInitializer { channel in
channel.pipeline.addHandler(ReceiveAndCloseHandler()) channel.pipeline.addHandler(ReceiveAndCloseHandler())
}.bind(to: localhostPickPort).wait() }.bind(host: "127.0.0.1", port: 0).wait()
defer { defer {
try! serverChannel.close().wait() try! serverChannel.close().wait()
} }
@ -39,16 +48,19 @@ func run(identifier: String) {
measure(identifier: identifier) { measure(identifier: identifier) {
let numberOfIterations = 1000 let numberOfIterations = 1000
let serverAddress = serverChannel.localAddress!
let buffer = ByteBuffer(integer: 1, as: UInt8.self)
let el = group.next()
for _ in 0 ..< numberOfIterations { for _ in 0 ..< numberOfIterations {
let clientChannel = try! clientBootstrap.connect(to: serverChannel.localAddress!) try! el.flatSubmit {
.wait() clientBootstrap.connect(to: serverAddress).flatMap { clientChannel in
// Send a byte to make sure everything is really open. // Send a byte to make sure everything is really open.
var buffer = clientChannel.allocator.buffer(capacity: 1) clientChannel.writeAndFlush(buffer).flatMap {
buffer.writeInteger(1, as: UInt8.self) clientChannel.closeFuture
clientChannel.writeAndFlush(NIOAny(buffer), promise: nil) }
// Wait for the close to come from the server side. }
try! clientChannel.closeFuture.wait() }.wait()
} }
return numberOfIterations return numberOfIterations
} }

View File

@ -37,7 +37,7 @@ services:
- MAX_ALLOCS_ALLOWED_udp_1000_reqs_1_conn=16250 - MAX_ALLOCS_ALLOWED_udp_1000_reqs_1_conn=16250
- MAX_ALLOCS_ALLOWED_udp_1_reqs_1000_conn=226050 - MAX_ALLOCS_ALLOWED_udp_1_reqs_1000_conn=226050
- MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=4100 - MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=4100
- MAX_ALLOCS_ALLOWED_1000_tcpconnections=196800 - MAX_ALLOCS_ALLOWED_1000_tcpconnections=178010
- MAX_ALLOCS_ALLOWED_1000_udpbootstraps=4000 - MAX_ALLOCS_ALLOWED_1000_udpbootstraps=4000
- MAX_ALLOCS_ALLOWED_1000_udpconnections=115050 - MAX_ALLOCS_ALLOWED_1000_udpconnections=115050
- MAX_ALLOCS_ALLOWED_1000_udp_reqs=16050 - MAX_ALLOCS_ALLOWED_1000_udp_reqs=16050

View File

@ -36,7 +36,7 @@ services:
- MAX_ALLOCS_ALLOWED_udp_1000_reqs_1_conn=16250 - MAX_ALLOCS_ALLOWED_udp_1000_reqs_1_conn=16250
- MAX_ALLOCS_ALLOWED_udp_1_reqs_1000_conn=226050 - MAX_ALLOCS_ALLOWED_udp_1_reqs_1000_conn=226050
- MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=4100 - MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=4100
- MAX_ALLOCS_ALLOWED_1000_tcpconnections=194050 - MAX_ALLOCS_ALLOWED_1000_tcpconnections=177010
- MAX_ALLOCS_ALLOWED_1000_udpbootstraps=4000 - MAX_ALLOCS_ALLOWED_1000_udpbootstraps=4000
- MAX_ALLOCS_ALLOWED_1000_udpconnections=113050 - MAX_ALLOCS_ALLOWED_1000_udpconnections=113050
- MAX_ALLOCS_ALLOWED_1000_udp_reqs=16050 - MAX_ALLOCS_ALLOWED_1000_udp_reqs=16050

View File

@ -37,7 +37,7 @@ services:
- MAX_ALLOCS_ALLOWED_udp_1000_reqs_1_conn=18250 - MAX_ALLOCS_ALLOWED_udp_1000_reqs_1_conn=18250
- MAX_ALLOCS_ALLOWED_udp_1_reqs_1000_conn=235050 - MAX_ALLOCS_ALLOWED_udp_1_reqs_1000_conn=235050
- MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=3100 - MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=3100
- MAX_ALLOCS_ALLOWED_1000_tcpconnections=205800 - MAX_ALLOCS_ALLOWED_1000_tcpconnections=186050
- MAX_ALLOCS_ALLOWED_1000_udpbootstraps=3000 - MAX_ALLOCS_ALLOWED_1000_udpbootstraps=3000
- MAX_ALLOCS_ALLOWED_1000_udpconnections=120050 - MAX_ALLOCS_ALLOWED_1000_udpconnections=120050
- MAX_ALLOCS_ALLOWED_1000_udp_reqs=18050 - MAX_ALLOCS_ALLOWED_1000_udp_reqs=18050

View File

@ -37,7 +37,7 @@ services:
- MAX_ALLOCS_ALLOWED_udp_1000_reqs_1_conn=16250 - MAX_ALLOCS_ALLOWED_udp_1000_reqs_1_conn=16250
- MAX_ALLOCS_ALLOWED_udp_1_reqs_1000_conn=224050 - MAX_ALLOCS_ALLOWED_udp_1_reqs_1000_conn=224050
- MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=3100 - MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=3100
- MAX_ALLOCS_ALLOWED_1000_tcpconnections=196800 - MAX_ALLOCS_ALLOWED_1000_tcpconnections=178050
- MAX_ALLOCS_ALLOWED_1000_udpbootstraps=3000 - MAX_ALLOCS_ALLOWED_1000_udpbootstraps=3000
- MAX_ALLOCS_ALLOWED_1000_udpconnections=115050 - MAX_ALLOCS_ALLOWED_1000_udpconnections=115050
- MAX_ALLOCS_ALLOWED_1000_udp_reqs=16050 - MAX_ALLOCS_ALLOWED_1000_udp_reqs=16050