MCPcopy
hub / github.com/grafana/tempo / runWALBenchmarkWithAppendMode

Function runWALBenchmarkWithAppendMode

tempodb/wal/wal_test.go:507–565  ·  tempodb/wal/wal_test.go::runWALBenchmarkWithAppendMode
(b *testing.B, encoding string, flushCount int, appendTrace bool, runner func([][]byte, []*tempopb.Trace, common.WALBlock))

Source from the content-addressed store, hash-verified

505}
506
507func runWALBenchmarkWithAppendMode(b *testing.B, encoding string, flushCount int, appendTrace bool, runner func([][]byte, []*tempopb.Trace, common.WALBlock)) {
508 wal, err := New(&Config{
509 Filepath: b.TempDir(),
510 Version: encoding,
511 })
512 require.NoError(b, err, "unexpected error creating temp wal")
513
514 blockID := uuid.New()
515
516 meta := backend.NewBlockMeta("fake", blockID, encoding)
517 block, err := wal.NewBlock(meta, model.CurrentEncoding)
518 require.NoError(b, err, "unexpected error creating block")
519
520 dec := model.MustNewSegmentDecoder(model.CurrentEncoding)
521
522 objects := 250
523 traces := make([]*tempopb.Trace, 0, objects)
524 objs := make([][]byte, 0, objects)
525 ids := make([][]byte, 0, objects)
526 for i := 0; i < objects; i++ {
527 id := make([]byte, 16)
528 _, err = crand.Read(id)
529 require.NoError(b, err)
530 obj := test.MakeTrace(rand.Int()%10+1, id)
531
532 trace.SortTrace(obj)
533
534 ids = append(ids, id)
535 traces = append(traces, obj)
536
537 b1, err := dec.PrepareForWrite(obj, 0, 0)
538 require.NoError(b, err)
539
540 b2, err := dec.ToObject([][]byte{b1})
541 require.NoError(b, err)
542
543 objs = append(objs, b2)
544 }
545
546 b.ResetTimer()
547
548 for flush := 0; flush < flushCount; flush++ {
549
550 for i := range traces {
551 if appendTrace {
552 require.NoError(b, block.AppendTrace(ids[i], traces[i], 0, 0, true))
553 } else {
554 require.NoError(b, block.Append(ids[i], objs[i], 0, 0, true))
555 }
556 }
557
558 err = block.Flush()
559 require.NoError(b, err)
560 }
561
562 if runner != nil {
563 runner(ids, traces, block)
564 }

Callers 2

BenchmarkAppendFlushFunction · 0.85
runWALBenchmarkFunction · 0.85

Calls 13

NewBlockMetaFunction · 0.92
MustNewSegmentDecoderFunction · 0.92
MakeTraceFunction · 0.92
SortTraceFunction · 0.92
NewBlockMethod · 0.80
IntMethod · 0.80
NewFunction · 0.70
ReadMethod · 0.65
PrepareForWriteMethod · 0.65
ToObjectMethod · 0.65
AppendTraceMethod · 0.65
AppendMethod · 0.65

Tested by

no test coverage detected