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

feat: add benchmark tools and fixed downloading #73

Merged
merged 3 commits into from
Oct 31, 2024
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
6 changes: 4 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ jobs:
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: '0'

- name: Golangci lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8
with:
version: v1.54
args: --verbose
Expand Down
16 changes: 16 additions & 0 deletions benchmark/cmd/dfbench/dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ func runDragonfly(ctx context.Context, cfg *config.Config) error {
logrus.Errorf("failed to run dragonfly benchmark: %v", err)
return err
}
logrus.Info("completed dragonfly benchmark")

logrus.Info("cleaning up dragonfly benchmark")
if err := dragonfly.Cleanup(ctx); err != nil {
logrus.Errorf("failed to cleanup dragonfly benchmark: %v", err)
return err
}

logrus.Info("completed dragonfly cleanup")
return nil
}

Expand All @@ -80,6 +88,14 @@ func runDragonfly(ctx context.Context, cfg *config.Config) error {
logrus.Errorf("failed to run dragonfly benchmark: %v", err)
return err
}
logrus.Info("completed dragonfly benchmark")

logrus.Info("cleaning up dragonfly benchmark")
if err := dragonfly.Cleanup(ctx); err != nil {
logrus.Errorf("failed to cleanup dragonfly benchmark: %v", err)
return err
}

logrus.Info("completed dragonfly cleanup")
return nil
}
68 changes: 61 additions & 7 deletions benchmark/pkg/dragonfly/dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@ package dragonfly
import (
"context"
"errors"
"os"
"fmt"
"path"

"github.com/dragonflyoss/perf-tests/benchmark/pkg/backend"
"github.com/dragonflyoss/perf-tests/benchmark/pkg/config"
"github.com/dragonflyoss/perf-tests/benchmark/pkg/util"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
)

const (
OutputDir = "/tmp"
)

// Dragonfly represents a benchmark runner for Dragonfly.
type Dragonfly interface {
// Run runs all benchmarks.
Expand All @@ -42,6 +47,9 @@ type Dragonfly interface {

// DownloadFileByProxy downloads file by proxy.
DownloadFileByProxy(context.Context, backend.FileSizeLevel) error

// Cleanup cleans up the downloaded files.
Cleanup(context.Context) error
}

// dragonfly implements the Dragonfly interface.
Expand Down Expand Up @@ -195,10 +203,15 @@ func (d *dragonfly) downloadFileByDfget(ctx context.Context, podExec *util.PodEx
return err
}

outputPath := path.Join(os.TempDir(), path.Base(downloadURL.Path))
output, err := podExec.Command(ctx, "dfget", downloadURL.String(), "--output", outputPath).CombinedOutput()
outputPath, err := d.getOutput(fileSizeLevel, "dfget")
if err != nil {
logrus.Errorf("failed to get output path: %v", err)
return err
}

output, err := podExec.Command(ctx, "sh", "-c", fmt.Sprintf("dfget '%s' --output %s", downloadURL.String(), outputPath)).CombinedOutput()
if err != nil {
logrus.Errorf("failed to download file: %v", err)
logrus.Errorf("failed to download file: %v \nmessage: %s", err, string(output))
return err
}

Expand Down Expand Up @@ -242,17 +255,53 @@ func (d *dragonfly) downloadFileByProxy(ctx context.Context, podExec *util.PodEx
return err
}

outputPath := path.Join(os.TempDir(), path.Base(downloadURL.Path))
output, err := podExec.Command(ctx, "curl", "-x", "http://127.0.0.1:4001", downloadURL.String(), "--output", outputPath).CombinedOutput()
outputPath, err := d.getOutput(fileSizeLevel, "proxy")
if err != nil {
logrus.Errorf("failed to get output path: %v", err)
return err
}

output, err := podExec.Command(ctx, "sh", "-c", fmt.Sprintf("curl -x %s '%s' --output %s", "http://127.0.0.1:4001", downloadURL.String(), outputPath)).CombinedOutput()
if err != nil {
logrus.Errorf("failed to download file: %v", err)
logrus.Errorf("failed to download file: %v \nmessage: %s", err, string(output))
return err
}

logrus.Debugf("curl output: %s", string(output))
return nil
}

// Cleanup cleans up the downloaded files.
func (d *dragonfly) Cleanup(ctx context.Context) error {
pods, err := d.getClientPods(ctx)
if err != nil {
return err
}

var eg errgroup.Group
for _, pod := range pods {
podExec := util.NewPodExec(d.namespace, pod, "client")
eg.Go(func(podExec *util.PodExec) func() error {
return func() error {
output, err := podExec.Command(ctx, "sh", "-c", fmt.Sprintf("rm -rf %s/*", OutputDir)).CombinedOutput()
if err != nil {
logrus.Errorf("failed to cleanup: %v \nmessage: %s", err, string(output))
return err
}

return nil
}
}(podExec))
}

if err := eg.Wait(); err != nil {
logrus.Errorf("error processing pods: %v", err)
return err
}

return nil
}

// getClientPods returns the client pods.
func (d *dragonfly) getClientPods(ctx context.Context) ([]string, error) {
pods, err := util.GetPods(ctx, d.namespace, "component=client")
Expand All @@ -268,3 +317,8 @@ func (d *dragonfly) getClientPods(ctx context.Context) ([]string, error) {

return pods, nil
}

// getOutput returns the output path.
func (d *dragonfly) getOutput(fileSizeLevel backend.FileSizeLevel, tag string) (string, error) {
return path.Join(OutputDir, fmt.Sprintf("%s-%s-%s", string(fileSizeLevel), tag, uuid.New().String())), nil
}
1 change: 1 addition & 0 deletions tools/file-server/file-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spec:
app: dragonfly
component: file-server
type: ClusterIP
clusterIP: None
ports:
- name: nginx
port: 80
Expand Down