From b1391d199159caaef9d0ebf85bdbb5f378466cb1 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Thu, 10 Aug 2023 22:14:46 +0800 Subject: [PATCH] feat: support perf client to show `TX` from client to server (#17718) --- cmd/admin-handlers.go | 61 +++++++++++++++++++++++++++++++++++++++++++ cmd/admin-router.go | 4 +++ cmd/globals.go | 2 ++ go.mod | 2 +- go.sum | 4 +-- 5 files changed, 70 insertions(+), 3 deletions(-) diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 187e21928..d8b3153cc 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -41,6 +41,7 @@ import ( "sort" "strconv" "strings" + "sync/atomic" "time" "github.com/dustin/go-humanize" @@ -1172,6 +1173,66 @@ func (a adminAPIHandlers) SitePerfHandler(w http.ResponseWriter, r *http.Request } } +// ClientDevNullExtraTime - return extratime for last devnull +// [POST] /minio/admin/v3/speedtest/client/devnull/extratime +func (a adminAPIHandlers) ClientDevNullExtraTime(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + objectAPI, _ := validateAdminReq(ctx, w, r, iampolicy.BandwidthMonitorAction) + if objectAPI == nil { + return + } + + enc := json.NewEncoder(w) + if err := enc.Encode(madmin.ClientPerfExtraTime{TimeSpent: globalLastClientPerfExtraTime}); err != nil { + return + } +} + +// ClientDevNull - everything goes to io.Discard +// [POST] /minio/admin/v3/speedtest/client/devnull +func (a adminAPIHandlers) ClientDevNull(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + timeStart := time.Now() + objectAPI, _ := validateAdminReq(ctx, w, r, iampolicy.BandwidthMonitorAction) + if objectAPI == nil { + return + } + + nsLock := objectAPI.NewNSLock(minioMetaBucket, "client-perf") + lkctx, err := nsLock.GetLock(ctx, globalOperationTimeout) + if err != nil { + writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(toAPIErrorCode(ctx, err)), r.URL) + return + } + ctx = lkctx.Context() + defer nsLock.Unlock(lkctx) + timeEnd := time.Now() + + atomic.SwapInt64(&globalLastClientPerfExtraTime, timeEnd.Sub(timeStart).Nanoseconds()) + + ctx, cancel := context.WithTimeout(ctx, madmin.MaxClientPerfTimeout) + defer cancel() + totalRx := int64(0) + connectTime := time.Now() + for { + n, err := io.CopyN(io.Discard, r.Body, 128*humanize.KiByte) + if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { + // would mean the network is not stable. Logging here will help in debugging network issues. + if time.Since(connectTime) < (globalNetPerfMinDuration - time.Second) { + logger.LogIf(ctx, err) + } + } + totalRx += n + if err != nil || ctx.Err() != nil || totalRx > 100*humanize.GiByte { + break + } + + } + w.WriteHeader(http.StatusOK) +} + // NetperfHandler - perform mesh style network throughput test func (a adminAPIHandlers) NetperfHandler(w http.ResponseWriter, r *http.Request) { ctx := r.Context() diff --git a/cmd/admin-router.go b/cmd/admin-router.go index cc60b7e52..ff7bd88c3 100644 --- a/cmd/admin-router.go +++ b/cmd/admin-router.go @@ -36,6 +36,8 @@ const ( adminAPIVersionPrefix = SlashSeparator + adminAPIVersion adminAPISiteReplicationDevNull = "/site-replication/devnull" adminAPISiteReplicationNetPerf = "/site-replication/netperf" + adminAPIClientDevNull = "/speedtest/client/devnull" + adminAPIClientDevExtraTime = "/speedtest/client/devnull/extratime" ) var gzipHandler = func() func(http.Handler) http.HandlerFunc { @@ -388,6 +390,8 @@ func registerAdminRouter(router *mux.Router, enableConfigOps bool) { adminRouter.Methods(http.MethodPost).Path(adminVersion + "/speedtest/drive").HandlerFunc(adminMiddleware(adminAPI.DriveSpeedtestHandler, noGZFlag)) adminRouter.Methods(http.MethodPost).Path(adminVersion + "/speedtest/net").HandlerFunc(adminMiddleware(adminAPI.NetperfHandler, noGZFlag)) adminRouter.Methods(http.MethodPost).Path(adminVersion + "/speedtest/site").HandlerFunc(adminMiddleware(adminAPI.SitePerfHandler, noGZFlag)) + adminRouter.Methods(http.MethodPost).Path(adminVersion + adminAPIClientDevNull).HandlerFunc(adminMiddleware(adminAPI.ClientDevNull, noGZFlag)) + adminRouter.Methods(http.MethodPost).Path(adminVersion + adminAPIClientDevExtraTime).HandlerFunc(adminMiddleware(adminAPI.ClientDevNullExtraTime, noGZFlag)) // HTTP Trace adminRouter.Methods(http.MethodGet).Path(adminVersion + "/trace").HandlerFunc(adminMiddleware(adminAPI.TraceHandler, noObjLayerFlag)) diff --git a/cmd/globals.go b/cmd/globals.go index 7d354760f..3ad0f07d3 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -397,6 +397,8 @@ var ( globalInternodeInterface string globalInternodeInterfaceOnce sync.Once + // Set last client perf extra time (get lock, and validate) + globalLastClientPerfExtraTime int64 // Add new variable global values here. ) diff --git a/go.mod b/go.mod index a1385a49b..8d21b5f6b 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,7 @@ require ( github.com/minio/dperf v0.5.0 github.com/minio/highwayhash v1.0.2 github.com/minio/kes-go v0.1.0 - github.com/minio/madmin-go/v3 v3.0.9 + github.com/minio/madmin-go/v3 v3.0.11 github.com/minio/minio-go/v7 v7.0.61 github.com/minio/mux v1.9.0 github.com/minio/pkg v1.7.5 diff --git a/go.sum b/go.sum index 4b9dbaff8..7e4411123 100644 --- a/go.sum +++ b/go.sum @@ -485,8 +485,8 @@ github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/minio/kes-go v0.1.0 h1:h201DyOYP5sTqajkxFGxmXz/kPbT8HQNX1uh3Yx2PFc= github.com/minio/kes-go v0.1.0/go.mod h1:VorHLaIYis9/MxAHAtXN4d8PUMNKhIxTIlvFt0hBOEo= -github.com/minio/madmin-go/v3 v3.0.9 h1:Iel1A4Ab+MWEcX3xPrfmDGy/0z2l/PZkCNxmy/B/kHU= -github.com/minio/madmin-go/v3 v3.0.9/go.mod h1:lPrMoc1aeiIWmmrxBthkDqzMPQwC/Lu9ByuyM2wenJk= +github.com/minio/madmin-go/v3 v3.0.11 h1:7QrZkgbQ5+qTKGy6Nok2A8OgLAcn/lcMYYuSgiZrgBE= +github.com/minio/madmin-go/v3 v3.0.11/go.mod h1:DMXyWO670OXwZNN0v4ZrEodl9oLOcaPJIZhpoHpu7aw= github.com/minio/mc v0.0.0-20230726035150-6b8680a2f7ca h1:y/dJJuWhlVYN9tqBxoHvGCpJ7olVuPa1whg+GS1m1a8= github.com/minio/mc v0.0.0-20230726035150-6b8680a2f7ca/go.mod h1:9x/wxYmFZCP+FMVZe57igzxENRGNOFBrucj3m4NqByg= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=