mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/network: measure time of message in pq
This commit is contained in:
parent
fb458280d1
commit
35f34edced
1 changed files with 16 additions and 7 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue