forked from gomods/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding benchmark for mongo and fs * Adding delete, exists, save with other storages * Fixing typos, adding nonexistent module exits benchmark * Fixing delete operation in delete benchmark * Separating non testing existing modules benchmark, shortening the benchmark name * running benchmark in ci * Revert "running benchmark in ci" - mongo index make duplicate records to fail idempotent, will fix in a separate PR. This reverts commit f7d7826. * Adding reset timer, fixing duplicate record issue * Revert "Revert "running benchmark in ci" - mongo index make duplicate records to" This reverts commit 40a7b33. * removing benchmark from ci * Adding operation for returning errors
- Loading branch information
1 parent
dd16ce8
commit 4cc1b71
Showing
11 changed files
with
209 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
149 changes: 149 additions & 0 deletions
149
pkg/storage/storage_tests/module_storage/storage_benchmark_test.go
This file contains 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,149 @@ | ||
package modulestorage | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/gobuffalo/suite" | ||
"github.com/gomods/athens/pkg/errors" | ||
"github.com/gomods/athens/pkg/storage" | ||
"github.com/gomods/athens/pkg/storage/fs" | ||
"github.com/gomods/athens/pkg/storage/mem" | ||
"github.com/gomods/athens/pkg/storage/minio" | ||
"github.com/gomods/athens/pkg/storage/mongo" | ||
"github.com/gomods/athens/pkg/storage/rdbms" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func BenchmarkStorageList(b *testing.B) { | ||
module, version := "athens_module", "1.0.1" | ||
zip, info, mod := []byte("zip_data"), []byte("info"), []byte("mod_info") | ||
|
||
for _, store := range getStores(b) { | ||
|
||
backend := store.Storage() | ||
|
||
require.NoError(b, backend.Save(context.Background(), module, version, mod, bytes.NewReader(zip), info), "Save for storage %s failed", backend) | ||
|
||
b.ResetTimer() | ||
b.Run(store.StorageHumanReadableName(), func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
_, err := backend.List(context.Background(), module) | ||
require.NoError(b, err, "Error in listing module") | ||
} | ||
}) | ||
|
||
require.NoError(b, store.Cleanup()) | ||
} | ||
} | ||
|
||
func BenchmarkStorageSave(b *testing.B) { | ||
module, version := "athens_module", "1.0.1" | ||
zip, info, mod := []byte("zip_data"), []byte("info"), []byte("mod_info") | ||
|
||
for _, store := range getStores(b) { | ||
|
||
backend := store.Storage() | ||
|
||
b.ResetTimer() | ||
mi := 0 | ||
b.Run(store.StorageHumanReadableName(), func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
err := backend.Save(context.Background(), fmt.Sprintf("save-%s-%d", module, mi), version, mod, bytes.NewReader(zip), info) | ||
require.NoError(b, err) | ||
mi++ | ||
} | ||
}) | ||
|
||
require.NoError(b, store.Cleanup()) | ||
} | ||
} | ||
|
||
func BenchmarkStorageSaveAndDelete(b *testing.B) { | ||
module, version := "athens_module", "1.0.1" | ||
zip, info, mod := []byte("zip_data"), []byte("info"), []byte("mod_info") | ||
|
||
for _, store := range getStores(b) { | ||
|
||
backend := store.Storage() | ||
|
||
b.ResetTimer() | ||
b.Run(store.StorageHumanReadableName(), func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
name := fmt.Sprintf("del-%s-%d", module, i) | ||
err := backend.Save(context.Background(), name, version, mod, bytes.NewReader(zip), info) | ||
require.NoError(b, err, "save for storage %s module: %s failed", backend, name) | ||
err = backend.Delete(context.Background(), name, version) | ||
require.NoError(b, err, "delete failed: %s", name) | ||
} | ||
}) | ||
|
||
require.NoError(b, store.Cleanup()) | ||
} | ||
} | ||
|
||
func BenchmarkStorageDeleteNonExistingModules(b *testing.B) { | ||
module, version := "random-module", "version" | ||
for _, store := range getStores(b) { | ||
backend := store.Storage() | ||
|
||
b.ResetTimer() | ||
b.Run(store.StorageHumanReadableName(), func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
err := backend.Delete(context.Background(), fmt.Sprintf("del-%s-%d", module, i), version) | ||
require.Equal(b, errors.KindNotFound, errors.Kind(err)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkStorageExists(b *testing.B) { | ||
module, version := "athens_module", "1.0.1" | ||
zip, info, mod := []byte("zip_data"), []byte("info"), []byte("mod_info") | ||
moduleName := fmt.Sprintf("existing-%s", module) | ||
|
||
for _, store := range getStores(b) { | ||
backend := store.Storage() | ||
err := backend.Save(context.Background(), moduleName, version, mod, bytes.NewReader(zip), info) | ||
require.NoError(b, err, "exists for storage %s failed", backend) | ||
|
||
b.ResetTimer() | ||
b.Run(store.StorageHumanReadableName(), func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
require.True(b, backend.Exists(context.Background(), moduleName, version)) | ||
} | ||
}) | ||
|
||
require.NoError(b, store.Cleanup()) | ||
} | ||
} | ||
|
||
func getStores(b *testing.B) []storage.TestSuite { | ||
var stores []storage.TestSuite | ||
|
||
//TODO: create the instance without model or TestSuite | ||
model := suite.NewModel() | ||
fsStore, err := fs.NewTestSuite(model) | ||
require.NoError(b, err, "couldn't create filesystem store") | ||
stores = append(stores, fsStore) | ||
|
||
mongoStore, err := mongo.NewTestSuite(model) | ||
require.NoError(b, err, "couldn't create mongo store") | ||
stores = append(stores, mongoStore) | ||
|
||
rdbmsStore, err := rdbms.NewTestSuite(model) | ||
require.NoError(b, err, "couldn't create mongo store") | ||
stores = append(stores, rdbmsStore) | ||
|
||
memStore, err := mem.NewTestSuite(model) | ||
require.NoError(b, err) | ||
stores = append(stores, memStore) | ||
|
||
minioStore, err := minio.NewTestSuite(model) | ||
require.NoError(b, err) | ||
stores = append(stores, minioStore) | ||
|
||
return stores | ||
} |
This file contains 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
This file contains 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 @@ | ||
#!/bin/bash | ||
|
||
go test -v -bench=. $(find . -iname '*storage*test.go' -not -path '/vendor/') -run=^$ |