Skip to content

rage-rb/sse-benchmark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rage SSE Benchmark

A performance benchmark for Rage, testing both standard API requests and Server-Sent Events (SSE) streaming under load.

Overview

This project benchmarks Rage's ability to handle:

  1. API Endpoint (GET /api) - Fetches a random record from a SQLite database (10,000 records) and returns it as JSON
  2. SSE Endpoint (GET /sse) - Creates a streaming connection that sends random values every second for 5-10 seconds

Project Setup

Generated with rage new -d sqlite3 with the following customizations:

  • YJIT enabled via config/initializers/yjit.rb
  • Production logs redirected to log/production.log (instead of STDOUT)

Requirements

  • Ruby (with YJIT support, Ruby 3.2+)
  • SQLite3
  • k6 for load testing

Installation

bundle install

Database Setup

bundle exec rage db:create
bundle exec rage db:migrate
bundle exec rage db:seed

This seeds the database with 10,000 World records.

Running the Server

Development:

rage s

Production:

rage s -e production -b 0.0.0.0

Running the Benchmark

The benchmark uses k6 and runs two scenarios simultaneously:

  • SSE Streams: Maintains a constant number of concurrent SSE connections
  • API Requests: Sends requests at a constant arrival rate

Default Configuration

Parameter Default Description
TARGET_STREAMS 5000 Number of concurrent SSE connections
TARGET_RPS 5000 API requests per second
Duration 5 minutes Total benchmark duration

Run with Defaults

k6 run benchmark/k6.js

Run with Custom Parameters

k6 run benchmark/k6.js \
  -e BASE_URL=http://localhost:3000 \
  -e TARGET_STREAMS=1000 \
  -e TARGET_RPS=2000

Metrics

The benchmark tracks:

SSE Metrics

  • sse_messages_total - Total SSE messages received
  • sse_streams_opened - Number of streams opened
  • sse_streams_closed - Number of streams closed successfully
  • sse_stream_duration - Duration of each stream
  • sse_errors - Failed SSE connections

API Metrics

  • api_req_success - Successful API requests
  • api_req_errors - Failed API requests
  • api_req_duration - Request latency

Thresholds

  • API error rate < 1%
  • SSE error rate < 1%
  • API p95 latency < 500ms
  • At least one SSE message received

Project Structure

.
├── app/
│   ├── controllers/
│   │   └── benchmarks_controller.rb  # API and SSE endpoints
│   └── models/
│       └── world.rb                  # ActiveRecord model
├── benchmark/
│   └── k6.js                         # k6 load test script
├── config/
│   ├── environments/
│   │   └── production.rb             # Production config
│   └── initializers/
│       └── yjit.rb                   # YJIT enablement
└── db/
    ├── migrate/
    ├── schema.rb
    └── seeds.rb                      # Seeds 10,000 World records

License

MIT

About

k6 load test for Rage comparing HTTP/JSON and Server-Sent Events performance

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors