Make UDP connection allocation test more like best practice code. (#1583)

Motivation:

There is at least a theoretical race to flush before close in prior version.
Having terrible code in the NIO repo is asking for someone to copy it.

Modifications:

flatMap the various parts of the client together which also ensures the
flush is complete before close is called.

Result:

Slightly nicer code, slightly fewer allocations.
This commit is contained in:
Peter Adams 2020-06-30 17:11:05 +01:00 committed by GitHub
parent 25db3ea68b
commit 8a865bd15e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 12 deletions

View File

@ -60,14 +60,13 @@ func run(identifier: String) {
measure(identifier: identifier) {
let buffer = ByteBuffer(integer: 1, as: UInt8.self)
for _ in 0 ..< numberOfIterations {
let clientChannel = try! clientBootstrap.bind(to: localhostPickPort).wait()
defer {
try! clientChannel.close().wait()
}
// Send a byte to make sure everything is really open.
let envelope = AddressedEnvelope<ByteBuffer>(remoteAddress: remoteAddress, data: buffer)
clientChannel.writeAndFlush(envelope, promise: nil)
try! clientBootstrap.bind(to: localhostPickPort).flatMap { clientChannel -> EventLoopFuture<Void> in
// Send a byte to make sure everything is really open.
let envelope = AddressedEnvelope<ByteBuffer>(remoteAddress: remoteAddress, data: buffer)
return clientChannel.writeAndFlush(envelope).flatMap {
clientChannel.close()
}
}.wait()
}
try! serverHandler.completionFuture.wait()
return numberOfIterations

View File

@ -39,7 +39,7 @@ services:
- MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=4100
- MAX_ALLOCS_ALLOWED_1000_tcpconnections=181010
- MAX_ALLOCS_ALLOWED_1000_udpbootstraps=2000
- MAX_ALLOCS_ALLOWED_1000_udpconnections=105050
- MAX_ALLOCS_ALLOWED_1000_udpconnections=103050
- MAX_ALLOCS_ALLOWED_1000_udp_reqs=16050
- SANITIZER_ARG=--sanitize=thread
- INTEGRATION_TESTS_ARG=-f tests_0[013-9]

View File

@ -38,7 +38,7 @@ services:
- MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=4100
- MAX_ALLOCS_ALLOWED_1000_tcpconnections=180010
- MAX_ALLOCS_ALLOWED_1000_udpbootstraps=2000
- MAX_ALLOCS_ALLOWED_1000_udpconnections=103050
- MAX_ALLOCS_ALLOWED_1000_udpconnections=102050
- MAX_ALLOCS_ALLOWED_1000_udp_reqs=16050
- SANITIZER_ARG=--sanitize=thread

View File

@ -39,7 +39,7 @@ services:
- MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=3100
- MAX_ALLOCS_ALLOWED_1000_tcpconnections=189050
- MAX_ALLOCS_ALLOWED_1000_udpbootstraps=2000
- MAX_ALLOCS_ALLOWED_1000_udpconnections=110050
- MAX_ALLOCS_ALLOWED_1000_udpconnections=108050
- MAX_ALLOCS_ALLOWED_1000_udp_reqs=18050

View File

@ -39,7 +39,7 @@ services:
- MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=3100
- MAX_ALLOCS_ALLOWED_1000_tcpconnections=181050
- MAX_ALLOCS_ALLOWED_1000_udpbootstraps=2000
- MAX_ALLOCS_ALLOWED_1000_udpconnections=105050
- MAX_ALLOCS_ALLOWED_1000_udpconnections=103050
- MAX_ALLOCS_ALLOWED_1000_udp_reqs=16050