Skip to content

Commit

Permalink
test(e2e/heaptrack) set max client to 10K
Browse files Browse the repository at this point in the history
  • Loading branch information
Totodore committed Jan 27, 2025
1 parent 43cdcf9 commit 8f67130
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 69 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
heaptrack:
description: 'Run heaptrack memory benchmark'
description: "Run heaptrack memory benchmark"
required: true
default: false
type: boolean
Expand All @@ -18,6 +18,9 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: actions/cache@v4
with:
path: |
Expand All @@ -30,17 +33,22 @@ jobs:
- name: Install heaptrack
run: sudo apt-get install -y heaptrack
- name: Build server && client
run: cargo build -r -p heaptrack && cargo build -r -p heaptrack --bin heaptrack-client
run: cargo build -r -p heaptrack && npm i --prefix e2e/heaptrack
- name: Run memory benchmark
run: heaptrack target/release/heaptrack > server.txt & ./target/release/heaptrack-client > client.txt
- name: Server output
if: always()
run: cat server.txt
- name: Client output
if: always()
run: cat client.txt
run: |
ulimit -n 20000
RUST_LOG="socketioxide=trace,engineioxide=trace,info" heaptrack target/release/heaptrack > server.txt &
cd e2e/heaptrack
node --experimental-strip-types client.ts > ../../client.txt &
sleep 60
kill $!
- name: Publish logs
uses: actions/upload-artifact@v4
with:
name: logs-${{ github.head_ref }}.${{ github.sha }}
path: *.txt
- name: Publish memory benchmark
uses: actions/upload-artifact@v4
with:
name: heaptrack-${{ github.head_ref }}.${{ github.sha }}
path: heaptrack.heaptrack.*
path: heaptrack.heaptrack.*
4 changes: 2 additions & 2 deletions e2e/heaptrack/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.gz
client/node_modules
memory_usage.svg
node_modules
memory_usage.svg
10 changes: 3 additions & 7 deletions e2e/heaptrack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
socketioxide = { path = "../../crates/socketioxide" }
socketioxide = { path = "../../crates/socketioxide", features = ["tracing"] }
hyper = { workspace = true, features = ["server", "http1"] }
hyper-util = { workspace = true, features = ["tokio"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "signal"] }
rust_socketio = { version = "0.6.0", features = ["async"] }
serde_json = "1.0.68"
tracing-subscriber.workspace = true
serde_json.workspace = true
rand = "0.8.4"

[[bin]]
name = "heaptrack-client"
path = "src/client.rs"
56 changes: 56 additions & 0 deletions e2e/heaptrack/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { io } from "socket.io-client";

const URL = process.env.URL || "http://localhost:3000";
const MAX_CLIENTS = 5000;
const POLLING_PERCENTAGE = 0.05;
const CLIENT_CREATION_INTERVAL_IN_MS = 1;
const EMIT_INTERVAL_IN_MS = 1000;

let clientCount = 0;
let lastReport = new Date().getTime();
let packetsSinceLastReport = 0;

const createClient = () => {
// for demonstration purposes, some clients stay stuck in HTTP long-polling
const transports =
Math.random() < POLLING_PERCENTAGE ? ["polling"] : ["polling", "websocket"];

const socket = io(URL, {
transports,
});

setInterval(() => {
socket.emit("ping");
}, EMIT_INTERVAL_IN_MS);

socket.on("pong", () => {
packetsSinceLastReport++;
});

socket.on("disconnect", (reason) => {
console.log(`disconnect due to ${reason}`);
});

if (++clientCount < MAX_CLIENTS) {
setTimeout(createClient, CLIENT_CREATION_INTERVAL_IN_MS);
}
};

createClient();

const printReport = () => {
const now = new Date().getTime();
const durationSinceLastReport = (now - lastReport) / 1000;
const packetsPerSeconds = (
packetsSinceLastReport / durationSinceLastReport
).toFixed(2);

console.log(
`client count: ${clientCount} ; average packets received per second: ${packetsPerSeconds}`,
);

packetsSinceLastReport = 0;
lastReport = now;
};

setInterval(printReport, 5000);
141 changes: 141 additions & 0 deletions e2e/heaptrack/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions e2e/heaptrack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "heaptrack-bench",
"type": "module",
"dependencies": {
"socket.io-client": "^4.8.1"
},
"devDependencies": {
"@types/node": "^22.10.10"
}
}
50 changes: 0 additions & 50 deletions e2e/heaptrack/src/client.rs

This file was deleted.

1 change: 1 addition & 0 deletions e2e/heaptrack/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn on_connect(socket: SocketRef) {

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let (svc, io) = SocketIo::new_svc();

io.ns("/", on_connect);
Expand Down

0 comments on commit 8f67130

Please sign in to comment.