Skip to content

Commit ec411bd

Browse files
Add benchmark infratructure without actual tests (#146)
* add benchmark infratructure without actual test * apply swiftformat * fix header in sh file * use new async seq methods
1 parent c3bbb75 commit ec411bd

14 files changed

+192
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
/.build
3+
/Benchmarks/.build
34
/Packages
45
/*.xcodeproj
56
xcuserdata/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-kafka-client open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the swift-kafka-client project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of swift-kafka-client project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Benchmark
16+
import Kafka
17+
18+
let benchmarks = {
19+
Benchmark.defaultConfiguration = .init(
20+
metrics: [.wallClock, .cpuTotal, .allocatedResidentMemory, .contextSwitches, .throughput] + .arc,
21+
warmupIterations: 0,
22+
scalingFactor: .one,
23+
maxDuration: .seconds(5),
24+
maxIterations: 100
25+
)
26+
27+
Benchmark.setup = {}
28+
29+
Benchmark.teardown = {}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-kafka-client open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the swift-kafka-client project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of swift-kafka-client project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Benchmark
16+
import Crdkafka
17+
import Kafka
18+
19+
let benchmarks = {
20+
Benchmark.defaultConfiguration = .init(
21+
metrics: [.wallClock, .cpuTotal, .allocatedResidentMemory, .contextSwitches, .throughput] + .arc,
22+
warmupIterations: 0,
23+
scalingFactor: .one,
24+
maxDuration: .seconds(5),
25+
maxIterations: 100
26+
)
27+
28+
Benchmark.setup = {}
29+
30+
Benchmark.teardown = {}
31+
}

Benchmarks/Package.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// swift-tools-version: 5.7
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the swift-kafka-client open source project
5+
//
6+
// Copyright (c) 2023 Apple Inc. and the swift-kafka-client project authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
// See CONTRIBUTORS.txt for the list of swift-kafka-client project authors
11+
//
12+
// SPDX-License-Identifier: Apache-2.0
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
import PackageDescription
17+
18+
let package = Package(
19+
name: "benchmarks",
20+
platforms: [
21+
.macOS(.v13),
22+
],
23+
dependencies: [
24+
.package(path: "../"),
25+
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.11.1"),
26+
],
27+
targets: [
28+
.executableTarget(
29+
name: "SwiftKafkaConsumerBenchmarks",
30+
dependencies: [
31+
.product(name: "Benchmark", package: "package-benchmark"),
32+
.product(name: "Kafka", package: "swift-kafka-client"),
33+
],
34+
path: "Benchmarks/SwiftKafkaConsumerBenchmarks",
35+
plugins: [
36+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
37+
]
38+
),
39+
.executableTarget(
40+
name: "SwiftKafkaProducerBenchmarks",
41+
dependencies: [
42+
.product(name: "Benchmark", package: "package-benchmark"),
43+
.product(name: "Kafka", package: "swift-kafka-client"),
44+
],
45+
path: "Benchmarks/SwiftKafkaProducerBenchmarks",
46+
plugins: [
47+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
48+
]
49+
),
50+
]
51+
)

Sources/Kafka/KafkaConsumer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public final class KafkaConsumer: Sendable, Service {
189189
)
190190
}
191191
}(),
192+
finishOnDeinit: true,
192193
delegate: KafkaConsumerMessagesDelegate(stateMachine: self.stateMachine)
193194
)
194195

@@ -294,6 +295,7 @@ public final class KafkaConsumer: Sendable, Service {
294295
let sourceAndSequence = NIOAsyncSequenceProducer.makeSequence(
295296
elementType: KafkaConsumerEvent.self,
296297
backPressureStrategy: NIOAsyncSequenceProducerBackPressureStrategies.NoBackPressure(),
298+
finishOnDeinit: true,
297299
delegate: KafkaConsumerEventsDelegate(stateMachine: stateMachine)
298300
)
299301

Sources/Kafka/KafkaProducer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public final class KafkaProducer: Service, Sendable {
189189
let sourceAndSequence = NIOAsyncSequenceProducer.makeSequence(
190190
elementType: KafkaProducerEvent.self,
191191
backPressureStrategy: NIOAsyncSequenceProducerBackPressureStrategies.NoBackPressure(),
192+
finishOnDeinit: true,
192193
delegate: KafkaProducerCloseOnTerminate(stateMachine: stateMachine)
193194
)
194195

dev/update-benchmark-thresholds.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the swift-kafka-client open source project
5+
##
6+
## Copyright (c) 2023 Apple Inc. and the swift-kafka-client project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of swift-kafka-client project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
16+
set -eu
17+
set -o pipefail
18+
19+
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
20+
target_repo=${2-"$here/.."}
21+
22+
for f in 57 58 59 510 -nightly; do
23+
echo "swift$f"
24+
25+
docker_file=$(if [[ "$f" == "-nightly" ]]; then f=main; fi && ls "$target_repo/docker/docker-compose."*"$f"*".yaml")
26+
27+
docker-compose -f docker/docker-compose.yaml -f $docker_file run update-benchmark-baseline
28+
done

docker/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ ENV LANGUAGE en_US.UTF-8
1515
# Dependencies
1616
RUN apt-get update
1717
RUN apt-get install libsasl2-dev -y
18+
RUN apt-get install libjemalloc-dev -y
19+
1820

1921
# tools
2022
RUN mkdir -p $HOME/.tools

docker/docker-compose.2204.510.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ services:
1919
- STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete
2020
# - SANITIZER_ARG=--sanitize=thread # TSan broken still
2121

22+
update-benchmark-baseline:
23+
image: swift-kafka-client:22.04-5.10
24+
environment:
25+
- SWIFT_VERSION=5.10
26+
2227
shell:
2328
image: swift-kafka-client:22.04-5.10

docker/docker-compose.2204.57.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ services:
1919
- STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete
2020
# - SANITIZER_ARG=--sanitize=thread # TSan broken still
2121

22+
update-benchmark-baseline:
23+
image: swift-kafka-client:22.04-5.7
24+
environment:
25+
- SWIFT_VERSION=5.7
26+
2227
shell:
2328
image: swift-kafka-client:22.04-5.7

0 commit comments

Comments
 (0)