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

[Move Object] Rename benchmark e2e perf test #2878

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions tools/integration_tests/benchmarking/benchmark_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,38 @@ package benchmarking

import (
"fmt"
"log"
"os"
"path"
"testing"
"time"

"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/benchmark_setup"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/operations"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup"
)

const (
expectedDeleteLatency time.Duration = 675 * time.Millisecond
)

type benchmarkDeleteTest struct{}
type benchmarkDeleteTest struct {
flags []string
}

func (s *benchmarkDeleteTest) SetupB(b *testing.B) {
testDirPath = setup.SetupTestDirectory(testDirName)
mountGCSFuseAndSetupTestDir(s.flags, testDirName)
}

func (s *benchmarkDeleteTest) TeardownB(b *testing.B) {}

// createFilesToDelete creates the below objects in the bucket.
// benchmarking/a{i}.txt where i is a counter based on the benchtime value.
func createFilesToDelete(b *testing.B) {
for i := 0; i < b.N; i++ {
operations.CreateFileOfSize(5, path.Join(testDirPath, fmt.Sprintf("a%d.txt", i)), b)
}
func (s *benchmarkDeleteTest) TeardownB(b *testing.B) {
setup.UnmountGCSFuse(rootDir)
}

////////////////////////////////////////////////////////////////////////
// Test scenarios
////////////////////////////////////////////////////////////////////////

func (s *benchmarkDeleteTest) Benchmark_Delete(b *testing.B) {
createFilesToDelete(b)
createFiles(b)
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := os.Remove(path.Join(testDirPath, fmt.Sprintf("a%d.txt", i))); err != nil {
Expand All @@ -70,5 +66,15 @@ func (s *benchmarkDeleteTest) Benchmark_Delete(b *testing.B) {

func Benchmark_Delete(b *testing.B) {
ts := &benchmarkDeleteTest{}
benchmark_setup.RunBenchmarks(b, ts)

flagsSet := [][]string{
{"--stat-cache-ttl=0"}, {"--client-protocol=grpc", "--stat-cache-ttl=0"},
}

// Run tests.
for _, flags := range flagsSet {
ts.flags = flags
log.Printf("Running tests with flags: %s", ts.flags)
benchmark_setup.RunBenchmarks(b, ts)
}
}
79 changes: 79 additions & 0 deletions tools/integration_tests/benchmarking/benchmark_rename_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package benchmarking

import (
"fmt"
"log"
"os"
"path"
"testing"
"time"

"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/benchmark_setup"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup"
)

type benchmarkRenameTest struct {
flags []string
}

const (
expectedRenameLatency time.Duration = 700 * time.Millisecond
)

func (s *benchmarkRenameTest) SetupB(b *testing.B) {
mountGCSFuseAndSetupTestDir(s.flags, testDirName)
}

func (s *benchmarkRenameTest) TeardownB(b *testing.B) {
setup.UnmountGCSFuse(rootDir)
}

////////////////////////////////////////////////////////////////////////
// Test scenarios
////////////////////////////////////////////////////////////////////////

func (s *benchmarkRenameTest) Benchmark_Rename(b *testing.B) {
createFiles(b)
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := os.Rename(path.Join(testDirPath, fmt.Sprintf("a%d.txt", i)), path.Join(testDirPath, fmt.Sprintf("b%d.txt", i))); err != nil {
b.Errorf("testing error: %v", err)
}
}
averageRenameLatency := time.Duration(int(b.Elapsed()) / b.N)
if averageRenameLatency > expectedRenameLatency {
b.Errorf("RenameFile took more time (%d msec) than expected (%d msec)", averageRenameLatency.Milliseconds(), expectedRenameLatency.Milliseconds())
}
}

////////////////////////////////////////////////////////////////////////
// Test Function (Runs once before all tests)
////////////////////////////////////////////////////////////////////////

func Benchmark_Rename(b *testing.B) {
ts := &benchmarkRenameTest{}
flagsSet := [][]string{
{"--stat-cache-ttl=0", "--enable-atomic-rename-object=true"}, {"--client-protocol=grpc", "--stat-cache-ttl=0", "--enable-atomic-rename-object=true"},
}

// Run tests.
for _, flags := range flagsSet {
ts.flags = flags
log.Printf("Running tests with flags: %s", ts.flags)
benchmark_setup.RunBenchmarks(b, ts)
}
}
22 changes: 18 additions & 4 deletions tools/integration_tests/benchmarking/benchmark_stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package benchmarking

import (
"log"
"path"
"testing"
"time"
Expand All @@ -32,13 +33,17 @@ const (
expectedStatLatency time.Duration = 390 * time.Millisecond
)

type benchmarkStatTest struct{}
type benchmarkStatTest struct {
flags []string
}

func (s *benchmarkStatTest) SetupB(b *testing.B) {
testDirPath = setup.SetupTestDirectory(testDirName)
mountGCSFuseAndSetupTestDir(s.flags, testDirName)
}

func (s *benchmarkStatTest) TeardownB(b *testing.B) {}
func (s *benchmarkStatTest) TeardownB(b *testing.B) {
setup.UnmountGCSFuse(rootDir)
}

// createFilesToStat creates the below object in the bucket.
// benchmarking/a.txt
Expand Down Expand Up @@ -70,5 +75,14 @@ func (s *benchmarkStatTest) Benchmark_Stat(b *testing.B) {

func Benchmark_Stat(b *testing.B) {
ts := &benchmarkStatTest{}
benchmark_setup.RunBenchmarks(b, ts)
flagsSet := [][]string{
{"--stat-cache-ttl=0"}, {"--client-protocol=grpc", "--stat-cache-ttl=0"},
}

// Run tests.
for _, flags := range flagsSet {
ts.flags = flags
log.Printf("Running tests with flags: %s", ts.flags)
benchmark_setup.RunBenchmarks(b, ts)
}
}
40 changes: 35 additions & 5 deletions tools/integration_tests/benchmarking/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package benchmarking

import (
"context"
"fmt"
"log"
"os"
"path"
Expand All @@ -24,6 +25,7 @@ import (
"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/mounting/static_mounting"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/operations"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup"
)

Expand All @@ -35,8 +37,35 @@ var (
storageClient *storage.Client
ctx context.Context
testDirPath string
mountFunc func([]string) error
// mount directory is where our tests run.
mountDir string
// root directory is the directory to be unmounted.
rootDir string
)

////////////////////////////////////////////////////////////////////////
// Helpers
////////////////////////////////////////////////////////////////////////

func mountGCSFuseAndSetupTestDir(flags []string, testDirName string) {
// When tests are running in GKE environment, use the mounted directory provided as test flag.
if setup.MountedDirectory() != "" {
mountDir = setup.MountedDirectory()
}
setup.MountGCSFuseWithGivenMountFunc(flags, mountFunc)
setup.SetMntDir(mountDir)
testDirPath = setup.SetupTestDirectory(testDirName)
}

// createFiles creates the below objects in the bucket.
// benchmarking/a{i}.txt where i is a counter based on the benchtime value.
func createFiles(b *testing.B) {
for i := 0; i < b.N; i++ {
operations.CreateFileOfSize(5, path.Join(testDirPath, fmt.Sprintf("a%d.txt", i)), b)
}
}

func TestMain(m *testing.M) {
setup.ParseSetUpFlags()
setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()
Expand All @@ -57,11 +86,12 @@ func TestMain(m *testing.M) {
// Set up test directory.
setup.SetUpTestDirForTestBucketFlag()

flagsSet := [][]string{
{"--stat-cache-ttl=0"},
{"--client-protocol=grpc", "--stat-cache-ttl=0"},
}
successCode := static_mounting.RunTests(flagsSet, m)
// Save mount and root directory variables.
mountDir, rootDir = setup.MntDir(), setup.MntDir()

log.Println("Running static mounting tests...")
mountFunc = static_mounting.MountGcsfuseWithStaticMounting
successCode := m.Run()

// Clean up test directory created.
setup.CleanupDirectoryOnGCS(ctx, storageClient, path.Join(setup.TestBucket(), testDirName))
Expand Down
Loading