-
Notifications
You must be signed in to change notification settings - Fork 36
Add Benchmarks for metrics #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
freef4ll
wants to merge
13
commits into
swift-server:main
Choose a base branch
from
ordo-one:benchmark
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+403
−0
Open
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0a5b476
Add Benchmarks
freef4ll 998da01
Refactor and add docker scripts
freef4ll 43cfe7b
fix tresholds
freef4ll 3032be0
fix main thresholds
freef4ll 9454c98
address feedback
freef4ll 293c555
Delete Benchmarks/Package.resolved
freef4ll fdeb454
Delete Benchmarks/Thresholds/5.7/PrometheusBenchmarks.Counter_-_setup…
freef4ll e63303e
drop swift-version copy and paste on benchmark files
freef4ll 7a8e280
SwiftNIO -> SwiftPrometheus license fix up
freef4ll 3a70188
license fix up
freef4ll a15bd27
add .build to ignore
freef4ll dd1b2b5
Merge branch 'swift-server:main' into benchmark
freef4ll 617473b
merge
freef4ll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc | ||
.benchmarkBaselines/ |
64 changes: 64 additions & 0 deletions
64
Benchmarks/Benchmarks/PrometheusBenchmarks/Benchmarks.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// swift-tools-version:5.7 | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftPrometheus open source project | ||
// | ||
// Copyright (c) 2018-2023 SwiftPrometheus project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftPrometheus project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Benchmark | ||
import Prometheus | ||
|
||
let registry = PrometheusCollectorRegistry() | ||
|
||
public func makeLabels(_ idx: Int) -> [(String, String)] { | ||
[ | ||
("job", "api_server_\(idx)"), | ||
("handler", "/api/handler_\(idx)"), | ||
("status_code", "200"), | ||
("version", "\(idx).0.0"), | ||
] | ||
} | ||
|
||
let benchmarks = { | ||
Benchmark.defaultConfiguration.maxDuration = .seconds(5) | ||
Benchmark.defaultConfiguration.scalingFactor = .kilo | ||
// Benchmark.defaultConfiguration.metrics = [.wallClock, .throughput, .mallocCountTotal] | ||
Benchmark.defaultConfiguration.metrics = [.mallocCountTotal] | ||
|
||
Benchmark("Counter #1") { benchmark in | ||
runCounterBench(benchmark.scaledIterations) | ||
} | ||
|
||
Benchmark("Counter #2") { benchmark, run in | ||
freef4ll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for _ in benchmark.scaledIterations { | ||
run() | ||
} | ||
} setup: { | ||
setupCounterBench() | ||
} | ||
|
||
Benchmark("Gauge") { benchmark in | ||
runGaugeBench(benchmark.scaledIterations) | ||
} | ||
|
||
Benchmark("DurationHistogram") { benchmark in | ||
runDurationHistogramBench(benchmark.scaledIterations) | ||
} | ||
|
||
Benchmark("RegistryEmit - 5000 metrics", | ||
configuration: .init(scalingFactor: .one)) { benchmark, run in | ||
for _ in benchmark.scaledIterations { | ||
run() | ||
} | ||
} setup: { | ||
setupRegistryExport(numberOfMetrics: 5000) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// swift-tools-version:5.7 | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftPrometheus open source project | ||
// | ||
// Copyright (c) 2018-2023 SwiftPrometheus project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftPrometheus project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Benchmark | ||
import Prometheus | ||
|
||
public func runCounterBench(_ iterations: Range<Int>) { | ||
let ctr = registry.makeCounter(name: "counter_1", labels: makeLabels(1)) | ||
for _ in iterations { | ||
blackHole(ctr.increment()) | ||
} | ||
} | ||
|
||
public func setupCounterBench() -> () -> Void { | ||
let ctr = registry.makeCounter(name: "counter_2", labels: makeLabels(2)) | ||
return { | ||
blackHole(ctr.increment()) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Benchmarks/Benchmarks/PrometheusBenchmarks/DurationHistogram.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// swift-tools-version:5.7 | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftPrometheus open source project | ||
// | ||
// Copyright (c) 2018-2023 SwiftPrometheus project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftPrometheus project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Benchmark | ||
import Prometheus | ||
|
||
public func runDurationHistogramBench(_ iterations: Range<Int>) { | ||
let histogram = registry.makeDurationHistogram(name: "histogram_1", labels: makeLabels(3), | ||
freef4ll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
buckets: [ | ||
.milliseconds(100), | ||
.milliseconds(250), | ||
.milliseconds(500), | ||
.seconds(1), | ||
]) | ||
for _ in iterations { | ||
blackHole(histogram.record(Duration.milliseconds(400))) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// swift-tools-version:5.7 | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftPrometheus open source project | ||
// | ||
// Copyright (c) 2018-2023 SwiftPrometheus project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftPrometheus project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Benchmark | ||
import Prometheus | ||
|
||
public func runGaugeBench(_ iterations: Range<Int>) { | ||
let gauge = registry.makeGauge(name: "gauge_1", labels: makeLabels(2)) | ||
for _ in iterations { | ||
blackHole(gauge.increment()) | ||
} | ||
} | ||
|
||
public func setupGaugeBench() -> () -> Void { | ||
let gauge = registry.makeGauge(name: "gauge_1", labels: makeLabels(2)) | ||
return { | ||
blackHole(gauge.increment()) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Benchmarks/Benchmarks/PrometheusBenchmarks/RegistryEmit.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// swift-tools-version:5.7 | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftPrometheus open source project | ||
// | ||
// Copyright (c) 2018-2023 SwiftPrometheus project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftPrometheus project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Benchmark | ||
import Prometheus | ||
|
||
public func setupRegistryExport(numberOfMetrics: Int) -> () -> Void { | ||
let registryExport = PrometheusCollectorRegistry() | ||
|
||
var counterArray = [Counter]() | ||
var gaugeArray = [Gauge]() | ||
var buffer = [UInt8]() | ||
|
||
let counterExportSize = 620_000 | ||
counterArray.reserveCapacity(numberOfMetrics) | ||
gaugeArray.reserveCapacity(numberOfMetrics) | ||
buffer.reserveCapacity(counterExportSize) | ||
|
||
for i in 0..<(numberOfMetrics / 2) { | ||
let counter = registryExport.makeCounter(name: "http_requests_total", labels: makeLabels(i)) | ||
counter.increment() | ||
counterArray.append(counter) | ||
|
||
let gauge = registryExport.makeGauge(name: "export_gauge_\(i)", labels: makeLabels(i)) | ||
gauge.increment() | ||
gaugeArray.append(gauge) | ||
} | ||
return { | ||
blackHole(registryExport.emit(into: &buffer)) | ||
} | ||
} |
freef4ll marked this conversation as resolved.
Show resolved
Hide resolved
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// swift-tools-version:5.7 | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftPrometheus open source project | ||
// | ||
// Copyright (c) 2018-2023 SwiftPrometheus project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftPrometheus project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "benchmarks", | ||
platforms: [ | ||
.macOS(.v13), | ||
], | ||
dependencies: [ | ||
.package(path: "../"), | ||
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.11.2"), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "PrometheusBenchmarks", | ||
dependencies: [ | ||
.product(name: "Benchmark", package: "package-benchmark"), | ||
.product(name: "Prometheus", package: "swift-prometheus"), | ||
], | ||
path: "Benchmarks/PrometheusBenchmarks", | ||
plugins: [ | ||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"), | ||
] | ||
), | ||
] | ||
) |
3 changes: 3 additions & 0 deletions
3
Benchmarks/Thresholds/5.10/PrometheusBenchmarks.Counter_#1.p90.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"mallocCountTotal" : 1 | ||
} |
3 changes: 3 additions & 0 deletions
3
Benchmarks/Thresholds/5.10/PrometheusBenchmarks.Counter_#2.p90.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"mallocCountTotal" : 0 | ||
} |
3 changes: 3 additions & 0 deletions
3
Benchmarks/Thresholds/5.10/PrometheusBenchmarks.DurationHistogram.p90.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"mallocCountTotal" : 2 | ||
} |
3 changes: 3 additions & 0 deletions
3
Benchmarks/Thresholds/5.10/PrometheusBenchmarks.Gauge.p90.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"mallocCountTotal" : 1 | ||
} |
3 changes: 3 additions & 0 deletions
3
Benchmarks/Thresholds/5.10/PrometheusBenchmarks.RegistryEmit_-_5000_metrics.p90.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"mallocCountTotal" : 0 | ||
} |
3 changes: 3 additions & 0 deletions
3
Benchmarks/Thresholds/5.7/PrometheusBenchmarks.Counter_#1.p90.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"mallocCountTotal" : 1 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.