mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-03 13:23:07 +00:00
don't blanket wait for 1s to accumulate a batch.
Instead check the batch size and poll every 100ms (up to 1s) until the minimum batch size is accumulated.
This commit is contained in:
parent
24a1181b9a
commit
7a5aaa8d1c
12
tracer.go
12
tracer.go
@ -21,6 +21,7 @@ import (
|
||||
)
|
||||
|
||||
var TraceBufferSize = 1 << 16 // 64K ought to be enough for everyone; famous last words.
|
||||
var MinTraceBatchSize = 16
|
||||
|
||||
type basicTracer struct {
|
||||
ch chan struct{}
|
||||
@ -187,10 +188,17 @@ func (t *RemoteTracer) doWrite() {
|
||||
for {
|
||||
_, ok := <-t.ch
|
||||
|
||||
// wait a bit to accumulate a batch
|
||||
time.Sleep(time.Second)
|
||||
// deadline for batch accumulation
|
||||
deadline := time.Now().Add(time.Second)
|
||||
|
||||
again:
|
||||
t.mx.Lock()
|
||||
if len(t.buf) < MinTraceBatchSize && time.Now().Before(deadline) {
|
||||
t.mx.Unlock()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
goto again
|
||||
}
|
||||
|
||||
tmp := t.buf
|
||||
t.buf = buf[:0]
|
||||
buf = tmp
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user