Skip to content

adopt package-benchmark #41

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

Merged
merged 15 commits into from
Oct 25, 2023

Conversation

dkz2
Copy link
Contributor

@dkz2 dkz2 commented Oct 11, 2023

Motivation:
As the Swift community is moving towards adopting the Benchmark package for performance evaluations, it is imperative for our Memcache client to remain aligned with best practices. The new Benchmark package not only standardize the performance measurement process but also offers detailed insights that were previously harder to obtain. This PR closes #35.

Modifications:

  • Integrate a sub Swift Package dedicated to benchmarks.
  • Establish allocation limits under benchmark/Thresholds/
  • Introduce a dev/update-benchmark-thresholds script. This script, using Docker, conducts benchmarks for all supported Swift versions and then refreshes the thresholds.
  • As part of our CI, benchmarks are conducted for each Swift version post the successful completion of regular tests.

Results:
The integration of the Benchmark package ensures a more thorough performance evaluation for our Memcache client. Emphasizing critical metrics and paving the way for a more accessible, iterative and detailed benchmarking process.

Copy link
Contributor

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Left some comments inline

Comment on lines 23 to 27
.mallocCountTotal,
.mallocCountLarge,
.mallocCountTotal,
.memoryLeaked,
.allocatedResidentMemory,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for now only mallocCountTotal is fine

]

Benchmark("Set Request", configuration: .init(metrics: defaultMetrics)) { benchmark in
try await withThrowingTaskGroup(of: Void.self) { group in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a separate file where we have those benchmarks as methods. Similar to what we do in certificates and nio?

Benchmark("Set Request", configuration: .init(metrics: defaultMetrics)) { benchmark in
try await withThrowingTaskGroup(of: Void.self) { group in

let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's pass the EL to those new functions and let's statically initialize an EL outside of the let benchmarks. Take a look at what we do in NIO for it.


for _ in benchmark.scaledIterations {
let getValue: String? = try await memcacheConnection.get("foo")
assert(getValue == setValue, "Value retrieved from Memcache does not match the set value")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to assert here.

}
}

Benchmark("Delete Request", configuration: .init(metrics: defaultMetrics)) { benchmark in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments for the other benchmarks

Comment on lines 29 to 34
.target(
name: "Benchmarks"),
.testTarget(
name: "BenchmarksTests",
dependencies: ["Benchmarks"]
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need those two targets

)
// Benchmark of MemcacheBenchmarks
package.targets += [
.executableTarget(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just put this above instead of doing the += dance

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last comment then we can merge it

scalingFactor: .mega
)
) { benchmark in
try await runSetRequest(iterations: benchmark.scaledIterations.lowerBound, eventLoop: eventLoop)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the upperBound for all of those instead of the lowerBound

@dkz2 dkz2 marked this pull request as ready for review October 17, 2023 14:58
@@ -34,7 +34,7 @@ services:
depends_on:
- runtime-setup
- memcached
command: /bin/bash -xcl "swift $${SWIFT_TEST_VERB-test} $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-}"
command: /bin/bash -xcl "swift $${SWIFT_TEST_VERB-test} $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-} && cd Benchmarks && swift package benchmark baseline check --check-absolute-path Thresholds/$${SWIFT_VERSION-}/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to disable the sandbox here as well

@FranzBusch FranzBusch merged commit 585b081 into swift-server:main Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Benchmark MemcachedConnection for Performance Metrics
2 participants