Skip to content

Commit 8d36cfe

Browse files
Merge pull request #80 from thingsboard/add-claude-md
Add CLAUDE.md with build commands and architecture overview
2 parents 2cf870b + 818f153 commit 8d36cfe

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

CLAUDE.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Overview
6+
7+
ThingsBoard Performance Tests — a Spring Boot application that stress-tests ThingsBoard IoT platform by simulating massive concurrent device message publishing over MQTT, HTTP, and LwM2M protocols.
8+
9+
## Build & Run
10+
11+
**Build (Maven, Java 17 required):**
12+
```bash
13+
mvn clean package -DskipTests
14+
```
15+
16+
**Run locally (after build):**
17+
```bash
18+
java -jar target/tb-ce-performance-tests.jar
19+
```
20+
21+
**Build Docker image:**
22+
```bash
23+
cd docker
24+
docker buildx build --no-cache --pull -t thingsboard/tb-ce-performance-test:latest .
25+
```
26+
27+
**Run via Docker (most common usage):**
28+
```bash
29+
docker run -it --rm --network host --pull always --log-driver none \
30+
--env REST_URL=http://127.0.0.1:8080 \
31+
--env MQTT_HOST=127.0.0.1 \
32+
--env DEVICE_END_IDX=1000 \
33+
--env MESSAGES_PER_SECOND=50 \
34+
--env DURATION_IN_SECONDS=300 \
35+
--env TEST_PAYLOAD_TYPE=SMART_METER \
36+
thingsboard/tb-ce-performance-test:latest
37+
```
38+
39+
Or with an env file:
40+
```bash
41+
docker run -it --env-file .env --name tb-perf-test thingsboard/tb-ce-performance-test:latest
42+
```
43+
44+
## Configuration
45+
46+
All configuration is driven by environment variables mapped in `src/main/resources/tb-ce-performance-tests.yml`. Key variables:
47+
48+
| Variable | Default | Description |
49+
|---|---|---|
50+
| `REST_URL` | `http://localhost:8080` | ThingsBoard REST API URL |
51+
| `REST_USERNAME` | `tenant@thingsboard.org` | TB login |
52+
| `REST_PASSWORD` | `tenant` | TB password |
53+
| `MQTT_HOST` | `localhost` | MQTT broker host |
54+
| `MQTT_PORT` | `1883` | MQTT broker port (8883 for TLS) |
55+
| `MQTT_SSL_ENABLED` | `false` | Enable MQTT TLS |
56+
| `DEVICE_API` | `MQTT` | Device protocol: `MQTT`, `HTTP`, or `LWM2M` |
57+
| `TEST_API` | `device` | Test mode: `device`, `gateway`, or `lwm2m` |
58+
| `DEVICE_START_IDX` | `0` | First device index |
59+
| `DEVICE_END_IDX` | `1000` | Last device index |
60+
| `DEVICE_CREATE_ON_START` | `true` | Create devices before test |
61+
| `DEVICE_DELETE_ON_COMPLETE` | `false` | Delete devices after test |
62+
| `MESSAGES_PER_SECOND` | `1000` | Target message throughput |
63+
| `DURATION_IN_SECONDS` | `300` | Test duration |
64+
| `TEST_PAYLOAD_TYPE` | `SMART_METER` | Payload type: `DEFAULT`, `SMART_TRACKER`, `SMART_METER`, `INDUSTRIAL_PLC` |
65+
| `TEST_PAYLOAD_DATAPOINTS` | `60` | Datapoints per message (INDUSTRIAL_PLC only) |
66+
| `WARMUP_ENABLED` | `true` | Run warmup phase before test |
67+
| `UPDATE_ROOT_RULE_CHAIN` | `false` | Replace TB root rule chain with a counter rule chain during test |
68+
| `ALARMS_PER_SECOND` | `1` | Alarm messages per second |
69+
70+
## Architecture
71+
72+
### Entry Points
73+
- `PerformanceTestApplication` — Spring Boot main class, loads `tb-ce-performance-tests.yml`
74+
- `PerformanceTestRunner``ApplicationRunner` that calls `TestExecutor.runTest()` then exits the JVM
75+
76+
### Test Executor Hierarchy
77+
`TestExecutor` (interface) → `BaseTestExecutor` (abstract) handles lifecycle:
78+
1. Create device profiles
79+
2. Create dashboards/customers (if configured)
80+
3. `initEntities()` — create devices/gateways
81+
4. Optionally update root rule chain
82+
5. `runApiTests()` — execute the load test at `MESSAGES_PER_SECOND` rate for `DURATION_IN_SECONDS`
83+
6. Cleanup entities and revert rule chain
84+
85+
Concrete executors:
86+
- `DeviceBaseTestExecutor``MqttDeviceAPITest`, `HttpDeviceAPITest`, `Lwm2mDeviceAPITest`
87+
- `GatewayBaseTestExecutor``MqttGatewayAPITest`, `GatewayAPITest`
88+
- `LwM2MClientBaseTestExecutor``Lwm2mDeviceAPITest`
89+
90+
### Message Generation
91+
`MessageGenerator` implementations in `service/msg/`:
92+
- `SmartMeterTelemetryGenerator` / `SmartMeterAttributesGenerator`
93+
- `SmartTrackerTelemetryGenerator` / `SmartTrackerAttributesGenerator`
94+
- `IndustrialPLCTelemetryGenerator` / `IndustrialPLCAttributesGenerator`
95+
- `RandomTelemetryGenerator` / `RandomAttributesGenerator`
96+
97+
### Device Naming Convention
98+
Devices are named `DW00000000` (prefix `DW` + zero-padded index), gateways use `GW` prefix.
99+
100+
### Key Services
101+
- `DefaultRestClientService` — manages thread pools (HTTP executor + log scheduler), wraps TB REST client
102+
- `DefaultDashboardManager` — creates dashboards from JSON files in `src/main/resources/`
103+
- `DeviceProfileManagerImpl` — creates TB device profiles from JSON files in `src/main/resources/device/profile/`
104+
- `RuleChainManager` — can swap/revert the TB root rule chain for clean measurement
105+
106+
### LwM2M Support
107+
The `lwm2m/` package contains a full Leshan-based LwM2M client implementation supporting NoSec, PSK, RPK, and X.509 security modes. LwM2M object models are in `src/main/resources/models/`.
108+
109+
### Kubernetes / Multi-instance
110+
Supports sharding across instances via `INSTANCE_IDX` / `USE_INSTANCE_IDX` / `DEVICE_COUNT` to partition the device range among multiple pods.

0 commit comments

Comments
 (0)