Skip to content

Commit 56bd548

Browse files
committed
roachtest: capture metrics for index backfill in schemachange/bulkingest
This will allow us to make a roachperf chart to track changes over time. Release note: None
1 parent 8b5e34a commit 56bd548

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pkg/cmd/roachtest/tests/schemachange.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
1515
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
1616
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry"
17+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil"
1718
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil/task"
1819
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/spec"
1920
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
@@ -339,11 +340,40 @@ func makeSchemaChangeBulkIngestTest(
339340
return registry.TestSpec{
340341
Name: "schemachange/bulkingest",
341342
Owner: registry.OwnerSQLFoundations,
343+
Benchmark: true,
342344
Cluster: r.MakeClusterSpec(numNodes, spec.WorkloadNode(), spec.SSD(4)),
343345
CompatibleClouds: registry.AllExceptAWS,
344346
Suites: registry.Suites(registry.Nightly),
345347
Leases: registry.MetamorphicLeases,
346348
Timeout: length * 2,
349+
PostProcessPerfMetrics: func(test string, histogram *roachtestutil.HistogramMetric) (roachtestutil.AggregatedPerfMetrics, error) {
350+
// The histogram tracks the total elapsed time for the CREATE INDEX operation.
351+
totalElapsed := histogram.Elapsed
352+
353+
// Calculate the approximate data size for the index.
354+
// The index is on (payload, a) where payload is 40 bytes.
355+
// Approximate size per row for index: 40 bytes (payload) + 8 bytes (a) = 48 bytes
356+
rowsIndexed := int64(numRows)
357+
bytesPerRow := int64(48)
358+
mb := int64(1 << 20)
359+
dataSizeInMB := (rowsIndexed * bytesPerRow) / mb
360+
361+
// Calculate throughput in MB/s per node.
362+
indexDuration := int64(totalElapsed / 1000) // Convert to seconds.
363+
if indexDuration == 0 {
364+
indexDuration = 1 // Avoid division by zero.
365+
}
366+
avgRatePerNode := roachtestutil.MetricPoint(float64(dataSizeInMB) / float64(int64(numNodes)*indexDuration))
367+
368+
return roachtestutil.AggregatedPerfMetrics{
369+
{
370+
Name: fmt.Sprintf("%s_throughput", test),
371+
Value: avgRatePerNode,
372+
Unit: "MB/s/node",
373+
IsHigherBetter: true,
374+
},
375+
}, nil
376+
},
347377
// `fixtures import` (with the workload paths) is not supported in 2.1
348378
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
349379
// Configure column a to have sequential ascending values. The payload
@@ -372,6 +402,11 @@ func makeSchemaChangeBulkIngestTest(
372402

373403
c.Run(ctx, option.WithNodes(c.WorkloadNode()), cmdWrite)
374404

405+
// Set up histogram exporter for performance metrics.
406+
exporter := roachtestutil.CreateWorkloadHistogramExporter(t, c)
407+
tickHistogram, perfBuf := initBulkJobPerfArtifacts(length*2, t, exporter)
408+
defer roachtestutil.CloseExporter(ctx, exporter, t, c, perfBuf, c.Node(1), "")
409+
375410
m := c.NewDeprecatedMonitor(ctx, c.CRDBNodes())
376411

377412
indexDuration := length
@@ -402,10 +437,14 @@ func makeSchemaChangeBulkIngestTest(
402437
}
403438

404439
t.L().Printf("Creating index")
440+
// Tick once before starting the index creation.
441+
tickHistogram()
405442
before := timeutil.Now()
406443
if _, err := db.Exec(`CREATE INDEX payload_a ON bulkingest.bulkingest (payload, a)`); err != nil {
407444
t.Fatal(err)
408445
}
446+
// Tick once after the index creation to capture the total elapsed time.
447+
tickHistogram()
409448
t.L().Printf("CREATE INDEX took %v\n", timeutil.Since(before))
410449
return nil
411450
})

0 commit comments

Comments
 (0)