Skip to content

Commit

Permalink
Merge pull request #1974 from tigerbeetle/cb22/devhub-misc
Browse files Browse the repository at this point in the history
benchmark/devhub: track empty datafile size and devhub improvements
  • Loading branch information
cb22 committed May 23, 2024
2 parents e449c51 + 087606f commit 7d8a4f2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
48 changes: 34 additions & 14 deletions src/devhub/devhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ async function mainMetrics() {
const dataUrl =
"https://raw.githubusercontent.com/tigerbeetle/devhubdb/main/devhub/data.json";
const data = await (await fetch(dataUrl)).text();
const maxBatches = 200;
const batches = data.split("\n")
.filter((it) => it.length > 0)
.map((it) => JSON.parse(it));
.map((it) => JSON.parse(it))
.slice(-1 * maxBatches)
.reverse();

const series = batchesToSeries(batches);
plotSeries(series, document.querySelector("#charts"));
plotSeries(series, document.querySelector("#charts"), batches.length);
}

async function mainSeeds() {
Expand Down Expand Up @@ -150,11 +154,11 @@ function pullRequestNumber(record) {
//
// This doesn't depend on particular plotting library though.
function batchesToSeries(batches) {
const result = new Map();
for (const batch of batches) {
const results = new Map();
for (const [index, batch] of batches.entries()) {
for (const metric of batch.metrics) {
if (!result.has(metric.name)) {
result.set(metric.name, {
if (!results.has(metric.name)) {
results.set(metric.name, {
name: metric.name,
unit: undefined,
value: [],
Expand All @@ -163,7 +167,7 @@ function batchesToSeries(batches) {
});
}

const series = result.get(metric.name);
const series = results.get(metric.name);
assert(series.name == metric.name);

if (series.unit) {
Expand All @@ -172,24 +176,31 @@ function batchesToSeries(batches) {
series.unit = metric.unit;
}

series.value.push(metric.value);
// Even though our x-axis is time, we want to spread things out evenly by batch, rather than
// group according to time. Apex charts is much quicker when given an x value, even though it
// isn't strictly needed.
series.value.push([batches.length - index, metric.value]);
series.git_commit.push(batch.attributes.git_commit);
series.timestamp.push(batch.timestamp);
}
}
return result.values();

return results;
}

// Plot time series using <https://apexcharts.com>.
function plotSeries(seriesList, rootNode) {
for (const series of seriesList) {
function plotSeries(seriesList, rootNode, batchCount) {
for (const series of seriesList.values()) {
let options = {
title: {
text: series.name,
},
chart: {
type: "line",
height: "400px",
animations: {
enabled: false,
},
events: {
dataPointSelection: (event, chartContext, { dataPointIndex }) => {
window.open(
Expand All @@ -207,9 +218,18 @@ function plotSeries(seriesList, rootNode) {
data: series.value,
}],
xaxis: {
categories: series.timestamp.map((timestamp) =>
new Date(timestamp * 1000).toLocaleDateString()
),
categories: Array(series.value[series.value.length - 1][0]).fill("")
.concat(
series.timestamp.map((timestamp) =>
new Date(timestamp * 1000).toLocaleDateString()
).reverse(),
),
min: 0,
max: batchCount,
tickAmount: 15,
axisTicks: {
show: false,
},
tooltip: {
enabled: false,
},
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/devhub.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub fn main(shell: *Shell, gpa: std.mem.Allocator, cli_args: CliArgs) !void {
const query_p100_ms = try get_measurement(benchmark_result, "query latency p100", "ms");
const rss_bytes = try get_measurement(benchmark_result, "rss", "bytes");
const datafile_bytes = try get_measurement(benchmark_result, "datafile", "bytes");
const datafile_empty_bytes = try get_measurement(benchmark_result, "datafile empty", "bytes");

const batch = MetricBatch{
.timestamp = commit_timestamp,
Expand All @@ -54,6 +55,7 @@ pub fn main(shell: *Shell, gpa: std.mem.Allocator, cli_args: CliArgs) !void {
.{ .name = "query p100", .value = query_p100_ms, .unit = "ms" },
.{ .name = "RSS", .value = rss_bytes, .unit = "bytes" },
.{ .name = "datafile", .value = datafile_bytes, .unit = "bytes" },
.{ .name = "datafile empty", .value = datafile_empty_bytes, .unit = "bytes" },
},
};

Expand Down
7 changes: 7 additions & 0 deletions src/tigerbeetle/benchmark_driver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ pub fn main(allocator: std.mem.Allocator, args: *const cli.Command.Benchmark) !v
}
};

var maybe_stat_empty: ?std.fs.File.Stat = null;
if (args.addresses == null) {
const me = try std.fs.selfExePathAlloc(allocator);
defer allocator.free(me);

try format(allocator, .{ .tigerbeetle = me, .data_file = data_file });
data_file_created = true;
maybe_stat_empty = try std.fs.cwd().statFile(data_file);

tigerbeetle_process = try start(allocator, .{
.tigerbeetle = me,
Expand All @@ -66,6 +68,11 @@ pub fn main(allocator: std.mem.Allocator, args: *const cli.Command.Benchmark) !v

if (data_file_created) {
const stat = try std.fs.cwd().statFile(data_file);
if (maybe_stat_empty) |stat_empty| {
try std.io.getStdOut().writer().print("\ndatafile empty = {} bytes\n", .{
stat_empty.size,
});
}
try std.io.getStdOut().writer().print("datafile = {} bytes\n", .{stat.size});
}
}
Expand Down

0 comments on commit 7d8a4f2

Please sign in to comment.