Skip to content

Commit 99e9956

Browse files
authored
Add support for ordo-one/package-benchmark (#1678)
1 parent 4df985f commit 99e9956

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
matrix:
5151
include:
5252
- image: swiftlang/swift:nightly-jammy
53+
swift-version: main
5354
env:
5455
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_10_requests: 323000
5556
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_1_request: 161000
@@ -60,6 +61,7 @@ jobs:
6061
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_client: 170000
6162
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_server: 170000
6263
- image: swift:5.9-jammy
64+
swift-version: 5.9
6365
env:
6466
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_10_requests: 323000
6567
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_1_request: 161000
@@ -70,6 +72,7 @@ jobs:
7072
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_client: 170000
7173
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_server: 170000
7274
- image: swift:5.8-focal
75+
swift-version: 5.8
7376
env:
7477
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_10_requests: 323000
7578
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_1_request: 161000
@@ -80,6 +83,7 @@ jobs:
8083
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_client: 170000
8184
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_server: 170000
8285
- image: swift:5.7-focal
86+
swift-version: 5.7
8387
env:
8488
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_10_requests: 323000
8589
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_1_request: 161000
@@ -99,6 +103,13 @@ jobs:
99103
run: ./Performance/allocations/test-allocation-counts.sh
100104
env: ${{ matrix.env }}
101105
timeout-minutes: 20
106+
- name: Install jemalloc for benchmarking
107+
run: apt update && apt-get install -y libjemalloc-dev
108+
timeout-minutes: 20
109+
- name: Run Benchmarks
110+
working-directory: ./Performance/Benchmarks
111+
run: swift package benchmark baseline check --check-absolute-path Thresholds/${{ matrix.swift-version }}/
112+
timeout-minutes: 20
102113
integration-tests:
103114
strategy:
104115
fail-fast: false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ dev/codegen-tests/**/generated/*
2222
/scripts/.swift-format-source/
2323
Package.resolved
2424
*.out.*
25+
/Performance/Benchmarks/.benchmarkBaselines/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2023, gRPC Authors All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import Benchmark
17+
import Foundation
18+
19+
let benchmarks = {
20+
Benchmark.defaultConfiguration = .init(
21+
metrics: [
22+
.mallocCountTotal,
23+
.syscalls,
24+
.readSyscalls,
25+
.writeSyscalls,
26+
.memoryLeaked,
27+
.retainCount,
28+
.releaseCount,
29+
]
30+
)
31+
32+
// async code is currently still quite flaky in the number of retain/release it does so we don't measure them today
33+
var configWithoutRetainRelease = Benchmark.defaultConfiguration
34+
configWithoutRetainRelease.metrics.removeAll(where: { $0 == .retainCount || $0 == .releaseCount })
35+
36+
// Add Benchmarks here
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// swift-tools-version: 5.7
2+
/*
3+
* Copyright 2023, gRPC Authors All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
import PackageDescription
18+
19+
let package = Package(
20+
name: "benchmarks",
21+
platforms: [
22+
.macOS(.v13),
23+
],
24+
dependencies: [
25+
.package(path: "../../"),
26+
.package(url: "https://github.com/ordo-one/package-benchmark", from: "1.11.2")
27+
],
28+
targets: [
29+
.executableTarget(
30+
name: "GRPCSwiftBenchmark",
31+
dependencies: [
32+
.product(name: "Benchmark", package: "package-benchmark"),
33+
.product(name: "GRPC", package: "grpc-swift")
34+
],
35+
path: "Benchmarks/GRPCSwiftBenchmark",
36+
plugins: [
37+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
38+
]
39+
),
40+
]
41+
)

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ The `docs` directory contains documentation, including:
140140
- How to configure keepalive in [`docs/keepalive.md`][docs-keepalive]
141141
- Support for Apple Platforms and NIO Transport Services in
142142
[`docs/apple-platforms.md`][docs-apple]
143+
144+
## Benchmarks
145+
146+
Benchmarks for `grpc-swift` are in a separate Swift Package in the `Performance/Benchmarks` subfolder of this repository.
147+
They use the [`package-benchmark`](https://github.com/ordo-one/package-benchmark) plugin.
148+
Benchmarks depends on the [`jemalloc`](https://jemalloc.net) memory allocation library, which is used by `package-benchmark` to capture memory allocation statistics.
149+
An installation guide can be found in the [Getting Started article](https://swiftpackageindex.com/ordo-one/package-benchmark/documentation/benchmark/gettingstarted#Installing-Prerequisites-and-Platform-Support) of `package-benchmark`.
150+
Afterwards you can run the benchmarks from CLI by going to the `Performance/Benchmarks` subfolder (e.g. `cd Performance/Benchmarks`) and invoking:
151+
```
152+
swift package benchmark
153+
```
154+
155+
Profiling benchmarks or building the benchmarks in release mode in Xcode with `jemalloc` is currently not supported and requires disabling `jemalloc`.
156+
Make sure Xcode is closed and then open it from the CLI with the `BENCHMARK_DISABLE_JEMALLOC=true` environment variable set e.g.:
157+
```
158+
BENCHMARK_DISABLE_JEMALLOC=true xed .
159+
```
160+
161+
For more information please refer to `swift package benchmark --help` or the [documentation of `package-benchmark`](https://swiftpackageindex.com/ordo-one/package-benchmark/documentation/benchmark).
143162

144163
## Security
145164

0 commit comments

Comments
 (0)