-
Notifications
You must be signed in to change notification settings - Fork 2k
Add benchmark tests for the Sib #9969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| [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" } | ||
|
|
||
| [profile.release] | ||
| opt-level = 3 | ||
| codegen-units = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| 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; | ||
|
|
||
| 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 | ||
| session | ||
| .status_code(Status::Ok) | ||
| .header_str("Content-Type", "application/json")? | ||
| .header_str("Content-Length", "27")? | ||
| .body(&Bytes::from_static(b"{\"message\":\"Hello, World!\"}")) | ||
| .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"); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be refactored. From the rules: