Published
Edited
Apr 4, 2022
7 stars
Insert cell
Insert cell
// fake time of the postgres fix 🪄
tfix = new Date(Date.UTC(2021, 4, 19, 21))
Insert cell
simulated = {
const random = d3.randomPareto(1);

// start date
let t0 = new Date(Date.UTC(2021, 4, 17));

// the interval between queries is random and depends on the time of the day
const density = (t) => 0.1 + Math.cos(1 + (t.getHours() / 24) * Math.PI) ** 2;

// query duration is random, but the denser the number of queries, the slower it gets
// after the fix, it becomes immediately much better: the base time is reduced from 3s to 10ms
// and the lag is 100x better
const duration = (t) =>
(t < tfix ? 0.1 : 0.1) +
Math.min(15 * density(t) * (t < tfix ? 1 : 0.01) * (random() - 1), 30);

return Array.from({ length: 14000 }, () => ({
time: (t0 = new Date(+t0 + 12000 * d3.randomExponential(density(t0))())),
duration: duration(t0)
}));
}
Insert cell
Plot.dot(simulated, { x: "time", y: "duration", r: 1, fill: "black" }).plot({
marks: [Plot.tickX([tfix], { stroke: "brown" }), Plot.tickY([0])]
})
Insert cell
Plot.plot({
color: { scheme: "ylgnbu", type: "sqrt" },
marks: [
Plot.rect(
simulated,
Plot.bin(
{ fill: "count" },
{ x: "time", y: "duration", r: 1, thresholds: 50 }
)
),
Plot.lineY(
simulated,
Plot.binX(
{ y: "median" },
{ x: "time", y: "duration", r: 1, thresholds: 50, curve: "step" }
)
),
Plot.tickX([tfix], { stroke: "brown" }),
Plot.tickY([0])
]
})
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more