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(requestmanager): add request timing #181

Merged
merged 1 commit into from
Jul 28, 2021
Merged
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
10 changes: 9 additions & 1 deletion requestmanager/requestmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"sync/atomic"
"time"

"github.com/hannahhoward/go-pubsub"
"golang.org/x/xerrors"
Expand Down Expand Up @@ -39,6 +40,7 @@ const (

type inProgressRequestStatus struct {
ctx context.Context
startTime time.Time
cancelFn func()
p peer.ID
networkError chan error
Expand Down Expand Up @@ -350,6 +352,8 @@ type terminateRequestMessage struct {
}

func (nrm *newRequestMessage) setupRequest(requestID graphsync.RequestID, rm *RequestManager) (gsmsg.GraphSyncRequest, chan graphsync.ResponseProgress, chan error) {
log.Infow("graphsync request initiated", "request id", requestID, "peer", nrm.p, "root", nrm.root)

request, hooksResult, err := rm.validateRequest(requestID, nrm.p, nrm.root, nrm.selector, nrm.extensions)
if err != nil {
rp, err := rm.singleErrorResponse(err)
Expand All @@ -372,7 +376,7 @@ func (nrm *newRequestMessage) setupRequest(requestID graphsync.RequestID, rm *Re
pauseMessages := make(chan struct{}, 1)
networkError := make(chan error, 1)
requestStatus := &inProgressRequestStatus{
ctx: ctx, cancelFn: cancel, p: p, resumeMessages: resumeMessages, pauseMessages: pauseMessages, networkError: networkError,
ctx: ctx, startTime: time.Now(), cancelFn: cancel, p: p, resumeMessages: resumeMessages, pauseMessages: pauseMessages, networkError: networkError,
}
lastResponse := &requestStatus.lastResponse
lastResponse.Store(gsmsg.NewResponse(request.ID(), graphsync.RequestAcknowledged))
Expand Down Expand Up @@ -411,6 +415,10 @@ func (nrm *newRequestMessage) handle(rm *RequestManager) {
}

func (trm *terminateRequestMessage) handle(rm *RequestManager) {
ipr, ok := rm.inProgressRequestStatuses[trm.requestID]
if ok {
log.Infow("graphsync request complete", "request id", trm.requestID, "peer", ipr.p, "total time", time.Since(ipr.startTime))
}
delete(rm.inProgressRequestStatuses, trm.requestID)
rm.asyncLoader.CleanupRequest(trm.requestID)
}
Expand Down