Skip to content

Commit

Permalink
Merge pull request #992 from gofiber/add-benchmarks
Browse files Browse the repository at this point in the history
Add benchmarks for storage drivers
  • Loading branch information
ReneWerner87 authored Sep 18, 2023
2 parents aeb7a24 + f113998 commit 499d8aa
Show file tree
Hide file tree
Showing 29 changed files with 1,290 additions and 292 deletions.
170 changes: 170 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
on:
push:
branches:
- master
- main
paths:
- "**"
- "!**.md"
pull_request:
paths:
- "**"
- "!**.md"

permissions:
deployments: write
contents: write

name: Benchmark
jobs:
Compare:
runs-on: ubuntu-latest
services:
arangodb:
image: 'arangodb:latest'
env:
ARANGO_NO_AUTH: 1
ports:
- '8529:8529'
dynamodb:
image: 'amazon/dynamodb-local:latest'
ports:
- '8000:8000'
memcached:
image: 'memcached:latest'
ports:
- '11211:11211'
mongo:
image: 'mongo:latest'
ports:
- '27017:27017'
mssql:
image: 'mcmoe/mssqldocker:latest'
ports:
- '1433:1433'
env:
ACCEPT_EULA: Y
SA_PASSWORD: MsSql!1234
MSSQL_DB: master
MSSQL_USER: sa
MSSQL_PASSWORD: MsSql!1234
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -U sa -P $SA_PASSWORD -Q 'select 1' -b -o /dev/null"
--health-interval 1s
--health-timeout 30s
--health-start-period 10s
--health-retries 20
mysql:
image: 'mysql:latest'
env:
MYSQL_DATABASE: fiber
MYSQL_USER: username
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
ports:
- '3306:3306'
options: >-
--health-cmd "mysqladmin ping" --health-interval 10s --health-timeout
5s --health-retries 5
postgres:
image: 'postgres:latest'
ports:
- '5432:5432'
env:
POSTGRES_DB: fiber
POSTGRES_USER: username
POSTGRES_PASSWORD: "pass#w%rd"
options: >-
--health-cmd pg_isready --health-interval 10s --health-timeout 5s
--health-retries 5
steps:
- name: Fetch Repository
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
with:
# NOTE: Keep this in sync with the version from go.mod
go-version: "1.20.x"

- name: Install Azurite
run: |
docker run -d -p 10000:10000 mcr.microsoft.com/azure-storage/azurite azurite-blob --blobHost 0.0.0.0 --blobPort 10000
- name: Install Coherence
run: |
docker run -d -p 1408:1408 -p 30000:30000 ghcr.io/oracle/coherence-ce:22.06.5
sleep 30
- name: Install couchbase
run: |
docker run --name couchbase -d -p 8091-8097:8091-8097 -p 9123:9123 -p 11207:11207 -p 11210:11210 -p 11280:11280 -p 18091-18097:18091-18097 couchbase:enterprise-7.1.1
sleep 10
docker exec --tty couchbase couchbase-cli cluster-init -c localhost:8091 --cluster-username admin --cluster-password 123456 --cluster-ramsize 256 --services data
sleep 10
docker exec --tty couchbase couchbase-cli bucket-create -c localhost:8091 --username admin --password 123456 --bucket fiber_storage --bucket-type couchbase --bucket-ramsize 100 --enable-flush 1
- name: Install etcd
run: |
docker run -d --name Etcd-server \
--publish 2379:2379 \
--publish 2380:2380 \
--env ALLOW_NONE_AUTHENTICATION=yes \
--env ETCD_ADVERTISE_CLIENT_URLS=http://etcd-server:2379 \
bitnami/etcd:latest
- name: Install MinIO
run: |
docker run -d --restart always -p 9000:9000 --name storage-minio -e MINIO_ROOT_USER='minio-user' -e MINIO_ROOT_PASSWORD='minio-password' minio/minio server /data
- name: Setup Redis
uses: shogo82148/actions-setup-redis@v1
with:
redis-version: '7.x'
auto-start: 'false'

- name: Run Redis
run: |
redis-server --port 6379 &
- name: Run Benchmarks
run: |
set -o pipefail
for d in */ ; do
[[ $d == "tls/" ]] && continue
cd "$d"
go test ./... -benchmem -run=^$ -bench . | tee -a ../output.txt
cd ..
done
shell: bash
env:
MSSQL_DATABASE: master
MSSQL_USERNAME: sa
MSSQL_PASSWORD: MsSql!1234
MYSQL_USERNAME: username
MYSQL_PASSWORD: password
MYSQL_DATABASE: fiber
POSTGRES_DATABASE: fiber
POSTGRES_USERNAME: username
POSTGRES_PASSWORD: "pass#w%rd"

- name: Get Previous Benchmark Results
uses: actions/cache@v3
with:
path: ./cache
key: ${{ runner.os }}-benchmark

- name: Save Benchmark Results
uses: benchmark-action/[email protected]
with:
tool: "go"
output-file-path: output.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
benchmark-data-dir-path: "benchmarks"
alert-threshold: "300%"
fail-on-alert: true
comment-on-alert: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
#summary-always: ${{ github.event_name != 'push' && github.event_name != 'workflow_dispatch' }}
auto-push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
save-data-file: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
3 changes: 2 additions & 1 deletion .github/workflows/test-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ jobs:
--tls-auth-clients no &
- name: Setup Redis Cluster
uses: vishnudxb/[email protected].8
uses: vishnudxb/[email protected].9
with:
master1-port: 7000
master2-port: 7001
master3-port: 7002
slave1-port: 7003
slave2-port: 7004
slave3-port: 7005
sleep-duration: 10

- name: Install Go
uses: actions/setup-go@v4
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-rueidis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ jobs:
--tls-ca-cert-file /home/runner/work/storage/storage/tls/ca.crt &
- name: Setup Redis Cluster
uses: vishnudxb/[email protected].8
uses: vishnudxb/[email protected].9
with:
master1-port: 7000
master2-port: 7001
master3-port: 7002
slave1-port: 7003
slave2-port: 7004
slave3-port: 7005
sleep-duration: 10

- name: Install Go
uses: actions/setup-go@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- 1.21.x
steps:
- name: Install MinIO
run: docker run -d -p 9000:9000 --name minio minio/minio server /data
run: docker run -d --restart always -p 9000:9000 --name storage-minio -e MINIO_ROOT_USER='minio-user' -e MINIO_ROOT_PASSWORD='minio-password' minio/minio server /data
- name: Fetch Repository
uses: actions/checkout@v4
- name: Install Go
Expand Down
61 changes: 50 additions & 11 deletions arangodb/arangodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var testStore = New(Config{
Reset: true,
})

func Test_ARANGODB_Set(t *testing.T) {
func Test_ArangoDB_Set(t *testing.T) {
var (
key = "john"
val = []byte("doe")
Expand All @@ -21,7 +21,7 @@ func Test_ARANGODB_Set(t *testing.T) {
require.NoError(t, err)
}

func Test_ARANGODB_Upsert(t *testing.T) {
func Test_ArangoDB_Upsert(t *testing.T) {
var (
key = "john"
val = []byte("doe")
Expand All @@ -34,7 +34,7 @@ func Test_ARANGODB_Upsert(t *testing.T) {
require.NoError(t, err)
}

func Test_ARANGODB_Get(t *testing.T) {
func Test_ArangoDB_Get(t *testing.T) {
var (
key = "john"
val = []byte("doe")
Expand All @@ -48,7 +48,7 @@ func Test_ARANGODB_Get(t *testing.T) {
require.Equal(t, val, result)
}

func Test_ARANGODB_Set_Expiration(t *testing.T) {
func Test_ArangoDB_Set_Expiration(t *testing.T) {
var (
key = "john"
val = []byte("doe")
Expand All @@ -61,21 +61,21 @@ func Test_ARANGODB_Set_Expiration(t *testing.T) {
time.Sleep(1100 * time.Millisecond)
}

func Test_ARANGODB_Get_Expired(t *testing.T) {
func Test_ArangoDB_Get_Expired(t *testing.T) {
key := "john"

result, err := testStore.Get(key)
require.NoError(t, err)
require.Zero(t, len(result))
}

func Test_ARANGODB_Get_NotExist(t *testing.T) {
func Test_ArangoDB_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist")
require.NoError(t, err)
require.Zero(t, len(result))
}

func Test_ARANGODB_Delete(t *testing.T) {
func Test_ArangoDB_Delete(t *testing.T) {
var (
key = "john"
val = []byte("doe")
Expand All @@ -92,7 +92,7 @@ func Test_ARANGODB_Delete(t *testing.T) {
require.Zero(t, len(result))
}

func Test_ARANGODB_Reset(t *testing.T) {
func Test_ArangoDB_Reset(t *testing.T) {
val := []byte("doe")

err := testStore.Set("john1", val, 0)
Expand All @@ -113,7 +113,7 @@ func Test_ARANGODB_Reset(t *testing.T) {
require.Zero(t, len(result))
}

func Test_ARANGODB_Non_UTF8(t *testing.T) {
func Test_ArangoDB_Non_UTF8(t *testing.T) {
val := []byte("0xF5")

err := testStore.Set("0xF6", val, 0)
Expand All @@ -124,10 +124,49 @@ func Test_ARANGODB_Non_UTF8(t *testing.T) {
require.Equal(t, val, result)
}

func Test_ARANGODB_Close(t *testing.T) {
func Test_ArangoDB_Close(t *testing.T) {
require.Nil(t, testStore.Close())
}

func Test_ARANGODB_Conn(t *testing.T) {
func Test_ArangoDB_Conn(t *testing.T) {
require.True(t, testStore.Conn() != nil)
}

func Benchmark_ArangoDB_Set(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

var err error
for i := 0; i < b.N; i++ {
err = testStore.Set("john", []byte("doe"), 0)
}

require.NoError(b, err)
}

func Benchmark_ArangoDB_Get(b *testing.B) {
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err = testStore.Get("john")
}

require.NoError(b, err)
}

func Benchmark_ArangoDB_SetAndDelete(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

var err error
for i := 0; i < b.N; i++ {
_ = testStore.Set("john", []byte("doe"), 0)
err = testStore.Delete("john")
}

require.NoError(b, err)
}
Loading

0 comments on commit 499d8aa

Please sign in to comment.