diff --git a/Benchmarks/.gitignore b/Benchmarks/.gitignore new file mode 100644 index 000000000..2517bcdfa --- /dev/null +++ b/Benchmarks/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc +.benchmarkBaselines/ \ No newline at end of file diff --git a/Benchmarks/Benchmarks/NIOPosixBenchmarks/Benchmarks.swift b/Benchmarks/Benchmarks/NIOPosixBenchmarks/Benchmarks.swift new file mode 100644 index 000000000..f579891e7 --- /dev/null +++ b/Benchmarks/Benchmarks/NIOPosixBenchmarks/Benchmarks.swift @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftNIO open source project +// +// Copyright (c) 2023 Apple Inc. and the SwiftNIO project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of SwiftNIO project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import Benchmark + +let benchmarks = { + let defaultMetrics: [BenchmarkMetric] = [ + .mallocCountTotal, + ] + + Benchmark( + "TCPEcho", + configuration: .init( + metrics: defaultMetrics, + timeUnits: .milliseconds, + scalingFactor: .mega + ) + ) { benchmark in + try runTCPEcho(numberOfWrites: benchmark.scaledIterations.upperBound) + } +} diff --git a/Benchmarks/Benchmarks/NIOPosixBenchmarks/TCPEcho.swift b/Benchmarks/Benchmarks/NIOPosixBenchmarks/TCPEcho.swift new file mode 100644 index 000000000..1c656ea21 --- /dev/null +++ b/Benchmarks/Benchmarks/NIOPosixBenchmarks/TCPEcho.swift @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftNIO open source project +// +// Copyright (c) 2023 Apple Inc. and the SwiftNIO project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of SwiftNIO project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import NIOCore +import NIOPosix + +private final class EchoChannelHandler: ChannelInboundHandler { + fileprivate typealias InboundIn = ByteBuffer + + func channelRead(context: ChannelHandlerContext, data: NIOAny) { + context.writeAndFlush(data, promise: nil) + } +} + +private final class EchoRequestChannelHandler: ChannelInboundHandler { + fileprivate typealias InboundIn = ByteBuffer + + private let bufferSize = 10000 + private let numberOfWrites: Int + private var batchCount = 0 + private let data: NIOAny + private let readsCompletePromise: EventLoopPromise + private var receivedData = 0 + + init(numberOfWrites: Int, readsCompletePromise: EventLoopPromise) { + self.numberOfWrites = numberOfWrites + self.readsCompletePromise = readsCompletePromise + self.data = NIOAny(ByteBuffer(repeating: 0, count: self.bufferSize)) + } + + func channelActive(context: ChannelHandlerContext) { + for _ in 0..> $HOME/.profile diff --git a/docker/docker-compose.2204.510.yaml b/docker/docker-compose.2204.510.yaml index ef1732e29..6c4362987 100644 --- a/docker/docker-compose.2204.510.yaml +++ b/docker/docker-compose.2204.510.yaml @@ -76,6 +76,11 @@ services: performance-test: image: swift-nio:22.04-5.10 + update-benchmark-baseline: + image: swift-nio:22.04-5.10 + environment: + - SWIFT_VERSION=5.10 + shell: image: swift-nio:22.04-5.10 diff --git a/docker/docker-compose.2204.57.yaml b/docker/docker-compose.2204.57.yaml index 31df38fc9..eccb233c9 100644 --- a/docker/docker-compose.2204.57.yaml +++ b/docker/docker-compose.2204.57.yaml @@ -76,6 +76,11 @@ services: performance-test: image: swift-nio:22.04-5.7 + update-benchmark-baseline: + image: swift-nio:22.04-5.7 + environment: + - SWIFT_VERSION=5.7 + shell: image: swift-nio:22.04-5.7 diff --git a/docker/docker-compose.2204.58.yaml b/docker/docker-compose.2204.58.yaml index f4910ba24..c7f4059b0 100644 --- a/docker/docker-compose.2204.58.yaml +++ b/docker/docker-compose.2204.58.yaml @@ -77,6 +77,11 @@ services: performance-test: image: swift-nio:22.04-5.8 + update-benchmark-baseline: + image: swift-nio:22.04-5.8 + environment: + - SWIFT_VERSION=5.8 + shell: image: swift-nio:22.04-5.8 diff --git a/docker/docker-compose.2204.59.yaml b/docker/docker-compose.2204.59.yaml index 357536253..c1d94f76b 100644 --- a/docker/docker-compose.2204.59.yaml +++ b/docker/docker-compose.2204.59.yaml @@ -77,6 +77,11 @@ services: performance-test: image: swift-nio:22.04-5.9 + update-benchmark-baseline: + image: swift-nio:22.04-5.9 + environment: + - SWIFT_VERSION=5.9 + shell: image: swift-nio:22.04-5.9 diff --git a/docker/docker-compose.2204.main.yaml b/docker/docker-compose.2204.main.yaml index e4da57992..ad3a7fb6a 100644 --- a/docker/docker-compose.2204.main.yaml +++ b/docker/docker-compose.2204.main.yaml @@ -76,6 +76,11 @@ services: performance-test: image: swift-nio:22.04-main + update-benchmark-baseline: + image: swift-nio:22.04-main + environment: + - SWIFT_VERSION=main + shell: image: swift-nio:22.04-main diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 8bf9b4adb..c563622f7 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -16,8 +16,8 @@ services: depends_on: [runtime-setup] volumes: - ~/.ssh:/root/.ssh - - ..:/code:z - working_dir: /code + - ..:/swift-nio:z + working_dir: /swift-nio cap_drop: - CAP_NET_RAW - CAP_NET_BIND_SERVICE @@ -40,12 +40,16 @@ services: test: <<: *common - command: /bin/bash -xcl "uname -a && swift -version && swift $${SWIFT_TEST_VERB-test} $${FORCE_TEST_DISCOVERY-} $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-} && ./scripts/integration_tests.sh $${INTEGRATION_TESTS_ARG-}" + command: /bin/bash -xcl "uname -a && swift -version && swift $${SWIFT_TEST_VERB-test} $${FORCE_TEST_DISCOVERY-} $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-} && ./scripts/integration_tests.sh $${INTEGRATION_TESTS_ARG-} && cd Benchmarks && swift package benchmark baseline check --check-absolute-path Thresholds/$${SWIFT_VERSION-}/" performance-test: <<: *common command: /bin/bash -xcl "swift build -c release -Xswiftc -Xllvm -Xswiftc -align-all-functions=5 -Xswiftc -Xllvm -Xswiftc -align-all-blocks=5 && ./.build/release/NIOPerformanceTester" + update-benchmark-baseline: + <<: *common + command: /bin/bash -xcl "cd Benchmarks && swift package --disable-sandbox --scratch-path .build/$${SWIFT_VERSION-}/ --allow-writing-to-package-directory benchmark --format metricP90AbsoluteThresholds --path Thresholds/$${SWIFT_VERSION-}/" + # util shell: