Skip to content
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

Add benchmarks #103

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Add benchmarks #103

wants to merge 13 commits into from

Conversation

ptoffy
Copy link
Member

@ptoffy ptoffy commented Jan 9, 2025

No description provided.

@ptoffy ptoffy requested review from 0xTim and gwynne as code owners January 9, 2025 08:49
@ptoffy ptoffy changed the title Start adding benchmarks Add benchmarks Jan 9, 2025
@MahdiBM
Copy link
Contributor

MahdiBM commented Jan 9, 2025

IMO we should use static thresholds, like SwiftNIO does.

package-benchmark relatively recently added a thresholds commands for this as well, and there is a bit of docs for it here.

I think using something like this should work to compare static thresholds against current branch:

            swift package -c release --disable-sandbox \
              benchmark thresholds check \
              --path $PWD/Benchmarks/Thresholds/ \
              --format markdown

.github/workflows/benchmark.yml Outdated Show resolved Hide resolved
Comment on lines 11 to 46
let boundary = "boundary123"
var message = ArraySlice(
"""
--\(boundary)\r
Content-Disposition: form-data; name="id"\r
Content-Type: text/plain\r
\r
123e4567-e89b-12d3-a456-426655440000\r
--\(boundary)\r
Content-Disposition: form-data; name="address"\r
Content-Type: application/json\r
\r
{\r
"street": "3, Garden St",\r
"city": "Hillsbery, UT"\r
}\r
--\(boundary)\r
Content-Disposition: form-data; name="profileImage"; filename="image1.png"\r
Content-Type: image/png\r
\r\n
""".utf8)

message.append(contentsOf: Array(repeating: UInt8.random(in: 0...255), count: 500_000_000)) // 500MB
message.append(contentsOf: "\r\n--\(boundary)--".utf8)

let stream = AsyncStream { continuation in
var offset = message.startIndex
while offset < message.endIndex {
let endIndex = min(message.endIndex, message.index(offset, offsetBy: 16))
continuation.yield(message[offset..<endIndex])
offset = endIndex
}
continuation.finish()
}

let sequence = StreamingMultipartParserAsyncSequence(boundary: boundary, buffer: stream)
Copy link
Contributor

Choose a reason for hiding this comment

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

Benchmark accepts a setUp closure IIRC. I'd personally just use a lazy variable to make sure the whole thing is only done once, regardless of how many iterations the benchmark is going to have.

@ptoffy
Copy link
Member Author

ptoffy commented Jan 9, 2025

IMO we should use static thresholds, like SwiftNIO does.

The problem with this is we don't have any baseline thresholds (yet)

Copy link

github-actions bot commented Jan 9, 2025

PR benchmarks run at
(main branch benchmarks not available)

@vapor vapor deleted a comment from github-actions bot Jan 9, 2025
@vapor vapor deleted a comment from github-actions bot Jan 9, 2025
@vapor vapor deleted a comment from github-actions bot Jan 9, 2025
@vapor vapor deleted a comment from github-actions bot Jan 9, 2025
Copy link

Benchmark Report

❌ Pull request has significant performance differences 📊

Click to expand comparison result

Benchmark check running at 2025-01-10 16:48:19 UTC

Could not find any matching absolute thresholds at path [/__w/multipart-kit/multipart-kit/Benchmarks/Thresholds/], failing threshold check.

Click to expand benchmark result

Baseline benchmarks

Host dc75ffde3938 with 2 aarch64 processors with 3 GB memory, running:
#23-Ubuntu SMP Mon Dec  9 23:51:16 UTC 2024

Parser

Collating Parser Allocations

Metric p0 p25 p50 p75 p90 p99 p100 Samples
Malloc (total) (K) * 153 153 153 153 153 153 153 1

Collating Parser Throughput

Metric p0 p25 p50 p75 p90 p99 p100 Samples
Throughput (# / s) (#) 1 1 1 1 1 1 1 1
Time (total CPU) (ms) * 1430 1430 1430 1430 1430 1430 1430 1
Time (wall clock) (ms) * 1430 1430 1430 1430 1430 1430 1430 1

Streaming Parser Allocations

Metric p0 p25 p50 p75 p90 p99 p100 Samples
Malloc (total) (K) * 153 153 153 153 153 153 153 1

Streaming Parser Throughput

Metric p0 p25 p50 p75 p90 p99 p100 Samples
Throughput (# / s) (#) 1 1 1 1 1 1 1 1
Time (total CPU) (ms) * 1060 1060 1060 1060 1060 1060 1060 1
Time (wall clock) (ms) * 1068 1068 1068 1068 1068 1068 1068 1

Serializer

Serializer Allocations

Metric p0 p25 p50 p75 p90 p99 p100 Samples
Malloc (total) * 8 8 8 8 8 8 8 10000

Serializer Throughput

Metric p0 p25 p50 p75 p90 p99 p100 Samples
Throughput (# / s) (#) 386 384 383 382 381 365 330 371
Time (total CPU) (μs) * 0 0 0 10000 10000 10000 10000 371
Time (wall clock) (μs) * 2592 2603 2609 2617 2628 2742 3033 371

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.

2 participants