Skip to content

Commit 0797648

Browse files
committed
Add metrics module
1 parent 91c2273 commit 0797648

43 files changed

Lines changed: 5732 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ members = [
5252
"modules/sdk-test-view-pk",
5353
"modules/sdk-test-event-table",
5454
"modules/tpcc",
55+
"modules/tpcc-metrics",
5556
"sdks/rust/tests/test-client",
5657
"sdks/rust/tests/test-counter",
5758
"sdks/rust/tests/connect_disconnect_client",

modules/tpcc-metrics/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "tpcc-metrics"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
7+
[lib]
8+
crate-type = ["cdylib"]
9+
10+
[dependencies]
11+
anyhow.workspace = true
12+
log.workspace = true
13+
spacetimedb = { workspace = true, features = ["unstable"] }
14+
spacetimedb-sats = { workspace = true, features = ["serde"] }
15+
http.workspace = true
16+
serde_json.workspace = true
17+
18+
[lints]
19+
workspace = true

modules/tpcc-metrics/src/lib.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use spacetimedb::{reducer, table, ReducerContext, Table};
2+
3+
#[table(accessor = state, public)]
4+
pub struct State {
5+
#[primary_key]
6+
pub id: i64,
7+
8+
pub run_start_ms: u64,
9+
pub run_end_ms: u64,
10+
pub measure_start_ms: u64,
11+
pub measure_end_ms: u64,
12+
13+
pub order_count: u64,
14+
pub measurement_time_ms: u64,
15+
}
16+
17+
#[reducer]
18+
pub fn reset(ctx: &ReducerContext, warmup_duration_ms: u64, measure_start_ms: u64, measure_end_ms: u64) {
19+
for row in ctx.db.state().iter() {
20+
ctx.db.state().delete(row);
21+
}
22+
23+
ctx.db.state().insert(State {
24+
id: 0,
25+
order_count: 0,
26+
measurement_time_ms: 0,
27+
run_start_ms: measure_start_ms - warmup_duration_ms,
28+
run_end_ms: measure_end_ms + warmup_duration_ms,
29+
measure_start_ms,
30+
measure_end_ms,
31+
});
32+
}
33+
34+
#[reducer]
35+
pub fn clear_state(ctx: &ReducerContext) {
36+
for row in ctx.db.state().iter() {
37+
ctx.db.state().delete(row);
38+
}
39+
}
40+
41+
#[reducer]
42+
pub fn register_completed_order(ctx: &ReducerContext) {
43+
// We intentionally do not check if the current time is within the measurement window,
44+
// this is the driver's reponsibility
45+
46+
let current_time_ms = ctx.timestamp.to_duration_since_unix_epoch().unwrap().as_millis() as u64;
47+
48+
let mut state = ctx.db.state().id().find(0).unwrap();
49+
50+
state.order_count += 1;
51+
state.measurement_time_ms = current_time_ms;
52+
53+
ctx.db.state().id().update(state);
54+
}

tools/tpcc-dashboard/.editorconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[src/**.ts]
8+
indent_style = space
9+
indent_size = 2
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
max_line_length = 120
13+
14+
[src/**.tsx]
15+
indent_style = space
16+
indent_size = 2
17+
charset = utf-8
18+
trim_trailing_whitespace = true
19+
max_line_length = 120
20+
21+
[*.json]
22+
indent_style = space
23+
indent_size = 2

tools/tpcc-dashboard/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

tools/tpcc-dashboard/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# React + TypeScript + Vite
2+
3+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4+
5+
Currently, two official plugins are available:
6+
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
8+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
9+
10+
## React Compiler
11+
12+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13+
14+
## Expanding the ESLint configuration
15+
16+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
17+
18+
```js
19+
export default defineConfig([
20+
globalIgnores(['dist']),
21+
{
22+
files: ['**/*.{ts,tsx}'],
23+
extends: [
24+
// Other configs...
25+
26+
// Remove tseslint.configs.recommended and replace with this
27+
tseslint.configs.recommendedTypeChecked,
28+
// Alternatively, use this for stricter rules
29+
tseslint.configs.strictTypeChecked,
30+
// Optionally, add this for stylistic rules
31+
tseslint.configs.stylisticTypeChecked,
32+
33+
// Other configs...
34+
],
35+
languageOptions: {
36+
parserOptions: {
37+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
38+
tsconfigRootDir: import.meta.dirname,
39+
},
40+
// other options...
41+
},
42+
},
43+
])
44+
```
45+
46+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47+
48+
```js
49+
// eslint.config.js
50+
import reactX from 'eslint-plugin-react-x'
51+
import reactDom from 'eslint-plugin-react-dom'
52+
53+
export default defineConfig([
54+
globalIgnores(['dist']),
55+
{
56+
files: ['**/*.{ts,tsx}'],
57+
extends: [
58+
// Other configs...
59+
// Enable lint rules for React
60+
reactX.configs['recommended-typescript'],
61+
// Enable lint rules for React DOM
62+
reactDom.configs.recommended,
63+
],
64+
languageOptions: {
65+
parserOptions: {
66+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
67+
tsconfigRootDir: import.meta.dirname,
68+
},
69+
// other options...
70+
},
71+
},
72+
])
73+
```

tools/tpcc-dashboard/config.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[connection]
2+
uri = "http://127.0.0.1:3000"
3+
database = "tpcc"
4+
confirmed_reads = true
5+
timeout_secs = 30
6+
7+
[load]
8+
warehouses = 1
9+
batch_size = 500
10+
reset = true
11+
12+
[driver]
13+
driver_id = "driver-a"
14+
terminal_start = 1
15+
terminals = 10
16+
warehouses = 1
17+
warmup_secs = 5
18+
measure_secs = 30
19+
delivery_wait_secs = 60
20+
keying_time_scale = 1.0
21+
think_time_scale = 1.0
22+
23+
[coordinator]
24+
run_id = "tpcc-demo"
25+
listen = "127.0.0.1:7878"
26+
expected_drivers = 2
27+
warmup_secs = 5
28+
measure_secs = 30
29+
output_dir = "tpcc-results/coordinator"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
import { defineConfig, globalIgnores } from 'eslint/config'
7+
8+
export default defineConfig([
9+
globalIgnores(['dist']),
10+
{
11+
files: ['**/*.{ts,tsx}'],
12+
extends: [
13+
js.configs.recommended,
14+
tseslint.configs.recommended,
15+
reactHooks.configs.flat.recommended,
16+
reactRefresh.configs.vite,
17+
],
18+
languageOptions: {
19+
ecmaVersion: 2020,
20+
globals: globals.browser,
21+
},
22+
},
23+
])

tools/tpcc-dashboard/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>tpcc-dashboard</title>
7+
</head>
8+
<body>
9+
<div id="root"></div>
10+
<script type="module" src="/src/main.tsx"></script>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)