Previously, the latency benchmark generated events and subscribed to them in the same process. This created artificial "batching" behavior where events were generated in loops and immediately measured.
We've split the system into two independent scripts:
- Simulates real IoT sensors
- Writes one event at a time (no batching)
- Configurable frequency (Hz)
- Can run independently
- Subscribes to SSE events
- Measures true end-to-end latency
- Reports statistics periodically
- Can run on different machines
- Realistic latency: Measures real network + processing time
- Scalability: Run multiple producers/subscribers independently
- Distribution: Test across networks/machines
- Production-like: Mirrors real IoT deployments
- No artificial batching: Each event written individually
- Load testing: Multiple producers at different frequencies
- Network latency: Producer and subscriber on different machines
- Tail latency analysis: Real p95/p99 measurements
- Continuous monitoring: Long-running latency tracking
# Terminal 1: Start producer (5 events/sec)
npm run example:producer -- -f 5 -s 3 -d 30
# Terminal 2: Monitor latency
npm run example:subscriber -- -d 30 -r 5./demo-realtime.shStarting Realtime Event Producer
Kvasir URL: http://localhost:8080
Sensors: Sensor1, Sensor2, Sensor3
Frequency: 5 Hz (200ms interval)
Generated 10 events (5.02 events/sec)
Generated 20 events (5.01 events/sec)
Starting Realtime SSE Subscriber
Kvasir URL: http://localhost:8080
Listening to: ALL sensors
=== Latency Report ===
Events received: 253
Event rate: 5.02 events/sec
Latency (avg): 48.73ms
Latency (p50): 42.30ms
Latency (p95): 87.12ms
Latency (p99): 145.89ms
Tail ratio (p99/p50): 3.45x
========================
- 📚 Full Guide: Detailed usage and examples
- 🏗️ Architecture Comparison: Old vs new design
- 📖 Main README: Updated with new scripts
{
"example:producer": "ts-node examples/realtime-event-producer.ts",
"example:subscriber": "ts-node examples/realtime-sse-subscriber.ts"
}examples/realtime-event-producer.ts- Event generatorexamples/realtime-sse-subscriber.ts- SSE latency monitorexamples/REALTIME-GUIDE.md- Complete documentationARCHITECTURE.md- Architecture comparisondemo-realtime.sh- Quick demo script
| Old (Batched) | New (Decoupled) |
|---|---|
| Single process | Separate processes |
| Artificial batching | Individual events |
| Self-measurement | Real latency |
| Not scalable | Fully scalable |
| Production testing | Production testing |
- Try the demo: Run
./demo-realtime.sh - Read the guide: Open
examples/REALTIME-GUIDE.md - Test load: Run multiple producers simultaneously
- Monitor production: Use subscriber for continuous monitoring
"The old architecture measured how fast we could generate and consume our own events. The new architecture measures how fast Kvasir can process events from independent producers - which is what matters in production."
Built to simulate real-world IoT deployments