Skip to content

Commit 585b081

Browse files
authored
adopt package-benchmark (#41)
* init benchmarking * more thresholdes + docker * working set request benchmark w docker * soundness * update benchmark script * #35 * 5.10 support * soundness checks build/ in subfolders * benchmark as methods * cleanup * make use of upperBound * docker sandbox fix * removed scaling factor * soundness
1 parent 1e7991a commit 585b081

File tree

38 files changed

+394
-3
lines changed

38 files changed

+394
-3
lines changed

Benchmarks/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-memcache-gsoc open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the swift-memcache-gsoc 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-memcache-gsoc project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Benchmark
16+
import Memcache
17+
import NIOCore
18+
import NIOPosix
19+
20+
private let eventLoopGroup = MultiThreadedEventLoopGroup.singleton.next()
21+
22+
let benchmarks = {
23+
let defaultMetrics: [BenchmarkMetric] = [
24+
.mallocCountTotal,
25+
]
26+
27+
Benchmark(
28+
"Set Request",
29+
configuration: .init(
30+
metrics: defaultMetrics,
31+
timeUnits: .milliseconds
32+
)
33+
) { benchmark in
34+
try await runSetRequest(iterations: benchmark.scaledIterations.upperBound, eventLoopGroup: eventLoopGroup)
35+
}
36+
37+
Benchmark(
38+
"Set with TTL Request",
39+
configuration: .init(
40+
metrics: defaultMetrics,
41+
timeUnits: .milliseconds
42+
)
43+
) { benchmark in
44+
try await runSetWithTTLRequest(iterations: benchmark.scaledIterations.upperBound, eventLoopGroup: eventLoopGroup)
45+
}
46+
Benchmark(
47+
"Delete Request",
48+
configuration: .init(
49+
metrics: defaultMetrics,
50+
timeUnits: .milliseconds
51+
)
52+
) { benchmark in
53+
try await runDeleteRequest(iterations: benchmark.scaledIterations.upperBound, eventLoopGroup: eventLoopGroup)
54+
}
55+
56+
Benchmark(
57+
"Increment Request",
58+
configuration: .init(
59+
metrics: defaultMetrics,
60+
timeUnits: .milliseconds
61+
)
62+
) { benchmark in
63+
try await runIncrementRequest(iterations: benchmark.scaledIterations.upperBound, eventLoopGroup: eventLoopGroup)
64+
}
65+
66+
Benchmark(
67+
"Decrement Request",
68+
configuration: .init(
69+
metrics: defaultMetrics,
70+
timeUnits: .milliseconds
71+
)
72+
) { benchmark in
73+
try await runDecrementRequest(iterations: benchmark.scaledIterations.upperBound, eventLoopGroup: eventLoopGroup)
74+
}
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-memcache-gsoc open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the swift-memcache-gsoc 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-memcache-gsoc project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Benchmark
16+
import Memcache
17+
import NIOCore
18+
import NIOPosix
19+
20+
func runSetRequest(iterations: Int, eventLoopGroup: EventLoopGroup) async throws {
21+
try await withThrowingTaskGroup(of: Void.self) { group in
22+
let memcacheConnection = MemcacheConnection(host: "memcached", port: 11211, eventLoopGroup: eventLoopGroup)
23+
group.addTask { try await memcacheConnection.run() }
24+
25+
let setValue = "bar"
26+
27+
for _ in 0..<iterations {
28+
try await memcacheConnection.set("foo", value: setValue)
29+
}
30+
group.cancelAll()
31+
}
32+
}
33+
34+
func runSetWithTTLRequest(iterations: Int, eventLoopGroup: EventLoopGroup) async throws {
35+
try await withThrowingTaskGroup(of: Void.self) { group in
36+
37+
let memcacheConnection = MemcacheConnection(host: "memcached", port: 11211, eventLoopGroup: eventLoopGroup)
38+
group.addTask { try await memcacheConnection.run() }
39+
40+
let setValue = "foo"
41+
let now = ContinuousClock.Instant.now
42+
let expirationTime = now.advanced(by: .seconds(90))
43+
let timeToLive = TimeToLive.expiresAt(expirationTime)
44+
45+
for _ in 0..<iterations {
46+
try await memcacheConnection.set("bar", value: setValue, timeToLive: timeToLive)
47+
}
48+
group.cancelAll()
49+
}
50+
}
51+
52+
func runDeleteRequest(iterations: Int, eventLoopGroup: EventLoopGroup) async throws {
53+
try await withThrowingTaskGroup(of: Void.self) { group in
54+
55+
let memcacheConnection = MemcacheConnection(host: "memcached", port: 11211, eventLoopGroup: eventLoopGroup)
56+
group.addTask { try await memcacheConnection.run() }
57+
58+
let setValue = "foo"
59+
try await memcacheConnection.set("bar", value: setValue)
60+
61+
for _ in 0..<iterations {
62+
try await memcacheConnection.delete("bar")
63+
}
64+
group.cancelAll()
65+
}
66+
}
67+
68+
func runIncrementRequest(iterations: Int, eventLoopGroup: EventLoopGroup) async throws {
69+
try await withThrowingTaskGroup(of: Void.self) { group in
70+
71+
let memcacheConnection = MemcacheConnection(host: "memcached", port: 11211, eventLoopGroup: eventLoopGroup)
72+
group.addTask { try await memcacheConnection.run() }
73+
74+
let initialValue = 1
75+
try await memcacheConnection.set("increment", value: initialValue)
76+
77+
let incrementAmount = 100
78+
for _ in 0..<iterations {
79+
try await memcacheConnection.increment("increment", amount: incrementAmount)
80+
}
81+
group.cancelAll()
82+
}
83+
}
84+
85+
func runDecrementRequest(iterations: Int, eventLoopGroup: EventLoopGroup) async throws {
86+
try await withThrowingTaskGroup(of: Void.self) { group in
87+
88+
let memcacheConnection = MemcacheConnection(host: "memcached", port: 11211, eventLoopGroup: eventLoopGroup)
89+
group.addTask { try await memcacheConnection.run() }
90+
91+
let initialValue = 100
92+
try await memcacheConnection.set("decrement", value: initialValue)
93+
94+
let decrementAmount = 10
95+
for _ in 0..<iterations {
96+
try await memcacheConnection.decrement("decrement", amount: decrementAmount)
97+
}
98+
group.cancelAll()
99+
}
100+
}

Benchmarks/Package.swift

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// swift-tools-version: 5.7
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the SwiftCertificates open source project
5+
//
6+
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates 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 SwiftCertificates 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(name: "swift-memcache-gsoc", path: "../"),
25+
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.11.1"),
26+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.56.0"),
27+
],
28+
targets: [
29+
.executableTarget(
30+
name: "MemcacheBenchmarks",
31+
dependencies: [
32+
.product(name: "Memcache", package: "swift-memcache-gsoc"),
33+
.product(name: "Benchmark", package: "package-benchmark"),
34+
.product(name: "NIOCore", package: "swift-nio"),
35+
.product(name: "NIOPosix", package: "swift-nio"),
36+
],
37+
path: "Benchmarks/MemcacheBenchmarks",
38+
plugins: [
39+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
40+
]
41+
),
42+
]
43+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 578
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 578
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 578
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 578
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 578
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 578
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 506
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 506
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 578
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 578
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 507
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 506
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 578
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mallocCountTotal" : 578
3+
}

0 commit comments

Comments
 (0)