swarm/network: measure time of messages in priority queue (#19250)

This commit is contained in:
Anton Evangelatov
2019-03-20 21:30:34 +01:00
committed by GitHub
parent c53c5e616f
commit baded64d88
16 changed files with 87 additions and 60 deletions

View File

@@ -28,8 +28,9 @@ package priorityqueue
import (
"context"
"errors"
"time"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
)
var (
@@ -69,13 +70,16 @@ READ:
case <-ctx.Done():
return
case x := <-q:
log.Trace("priority.queue f(x)", "p", p, "len(Queues[p])", len(pq.Queues[p]))
f(x)
val := x.(struct {
v interface{}
t time.Time
})
f(val.v)
metrics.GetOrRegisterResettingTimer("pq.run", nil).UpdateSince(val.t)
p = top
default:
if p > 0 {
p--
log.Trace("priority.queue p > 0", "p", p)
continue READ
}
p = top
@@ -83,7 +87,6 @@ READ:
case <-ctx.Done():
return
case <-pq.wakeup:
log.Trace("priority.queue wakeup", "p", p)
}
}
}
@@ -95,9 +98,15 @@ func (pq *PriorityQueue) Push(x interface{}, p int) error {
if p < 0 || p >= len(pq.Queues) {
return errBadPriority
}
log.Trace("priority.queue push", "p", p, "len(Queues[p])", len(pq.Queues[p]))
val := struct {
v interface{}
t time.Time
}{
x,
time.Now(),
}
select {
case pq.Queues[p] <- x:
case pq.Queues[p] <- val:
default:
return ErrContention
}