diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 0278c4ac9..5fa5d71c7 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -1054,15 +1054,8 @@ func (a adminAPIHandlers) ObjectSpeedtestHandler(w http.ResponseWriter, r *http. autotune = false } - err = objectAPI.MakeBucketWithLocation(ctx, globalObjectPerfBucket, BucketOptions{}) - if _, ok := err.(BucketExists); !ok { - // Only BucketExists error can be ignored. - writeErrorResponseJSON(ctx, w, toAPIError(ctx, err), r.URL) - return - } - deleteBucket := func() { - objectAPI.DeleteBucket(context.Background(), globalObjectPerfBucket, DeleteBucketOptions{ + objectAPI.DeleteBucket(context.Background(), pathJoin(minioMetaBucket, "speedtest"), DeleteBucketOptions{ Force: true, NoRecreate: true, }) diff --git a/cmd/globals.go b/cmd/globals.go index 4aba95ff2..0e3068969 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -349,7 +349,6 @@ var ( // Used for collecting stats for netperf globalNetPerfMinDuration = time.Second * 10 globalNetPerfRX netPerfRX - globalObjectPerfBucket = "minio-perf-test-tmp-bucket" // Add new variable global values here. ) diff --git a/cmd/perf-tests.go b/cmd/perf-tests.go index 52a4df7f2..3ac43d859 100644 --- a/cmd/perf-tests.go +++ b/cmd/perf-tests.go @@ -24,7 +24,6 @@ import ( "io" "io/ioutil" "math/rand" - "net/http" "sync" "sync/atomic" "time" @@ -32,8 +31,8 @@ import ( "github.com/dustin/go-humanize" "github.com/google/uuid" "github.com/minio/madmin-go" - "github.com/minio/minio-go/v7" - "github.com/minio/minio-go/v7/pkg/credentials" + "github.com/minio/minio/internal/hash" + xhttp "github.com/minio/minio/internal/http" "github.com/minio/pkg/randreader" ) @@ -62,15 +61,6 @@ func selfSpeedtest(ctx context.Context, size, concurrent int, duration time.Dura var totalBytesWritten uint64 var totalBytesRead uint64 - client, err := minio.NewCore(globalLocalNodeName, &minio.Options{ - Creds: credentials.NewStaticV4(globalActiveCred.AccessKey, globalActiveCred.SecretKey, ""), - Secure: globalIsTLS, - Transport: globalProxyTransport, - }) - if err != nil { - return SpeedtestResult{}, err - } - objCountPerThread := make([]uint64, concurrent) uploadsCtx, uploadsCancel := context.WithCancel(context.Background()) @@ -81,15 +71,15 @@ func selfSpeedtest(ctx context.Context, size, concurrent int, duration time.Dura uploadsCancel() }() - objNamePrefix := uuid.New().String() + "/" + objNamePrefix := "speedtest/objects/" + uuid.New().String() wg.Add(concurrent) for i := 0; i < concurrent; i++ { go func(i int) { defer wg.Done() for { - reader := newRandomReader(size) - _, err := client.PutObject(uploadsCtx, globalObjectPerfBucket, fmt.Sprintf("%s/%d.%d", objNamePrefix, i, objCountPerThread[i]), reader, int64(size), "", "", minio.PutObjectOptions{}) + hashReader, err := hash.NewReader(newRandomReader(size), + int64(size), "", "", int64(size)) if err != nil { if !contextCanceled(uploadsCtx) && !errors.Is(err, context.Canceled) { errOnce.Do(func() { @@ -99,7 +89,25 @@ func selfSpeedtest(ctx context.Context, size, concurrent int, duration time.Dura uploadsCancel() return } - atomic.AddUint64(&totalBytesWritten, uint64(size)) + reader := NewPutObjReader(hashReader) + objInfo, err := objAPI.PutObject(uploadsCtx, minioMetaBucket, fmt.Sprintf("%s.%d.%d", + objNamePrefix, i, objCountPerThread[i]), reader, ObjectOptions{ + UserDefined: map[string]string{ + xhttp.AmzStorageClass: storageClass, + }, + Speedtest: true, + }) + if err != nil { + objCountPerThread[i]-- + if !contextCanceled(uploadsCtx) && !errors.Is(err, context.Canceled) { + errOnce.Do(func() { + retError = err.Error() + }) + } + uploadsCancel() + return + } + atomic.AddUint64(&totalBytesWritten, uint64(objInfo.Size)) objCountPerThread[i]++ } }(i) @@ -130,10 +138,10 @@ func selfSpeedtest(ctx context.Context, size, concurrent int, duration time.Dura if objCountPerThread[i] == j { j = 0 } - r, _, _, err := client.GetObject(downloadsCtx, globalObjectPerfBucket, fmt.Sprintf("%s/%d.%d", objNamePrefix, i, j), minio.GetObjectOptions{}) + r, err := objAPI.GetObjectNInfo(downloadsCtx, minioMetaBucket, fmt.Sprintf("%s.%d.%d", + objNamePrefix, i, j), nil, nil, noLock, ObjectOptions{}) if err != nil { - errResp, ok := err.(minio.ErrorResponse) - if ok && errResp.StatusCode == http.StatusNotFound { + if isErrObjectNotFound(err) { continue } if !contextCanceled(downloadsCtx) && !errors.Is(err, context.Canceled) {