Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions frameworks/Rust/sib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "sib-techempower"
version = "0.0.1"
authors = ["[email protected]"]
description = "A high-performance, secure, and cross-platform modules optimized for efficiency, scalability, and reliability."
documentation = "https://docs.rs/sib"
edition = "2024"
keywords = ["sib", "networking", "real-time", "streaming", "web"]
license = "Apache-2.0"
repository = "https://github.com/PooyaEimandar/sib"
categories = ["development-tools"]
readme = "README.md"

[dependencies]
sib = { git = "https://github.com/PooyaEimandar/sib", default-features = false, features = [
"net-h1-server",
] }
bytes = { version = "1.10.1", default-features = false }
mimalloc = { version = "0.1.47", features = ["secure"] }
num_cpus = { version = "1.16" }
serde = { version = "1.0.219", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.140" }

[profile.release]
opt-level = 3
codegen-units = 1
16 changes: 16 additions & 0 deletions frameworks/Rust/sib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# [SIB](https://github.com/pooyaeimandar/sib) web framework

## Description

A high-performance, secure, and cross-platform modules optimized for efficiency, scalability, and reliability.
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.

## Test URLs

### Test 1: JSON Encoding

http://localhost:8080/json

### Test 2: Plaintext

http://localhost:8080/plaintext
24 changes: 24 additions & 0 deletions frameworks/Rust/sib/benchmark_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"framework": "sib",
"tests": [
{
"default": {
"json_url": "/json",
"plaintext_url": "/plaintext",
"port": 8080,
"approach": "Realistic",
"classification": "Fullstack",
"framework": "may",
"language": "Rust",
"flavor": "None",
"platform": "None",
"webserver": "None",
"os": "Linux",
"database_os": "Linux",
"display_name": "sib",
"notes": "",
"versus": "None"
}
}
]
}
11 changes: 11 additions & 0 deletions frameworks/Rust/sib/sib.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM rust:latest

ADD ./ /sib
WORKDIR /sib

RUN cargo clean
RUN RUSTFLAGS="-C target-cpu=native" cargo build --release

EXPOSE 8080

CMD ["./target/release/sib-techempower"]
105 changes: 105 additions & 0 deletions frameworks/Rust/sib/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
use bytes::Bytes;
use sib::network::http::{
h1::{H1Service, H1ServiceFactory},
message::Status,
session::Session,
};
use std::{
fs,
io::{Read, Write},
};

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[derive(serde::Serialize)]
struct JsonMessage<'a> {
message: &'a str,
}

impl Default for JsonMessage<'_> {
fn default() -> Self {
JsonMessage {
message: "Hello, World!",
}
}
}

struct H1Server<T>(pub T);

struct HService;

impl H1Service for HService {
fn call<S: Read + Write>(&mut self, session: &mut Session<S>) -> std::io::Result<()> {
if session.req_path() == Some("/json") {
// Respond with JSON
let json = serde_json::to_vec(&JsonMessage::default())?;
session
.status_code(Status::Ok)
.header_str("Content-Type", "application/json")?
.header_str("Content-Length", &json.len().to_string())?
.body(&Bytes::from(json))
.eom();
return Ok(());
}
session
.status_code(Status::Ok)
.header_str("Content-Type", "text/plain")?
.header_str("Content-Length", "13")?
.body(&Bytes::from_static(b"Hello, World!"))
.eom();
Ok(())
}
}

impl H1ServiceFactory for H1Server<HService> {
type Service = HService;

fn service(&self, _id: usize) -> HService {
HService
}
}

fn main() {
// Print number of CPU cores
let cpus = num_cpus::get();
println!("CPU cores: {}", cpus);

// Print total RAM in MB
if let Ok(meminfo) = fs::read_to_string("/proc/meminfo") {
for line in meminfo.lines() {
if line.starts_with("MemTotal:") {
let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() >= 2 {
if let Ok(kb) = parts[1].parse::<u64>() {
let mb = kb / 1024;
println!("Total RAM: {} MB", mb);
}
}
break;
}
}
}

// Pick a port and start the server
let addr = "0.0.0.0:8080";
let mut threads = Vec::with_capacity(cpus);

for _ in 0..cpus {
let handle = std::thread::spawn(move || {
let id = std::thread::current().id();
println!("Listening {} on thread: {:?}", addr, id);
H1Server(HService)
.start(addr, cpus, 0, None)
.expect(&format!("h1 server failed to start for thread {:?}", id))
.join()
.expect(&format!("h1 server failed to joining thread {:?}", id));
});
threads.push(handle);
}

// Wait for all threads to complete (they won’t unless crashed)
for handle in threads {
handle.join().expect("Thread panicked");
}
}
Loading