Skip to content

Commit ee07f87

Browse files
committed
Add latency chart
1 parent 7b81e45 commit ee07f87

4 files changed

Lines changed: 69 additions & 3 deletions

File tree

tools/tpcc-dashboard/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useAppDispatch, useAppSelector } from './hooks';
99
import NewOrderThroughtputChart from './NewOrderThroughtputChart';
1010
import StatsCards from './StatsCards';
1111
import './App.css';
12+
import LatencyDistributionChart from './LatencyDistributionChart';
1213

1314
function App() {
1415
const conn = useContext(SpacetimeDBContext);
@@ -57,13 +58,14 @@ function App() {
5758
}, [conn, dispatch]);
5859

5960
if (!isReady) {
60-
return <div>Waiting for data...</div>;
61+
return <div className="heading-7">Waiting for data...</div>;
6162
}
6263

6364
return (
6465
<div className="app">
6566
<StatsCards />
6667
<NewOrderThroughtputChart />
68+
<LatencyDistributionChart />
6769
</div>
6870
);
6971
}

tools/tpcc-dashboard/src/ConnectedGuard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function ConnectedGuard({ children }: { children: React.ReactNode }) {
1010
}
1111

1212
DbConnection.builder()
13-
// .withUri('https://tpc-c-benchmark.spacetimedb.com')
13+
.withUri('https://tpc-c-benchmark.spacetimedb.com')
1414
.withUri('http://localhost:3000')
1515
.withDatabaseName('tpcc-metrics')
1616
.onConnect(conn => {
@@ -21,7 +21,7 @@ export function ConnectedGuard({ children }: { children: React.ReactNode }) {
2121
}, [conn]);
2222

2323
if (!conn || !conn.isActive) {
24-
return <div>Connecting to SpacetimeDB...</div>;
24+
return <div className="heading-7">Connecting to SpacetimeDB...</div>;
2525
}
2626

2727
return (
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {
2+
CartesianGrid,
3+
Line,
4+
LineChart,
5+
ResponsiveContainer,
6+
Tooltip,
7+
XAxis,
8+
YAxis,
9+
} from 'recharts';
10+
import { useAppSelector } from './hooks';
11+
import { useMemo } from 'react';
12+
13+
export default function LatencyDistributionChart() {
14+
const latencyData = useAppSelector(state => state.globalState.latencyData);
15+
16+
const chartData = useMemo(() => {
17+
const sortedLatencies = Object.keys(latencyData)
18+
.map(key => parseInt(key))
19+
.sort((a, b) => a - b);
20+
21+
return sortedLatencies.map(latency => ({
22+
latency,
23+
count: latencyData[latency],
24+
}));
25+
}, [latencyData]);
26+
27+
return (
28+
<div className="chart">
29+
<ResponsiveContainer width="100%" height={460}>
30+
<LineChart data={chartData}>
31+
<CartesianGrid strokeDasharray="3 3" />
32+
<XAxis
33+
dataKey="latency"
34+
label={{
35+
value: 'Response Time (ms)',
36+
position: 'insideBottomRight',
37+
offset: -10,
38+
}}
39+
/>
40+
<YAxis
41+
label={{
42+
value: 'Number of transactions',
43+
angle: -90,
44+
position: 'insideLeft',
45+
}}
46+
/>
47+
<Tooltip />
48+
<Line type="monotone" dataKey="count" stroke="#8884d8" />
49+
</LineChart>
50+
</ResponsiveContainer>
51+
</div>
52+
);
53+
}

tools/tpcc-dashboard/src/features/globalState.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export interface GlobalState {
1111
measuredTransactionCount: number;
1212
/// Time in ms when the transaction was measured
1313
throughputData: number[];
14+
/// Latency frequency distribution, where the key is the latency in ms and the value is the count of transactions with that latency.
15+
latencyData: Record<number, number>;
1416
}
1517

1618
const initialState: GlobalState = {
@@ -23,6 +25,7 @@ const initialState: GlobalState = {
2325
totalTransactionCount: 0,
2426
measuredTransactionCount: 0,
2527
throughputData: [],
28+
latencyData: {},
2629
};
2730

2831
export const globalStateSlice = createSlice({
@@ -50,6 +53,7 @@ export const globalStateSlice = createSlice({
5053
state.totalTransactionCount = 0;
5154
state.measuredTransactionCount = 0;
5255
state.throughputData = [];
56+
state.latencyData = {};
5357
},
5458
deleteState: state => {
5559
console.log('State deleted, resetting to initial state');
@@ -71,6 +75,13 @@ export const globalStateSlice = createSlice({
7175
}
7276

7377
state.throughputData.push(Number(payload.measurementTimeMs));
78+
79+
const latency = Number(payload.latencyMs);
80+
if (state.latencyData[latency]) {
81+
state.latencyData[latency] += 1;
82+
} else {
83+
state.latencyData[latency] = 1;
84+
}
7485
},
7586
},
7687
});

0 commit comments

Comments
 (0)