Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneWerner87 committed Jul 22, 2024
2 parents ac2ddcf + 9c0cb9d commit 22e1155
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 20 deletions.
79 changes: 69 additions & 10 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ on:
paths-ignore:
- "**/*.md"

permissions:
# deployments permission to deploy GitHub pages website
deployments: write
# contents permission to update benchmark contents in gh-pages branch
contents: write

name: Benchmark
jobs:
Compare:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # to be able to retrieve the last commit in main

- name: Install Go
uses: actions/setup-go@v5
Expand All @@ -26,24 +34,75 @@ jobs:
- name: Run Benchmark
run: set -o pipefail; go test ./... -benchmem -run=^$ -bench . | tee output.txt

- name: Get Previous Benchmark Results
uses: actions/cache@v4
# NOTE: Benchmarks could change with different CPU types
- name: Get GitHub Runner System Information
uses: kenchan0130/actions-system-info@v1.3.0
id: system-info

- name: Get Main branch SHA
id: get-main-branch-sha
run: |
SHA=$(git rev-parse origin/main)
echo "sha=$SHA" >> $GITHUB_OUTPUT
- name: Get Benchmark Results from main branch
id: cache
uses: actions/cache/restore@v4
with:
path: ./cache
key: ${{ runner.os }}-benchmark
key: ${{ steps.get-main-branch-sha.outputs.sha }}-${{ runner.os }}-${{ steps.system-info.outputs.cpu-model }}-benchmark

# This will only run if we have Benchmark Results from main branch
- name: Compare PR Benchmark Results with main branch
uses: benchmark-action/github-action-benchmark@v1.20.3
if: steps.cache.outputs.cache-hit == 'true'
with:
tool: 'go'
output-file-path: output.txt
external-data-json-path: ./cache/benchmark-data.json
# Do not save the data (This allows comparing benchmarks)
save-data-file: false
fail-on-alert: true
comment-on-alert: true
github-token: ${{ secrets.GITHUB_TOKEN }}
summary-always: true
alert-threshold: "150%"

- name: Save Benchmark Results
- name: Store Benchmark Results for main branch
uses: benchmark-action/github-action-benchmark@v1.20.3
if: ${{ github.ref_name == 'main' }}
with:
tool: "go"
tool: 'go'
output-file-path: output.txt
external-data-json-path: ./cache/benchmark-data.json
# Save the data to external file (cache)
save-data-file: true
fail-on-alert: true
github-token: ${{ secrets.GITHUB_TOKEN }}
summary-always: true
alert-threshold: "150%"

- name: Publish Benchmark Results to GitHub Pages
uses: benchmark-action/github-action-benchmark@v1.20.3
if: ${{ github.ref_name == 'main' }}
with:
tool: 'go'
output-file-path: output.txt
github-token: ${{ secrets.BENCHMARK_TOKEN }}
benchmark-data-dir-path: "benchmarks"
fail-on-alert: true
comment-on-alert: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
# Enable Job Summary for PRs - deactivated because of issues
#summary-always: ${{ github.event_name != 'push' && github.event_name != 'workflow_dispatch' }}
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-on-alert: true
summary-always: true
# Save the data to external file (GitHub Pages)
save-data-file: true
alert-threshold: "150%"
# TODO: reactivate it later -> when v3 is the stable one
#auto-push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
auto-push: false
save-data-file: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}

- name: Update Benchmark Results cache
uses: actions/cache/save@v4
if: ${{ github.ref_name == 'main' }}
with:
path: ./cache
key: ${{ steps.get-main-branch-sha.outputs.sha }}-${{ runner.os }}-${{ steps.system-info.outputs.cpu-model }}-benchmark
28 changes: 18 additions & 10 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3099,23 +3099,25 @@ func Test_Ctx_SendFile_Compress_CheckCompressed(t *testing.T) {
expectedFileContent, err := io.ReadAll(f)
require.NoError(t, err)

sendFileBodyReader := func(compression string) []byte {
reqCtx := &fasthttp.RequestCtx{}
reqCtx.Request.Header.Add(HeaderAcceptEncoding, compression)
sendFileBodyReader := func(compression string) ([]byte, error) {
t.Helper()
c := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(c)
c.Request().Header.Add(HeaderAcceptEncoding, compression)

c := app.AcquireCtx(reqCtx)
err = c.SendFile("./ctx.go", SendFile{
err := c.SendFile("./ctx.go", SendFile{
Compress: true,
})
require.NoError(t, err)

return c.Response().Body()
return c.Response().Body(), err
}

t.Run("gzip", func(t *testing.T) {
t.Parallel()

body, err := fasthttp.AppendGunzipBytes(nil, sendFileBodyReader("gzip"))
b, err := sendFileBodyReader("gzip")
require.NoError(t, err)
body, err := fasthttp.AppendGunzipBytes(nil, b)
require.NoError(t, err)

require.Equal(t, expectedFileContent, body)
Expand All @@ -3124,7 +3126,9 @@ func Test_Ctx_SendFile_Compress_CheckCompressed(t *testing.T) {
t.Run("zstd", func(t *testing.T) {
t.Parallel()

body, err := fasthttp.AppendUnzstdBytes(nil, sendFileBodyReader("zstd"))
b, err := sendFileBodyReader("zstd")
require.NoError(t, err)
body, err := fasthttp.AppendUnzstdBytes(nil, b)
require.NoError(t, err)

require.Equal(t, expectedFileContent, body)
Expand All @@ -3133,7 +3137,9 @@ func Test_Ctx_SendFile_Compress_CheckCompressed(t *testing.T) {
t.Run("br", func(t *testing.T) {
t.Parallel()

body, err := fasthttp.AppendUnbrotliBytes(nil, sendFileBodyReader("br"))
b, err := sendFileBodyReader("br")
require.NoError(t, err)
body, err := fasthttp.AppendUnbrotliBytes(nil, b)
require.NoError(t, err)

require.Equal(t, expectedFileContent, body)
Expand Down Expand Up @@ -3242,6 +3248,8 @@ func Test_Ctx_SendFile_Multiple(t *testing.T) {
require.Contains(t, string(body), tc.body)
}

app.sendfilesMutex.RLock()
defer app.sendfilesMutex.RUnlock()
require.Len(t, app.sendfiles, 3)
}

Expand Down

1 comment on commit 22e1155

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 22e1155 Previous: 1c52689 Ratio
Benchmark_Utils_GetOffer/1_parameter 217.1 ns/op 0 B/op 0 allocs/op 137 ns/op 0 B/op 0 allocs/op 1.58
Benchmark_CORS_NewHandlerPreflight 1153 ns/op 104 B/op 5 allocs/op 766.5 ns/op 0 B/op 0 allocs/op 1.50
Benchmark_CORS_NewHandlerPreflightSingleOrigin 1151 ns/op 104 B/op 5 allocs/op 758.5 ns/op 0 B/op 0 allocs/op 1.52
Benchmark_CORS_NewHandlerPreflightWildcard 1058 ns/op 104 B/op 5 allocs/op 697.1 ns/op 0 B/op 0 allocs/op 1.52

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.