Skip to content

Commit

Permalink
get extratime for lock
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhi.li committed Aug 7, 2023
1 parent e06bf90 commit 2f88b58
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions perf-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ package madmin

import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"math/rand"
"net/http"
Expand All @@ -31,6 +33,11 @@ import (
"github.com/dustin/go-humanize"
)

// ClientPerfExtraTime - time for get lock or other
type ClientPerfExtraTime struct {
Dur int64 `json:"dur,omitempty"`
}

// ClientPerfResult - stats from client to server
type ClientPerfResult struct {
TX uint64 `json:"tx,omitempty"`
Expand Down Expand Up @@ -98,11 +105,29 @@ func (adm *AdminClient) ClientPerf(ctx context.Context, dur time.Duration) (resu
if errors.Is(err, context.DeadlineExceeded) {
err = nil
}

resp, err := adm.executeMethod(context.Background(), http.MethodPost, requestData{
queryValues: queryVals,
relPath: adminAPIPrefix + "/speedtest/client/devnull/extratime",
})
if err != nil {
return ClientPerfResult{}, err
}
var extraTime ClientPerfExtraTime
dec := json.NewDecoder(resp.Body)
err = dec.Decode(&extraTime)
if err != nil {
return result, err
return ClientPerfResult{}, err
}
durSpend := reader.endTime.Sub(reader.startTime).Nanoseconds()
if extraTime.Dur > 0 {
durSpend = durSpend - extraTime.Dur
}
if durSpend <= 0 {
return ClientPerfResult{}, fmt.Errorf("DurSpend is unexpected! Spent too much at get the lock!")
}
return ClientPerfResult{
TX: uint64(float64(reader.count) / reader.endTime.Sub(reader.startTime).Seconds()),
TX: uint64(float64(reader.count) / time.Duration(durSpend).Seconds()),
Error: "",
}, err
}

0 comments on commit 2f88b58

Please sign in to comment.