Skip to content

TTFB for bitswap shouldn't include candidate collection #333

@rvagg

Description

@rvagg

Arising out of this: https://github.com/filecoin-project/lassie/pull/321/files#r1243072856

Discussed today in a call and agreed that we should roughly align it to the other retrievers.

This block:

bytesWrittenCb := func(bytesWritten uint64) {
// record first byte received
if totalWritten.Load() == 0 {
br.events(events.FirstByte(br.clock.Now(), br.request.RetrievalID, phaseStartTime, bitswapCandidate, br.clock.Since(phaseStartTime)))
}
totalWritten.Add(bytesWritten)
blockCount.Add(1)
// reset the timer
if bytesWritten > 0 && lastBytesReceivedTimer != nil {
lastBytesReceivedTimer.Reset(br.cfg.BlockTimeout)
}
}
// setup providers for this retrieval
hasCandidates, nextCandidates, err := ayncCandidates.Next(ctx)
if !hasCandidates || err != nil {
cancel()
// we never received any candidates, so we give up on bitswap retrieval
return nil, nil
}
br.events(events.Started(br.clock.Now(), br.request.RetrievalID, phaseStartTime, types.RetrievalPhase, bitswapCandidate, multicodec.TransportBitswap))

The duration in FirstByte is taken from phaseStartTime (startTime in #321) which is at the top of RetrieveFromAsyncCandidates which is prior to collecting the first batch of candidates. The other retrievers take this duration from the beginning of asking the candidate for the data. But for Bitswap it's before we even collect candidates.

Likely solution

The bytesWrittenCb should be moved down lower and a new start clock time recorded before it. That new start time can be used by both the Started event and the FirstByte duration calculation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech debtNon-critical change that can wait to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions