in server/plugin/tracing/pzipkin/file_collector.go [85:130]
func (f *FileCollector) Run() {
gopool.Go(func(ctx context.Context) {
var (
batch []*zipkincore.Span
prev []*zipkincore.Span
t = time.NewTicker(f.Interval)
max = f.BatchSize * 2
)
for {
select {
case <-ctx.Done():
f.write(batch)
return
case span := <-f.c:
l := len(batch)
if l >= max {
dispose := l - f.BatchSize
log.Error(fmt.Sprintf("backlog is full, dispose %d span(s), max: %d",
dispose, max), nil)
batch = batch[dispose:] // allocate more
}
batch = append(batch, span)
l = len(batch)
if l < f.BatchSize {
continue
}
if c := f.write(batch); c == 0 {
continue
}
if prev != nil {
batch, prev = prev[:0], batch
} else {
prev, batch = batch, batch[len(batch):] // new one
}
case <-t.C:
if c := f.write(batch); c > 0 {
batch = batch[:0]
}
}
}
})
}