Skip to content

Commit 02cc18f

Browse files
jiukerharshavardhana
authored andcommitted
refactor the perf client for TTFB and TotalResponseTime (minio#17901)
1 parent ba4566e commit 02cc18f

File tree

2 files changed

+70
-75
lines changed

2 files changed

+70
-75
lines changed

cmd/perf-tests.go

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package cmd
1919

2020
import (
2121
"context"
22+
"encoding/gob"
2223
"errors"
2324
"fmt"
2425
"io"
@@ -367,29 +368,14 @@ func siteNetperf(ctx context.Context, duration time.Duration) madmin.SiteNetPerf
367368
for i := 0; i < connectionsPerPeer; i++ {
368369
go func() {
369370
defer wg.Done()
370-
cli, err := globalSiteReplicationSys.getAdminClient(ctx, info.DeploymentID)
371-
if err != nil {
372-
return
373-
}
374-
rp := cli.GetEndpointURL()
375-
reqURL := &url.URL{
376-
Scheme: rp.Scheme,
377-
Host: rp.Host,
378-
Path: adminPathPrefix + adminAPIVersionPrefix + adminAPISiteReplicationDevNull,
379-
}
380-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL.String(), r)
381-
if err != nil {
382-
return
383-
}
384-
client := &http.Client{
385-
Timeout: duration + 10*time.Second,
386-
Transport: globalRemoteTargetTransport,
387-
}
388-
resp, err := client.Do(req)
389-
if err != nil {
390-
return
391-
}
392-
defer xhttp.DrainBody(resp.Body)
371+
ctx, cancel := context.WithTimeout(ctx, duration+10*time.Second)
372+
defer cancel()
373+
perfNetRequest(
374+
ctx,
375+
info.DeploymentID,
376+
adminPathPrefix+adminAPIVersionPrefix+adminAPISiteReplicationDevNull,
377+
r,
378+
)
393379
}()
394380
}
395381
}
@@ -422,3 +408,41 @@ func siteNetperf(ctx context.Context, duration time.Duration) madmin.SiteNetPerf
422408
TotalConn: uint64(connectionsPerPeer),
423409
}
424410
}
411+
412+
// perfNetRequest - reader for http.request.body
413+
func perfNetRequest(ctx context.Context, deploymentID, reqPath string, reader io.Reader) (result madmin.SiteNetPerfNodeResult) {
414+
result = madmin.SiteNetPerfNodeResult{}
415+
cli, err := globalSiteReplicationSys.getAdminClient(ctx, deploymentID)
416+
if err != nil {
417+
result.Error = err.Error()
418+
return
419+
}
420+
rp := cli.GetEndpointURL()
421+
reqURL := &url.URL{
422+
Scheme: rp.Scheme,
423+
Host: rp.Host,
424+
Path: reqPath,
425+
}
426+
result.Endpoint = rp.String()
427+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL.String(), reader)
428+
if err != nil {
429+
result.Error = err.Error()
430+
return
431+
}
432+
client := &http.Client{
433+
Transport: globalRemoteTargetTransport,
434+
}
435+
resp, err := client.Do(req)
436+
if err != nil {
437+
result.Error = err.Error()
438+
return
439+
}
440+
defer xhttp.DrainBody(resp.Body)
441+
err = gob.NewDecoder(resp.Body).Decode(&result)
442+
// endpoint have been overwritten
443+
result.Endpoint = rp.String()
444+
if err != nil {
445+
result.Error = err.Error()
446+
}
447+
return
448+
}

cmd/site-replication.go

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ import (
2222
"context"
2323
"encoding/base64"
2424
"encoding/binary"
25-
"encoding/gob"
2625
"encoding/json"
2726
"encoding/xml"
2827
"errors"
2928
"fmt"
30-
"net/http"
3129
"net/url"
3230
"reflect"
3331
"runtime"
@@ -43,7 +41,6 @@ import (
4341
"github.com/minio/minio-go/v7/pkg/set"
4442
"github.com/minio/minio/internal/auth"
4543
sreplication "github.com/minio/minio/internal/bucket/replication"
46-
xhttp "github.com/minio/minio/internal/http"
4744
"github.com/minio/minio/internal/logger"
4845
bktpolicy "github.com/minio/pkg/bucket/policy"
4946
iampolicy "github.com/minio/pkg/iam/policy"
@@ -663,64 +660,38 @@ func (c *SiteReplicationSys) Netperf(ctx context.Context, duration time.Duration
663660
// will call siteNetperf, means call others's adminAPISiteReplicationDevNull
664661
if globalDeploymentID == info.DeploymentID {
665662
wg.Add(1)
666-
go func() (err error) {
663+
go func() {
667664
defer wg.Done()
668-
result := &madmin.SiteNetPerfNodeResult{}
669-
defer func() {
670-
if err != nil {
671-
result.Error = err.Error()
672-
}
673-
resultsMu.Lock()
674-
results.NodeResults = append(results.NodeResults, *result)
675-
resultsMu.Unlock()
676-
}()
665+
result := madmin.SiteNetPerfNodeResult{}
677666
cli, err := globalSiteReplicationSys.getAdminClient(ctx, info.DeploymentID)
678-
if err != nil {
679-
return err
680-
}
681-
*result = siteNetperf(ctx, duration)
682-
result.Endpoint = cli.GetEndpointURL().String()
683-
return nil
684-
}()
685-
continue
686-
}
687-
wg.Add(1)
688-
go func() (err error) {
689-
defer wg.Done()
690-
result := madmin.SiteNetPerfNodeResult{}
691-
defer func() {
692667
if err != nil {
693668
result.Error = err.Error()
669+
} else {
670+
result = siteNetperf(ctx, duration)
671+
result.Endpoint = cli.GetEndpointURL().String()
694672
}
695673
resultsMu.Lock()
696674
results.NodeResults = append(results.NodeResults, result)
697675
resultsMu.Unlock()
676+
return
698677
}()
699-
cli, err := globalSiteReplicationSys.getAdminClient(ctx, info.DeploymentID)
700-
if err != nil {
701-
return err
702-
}
703-
rp := cli.GetEndpointURL()
704-
reqURL := &url.URL{
705-
Scheme: rp.Scheme,
706-
Host: rp.Host,
707-
Path: adminPathPrefix + adminAPIVersionPrefix + adminAPISiteReplicationNetPerf,
708-
}
709-
result.Endpoint = rp.String()
710-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL.String(), nil)
711-
if err != nil {
712-
return err
713-
}
714-
client := &http.Client{
715-
Timeout: duration + 10*time.Second,
716-
Transport: globalRemoteTargetTransport,
717-
}
718-
resp, err := client.Do(req)
719-
if err != nil {
720-
return err
721-
}
722-
defer xhttp.DrainBody(resp.Body)
723-
return gob.NewDecoder(resp.Body).Decode(&result)
678+
continue
679+
}
680+
wg.Add(1)
681+
go func() {
682+
defer wg.Done()
683+
ctx, cancel := context.WithTimeout(ctx, duration+10*time.Second)
684+
defer cancel()
685+
result := perfNetRequest(
686+
ctx,
687+
info.DeploymentID,
688+
adminPathPrefix+adminAPIVersionPrefix+adminAPISiteReplicationNetPerf,
689+
nil,
690+
)
691+
resultsMu.Lock()
692+
results.NodeResults = append(results.NodeResults, result)
693+
resultsMu.Unlock()
694+
return
724695
}()
725696
}
726697
wg.Wait()

0 commit comments

Comments
 (0)