Skip to content

Commit

Permalink
Make UDP connection allocation test more like best practice code. (#1583
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
PeterAdams-A committed Jun 30, 2020
1 parent 25db3ea commit 8a865bd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.1604.52.yaml
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.1604.53.yaml
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.1804.50.yaml
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.1804.51.yaml
Expand Up @@ -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


Expand Down

0 comments on commit 8a865bd

Please sign in to comment.