Skip to content

Commit 787b344

Browse files
committed
Add benchmark tests for the Sib
1 parent 434b2bc commit 787b344

File tree

5 files changed

+166
-0
lines changed

5 files changed

+166
-0
lines changed

frameworks/Rust/sib/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "sib-techempower"
3+
version = "0.0.1"
4+
authors = ["[email protected]"]
5+
description = "A high-performance, secure, and cross-platform modules optimized for efficiency, scalability, and reliability."
6+
documentation = "https://docs.rs/sib"
7+
edition = "2024"
8+
keywords = ["sib", "networking", "real-time", "streaming", "web"]
9+
license = "Apache-2.0"
10+
repository = "https://github.com/PooyaEimandar/sib"
11+
categories = ["development-tools"]
12+
readme = "README.md"
13+
14+
[dependencies]
15+
sib = { git = "https://github.com/PooyaEimandar/sib", default-features = false, features = [
16+
"net-h1-server",
17+
] }
18+
bytes = { version = "1.10.1", default-features = false }
19+
mimalloc = { version = "0.1.47", features = ["secure"] }
20+
num_cpus = { version = "1.16" }
21+
22+
[profile.release]
23+
opt-level = 3
24+
codegen-units = 1

frameworks/Rust/sib/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# [SIB](https://github.com/pooyaeimandar/sib) web framework
2+
3+
## Description
4+
5+
A high-performance, secure, and cross-platform modules optimized for efficiency, scalability, and reliability.
6+
SIB supports HTTP/1.1 as well as HTTP/3, and uses coroutine-based concurrency via [may](https://github.com/Xudong-Huang/may) along with zero-copy request/response handling, aiming for the lowest possible overhead.
7+
8+
## Test URLs
9+
10+
### Test 1: JSON Encoding
11+
12+
http://localhost:8080/json
13+
14+
### Test 2: Plaintext
15+
16+
http://localhost:8080/plaintext
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"framework": "sib",
3+
"tests": [
4+
{
5+
"default": {
6+
"json_url": "/json",
7+
"plaintext_url": "/plaintext",
8+
"port": 8080,
9+
"approach": "Realistic",
10+
"classification": "Fullstack",
11+
"framework": "may",
12+
"language": "Rust",
13+
"flavor": "None",
14+
"platform": "None",
15+
"webserver": "None",
16+
"os": "Linux",
17+
"database_os": "Linux",
18+
"display_name": "sib",
19+
"notes": "",
20+
"versus": "None"
21+
}
22+
}
23+
]
24+
}

frameworks/Rust/sib/sib.dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM rust:latest
2+
3+
ADD ./ /sib
4+
WORKDIR /sib
5+
6+
RUN cargo clean
7+
RUN RUSTFLAGS="-C target-cpu=native" cargo build --release
8+
9+
EXPOSE 8080
10+
11+
CMD ["./target/release/sib-techempower"]

frameworks/Rust/sib/src/main.rs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
use bytes::Bytes;
2+
use sib::network::http::{
3+
h1::{H1Service, H1ServiceFactory},
4+
message::Status,
5+
session::Session,
6+
};
7+
use std::{
8+
fs,
9+
io::{Read, Write},
10+
};
11+
12+
#[global_allocator]
13+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
14+
15+
struct H1Server<T>(pub T);
16+
17+
struct HService;
18+
19+
impl H1Service for HService {
20+
fn call<S: Read + Write>(&mut self, session: &mut Session<S>) -> std::io::Result<()> {
21+
if session.req_path() == Some("/json") {
22+
// Respond with JSON
23+
session
24+
.status_code(Status::Ok)
25+
.header_str("Content-Type", "application/json")?
26+
.header_str("Content-Length", "27")?
27+
.body(&Bytes::from_static(b"{\"message\":\"Hello, World!\"}"))
28+
.eom();
29+
return Ok(());
30+
}
31+
session
32+
.status_code(Status::Ok)
33+
.header_str("Content-Type", "text/plain")?
34+
.header_str("Content-Length", "13")?
35+
.body(&Bytes::from_static(b"Hello, World!"))
36+
.eom();
37+
Ok(())
38+
}
39+
}
40+
41+
impl H1ServiceFactory for H1Server<HService> {
42+
type Service = HService;
43+
44+
fn service(&self, _id: usize) -> HService {
45+
HService
46+
}
47+
}
48+
49+
fn main() {
50+
// Print number of CPU cores
51+
let cpus = num_cpus::get();
52+
println!("CPU cores: {}", cpus);
53+
54+
// Print total RAM in MB
55+
if let Ok(meminfo) = fs::read_to_string("/proc/meminfo") {
56+
for line in meminfo.lines() {
57+
if line.starts_with("MemTotal:") {
58+
let parts: Vec<&str> = line.split_whitespace().collect();
59+
if parts.len() >= 2 {
60+
if let Ok(kb) = parts[1].parse::<u64>() {
61+
let mb = kb / 1024;
62+
println!("Total RAM: {} MB", mb);
63+
}
64+
}
65+
break;
66+
}
67+
}
68+
}
69+
70+
// Pick a port and start the server
71+
let addr = "0.0.0.0:8080";
72+
let mut threads = Vec::with_capacity(cpus);
73+
74+
for _ in 0..cpus {
75+
let handle = std::thread::spawn(move || {
76+
let id = std::thread::current().id();
77+
println!("Listening {} on thread: {:?}", addr, id);
78+
H1Server(HService)
79+
.start(addr, cpus, 0, None)
80+
.expect(&format!("h1 server failed to start for thread {:?}", id))
81+
.join()
82+
.expect(&format!("h1 server failed to joining thread {:?}", id));
83+
});
84+
threads.push(handle);
85+
}
86+
87+
// Wait for all threads to complete (they won’t unless crashed)
88+
for handle in threads {
89+
handle.join().expect("Thread panicked");
90+
}
91+
}

0 commit comments

Comments
 (0)