Skip to content

Commit 2481f23

Browse files
Bump sib to v0.0.12 (#10111)
* bump sib to v0.0.12 * fix: readme
1 parent f9ab8cd commit 2481f23

File tree

4 files changed

+62
-51
lines changed

4 files changed

+62
-51
lines changed

frameworks/Rust/sib/Cargo.toml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ categories = ["development-tools"]
1212
readme = "README.md"
1313

1414
[dependencies]
15-
sib = { version = "0.0.10", default-features = false, features = [
15+
sib = { version = "0.0.12", default-features = false, features = [
1616
"net-h1-server",
1717
] }
1818
bytes = { version = "1.10.1", default-features = false }
19-
mimalloc = { version = "0.1.47", features = ["secure"] }
20-
num_cpus = { version = "1.17.0" }
21-
serde = { version = "1.0.219", default-features = false, features = ["derive"] }
22-
serde_json = { version = "1.0.141" }
19+
heapless = { version = "0.9.1", default-features = false }
20+
http = { version = "1.3.1", default-features = false }
21+
mimalloc = { version = "0.1.48", default-features = false, features = [
22+
"secure",
23+
] }
24+
num_cpus = { version = "1.17.0", default-features = false }
25+
serde = { version = "1.0.221", default-features = false, features = ["derive"] }
26+
serde_json = { version = "1.0.144", default-features = false, features = [
27+
"std",
28+
] }
2329

2430
[profile.release]
2531
opt-level = 3

frameworks/Rust/sib/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
## Description
44

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.
5+
Sib supports HTTP/1.1, HTTP/2, and HTTP/3. It uses coroutines and io_uring, along with zero-copy request/response handling, to achieve the lowest possible overhead.
76

87
## Test URLs
98

frameworks/Rust/sib/sib.dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM rust:latest
33
ADD ./ /sib
44
WORKDIR /sib
55

6+
RUN apt-get update && apt-get install -y cmake clang lld llvm libclang-dev
67
RUN cargo clean
78
RUN RUSTFLAGS="-C target-cpu=native" cargo build --release
89

frameworks/Rust/sib/src/main.rs

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
use bytes::Bytes;
21
use sib::network::http::{
3-
server::HFactory, session::{HService, Session}, util::Status
4-
};
5-
use std::{
6-
fs
2+
server::{H1Config, HFactory},
3+
session::{HService, Session},
74
};
85

96
#[global_allocator]
@@ -26,28 +23,47 @@ struct Server;
2623

2724
impl HService for Server {
2825
fn call<S: Session>(&mut self, session: &mut S) -> std::io::Result<()> {
29-
if session.req_path() == Some("/json") {
26+
use core::fmt::Write;
27+
use sib::network::http::h1_session;
28+
if session.req_path() == "/json" {
3029
// Respond with JSON
30+
let mut res: heapless::String<192> = heapless::String::new();
3131
let json = serde_json::to_vec(&JsonMessage::default())?;
32-
session
33-
.status_code(Status::Ok)
34-
.header_str("Content-Type", "application/json")?
35-
.header_str("Content-Length", &json.len().to_string())?
36-
.body(&Bytes::from(json))
37-
.eom();
38-
return Ok(());
32+
write!(
33+
res,
34+
"HTTP/1.1 200 OK\r\n\
35+
Server: sib\r\n\
36+
Date: {}\r\n\
37+
Content-Type: application/json\r\n\
38+
Content-Length: {}\r\n\
39+
\r\n\
40+
{}",
41+
h1_session::CURRENT_DATE.load(),
42+
&json.len().to_string(),
43+
String::from_utf8_lossy(&json)
44+
)
45+
.unwrap();
46+
session.write_all_eom(res.as_bytes())
47+
} else {
48+
let mut res: heapless::String<160> = heapless::String::new();
49+
write!(
50+
res,
51+
"HTTP/1.1 200 OK\r\n\
52+
Server: sib\r\n\
53+
Date: {}\r\n\
54+
Content-Type: text/plain\r\n\
55+
Content-Length: 13\r\n\
56+
\r\n\
57+
Hello, World!",
58+
h1_session::CURRENT_DATE.load()
59+
)
60+
.unwrap();
61+
session.write_all_eom(res.as_bytes())
3962
}
40-
session
41-
.status_code(Status::Ok)
42-
.header_str("Content-Type", "text/plain")?
43-
.header_str("Content-Length", "13")?
44-
.body(&Bytes::from_static(b"Hello, World!"))
45-
.eom();
46-
Ok(())
4763
}
4864
}
4965

50-
impl HFactory for Server{
66+
impl HFactory for Server {
5167
type Service = Server;
5268

5369
fn service(&self, _id: usize) -> Server {
@@ -56,27 +72,10 @@ impl HFactory for Server{
5672
}
5773

5874
fn main() {
59-
// Print number of CPU cores
75+
let stack_size = 4 * 1024; // 4 KB stack
6076
let cpus = num_cpus::get();
61-
println!("CPU cores: {cpus}");
62-
63-
sib::set_num_workers(cpus);
6477

65-
// Print total RAM in MB
66-
if let Ok(meminfo) = fs::read_to_string("/proc/meminfo") {
67-
for line in meminfo.lines() {
68-
if line.starts_with("MemTotal:") {
69-
let parts: Vec<&str> = line.split_whitespace().collect();
70-
if parts.len() >= 2 {
71-
if let Ok(kb) = parts[1].parse::<u64>() {
72-
let mb = kb / 1024;
73-
println!("Total RAM: {mb} MB");
74-
}
75-
}
76-
break;
77-
}
78-
}
79-
}
78+
sib::init_global_poller(cpus, stack_size);
8079

8180
// Pick a port and start the server
8281
let addr = "0.0.0.0:8080";
@@ -87,15 +86,21 @@ fn main() {
8786
let id = std::thread::current().id();
8887
println!("Listening {addr} on thread: {id:?}");
8988
Server
90-
.start_h1(addr, 0)
91-
.unwrap_or_else(|_| panic!("h1 server failed to start for thread {id:?}"))
89+
.start_h1(
90+
addr,
91+
H1Config {
92+
io_timeout: std::time::Duration::from_secs(15),
93+
stack_size,
94+
},
95+
)
96+
.unwrap_or_else(|_| panic!("H1 server failed to start for thread {id:?}"))
9297
.join()
93-
.unwrap_or_else(|_| panic!("h1 server failed to joining thread {id:?}"));
98+
.unwrap_or_else(|_| panic!("H1 server failed to join thread {id:?}"));
9499
});
95100
threads.push(handle);
96101
}
97102

98-
// Wait for all threads to complete (they won’t unless crashed)
103+
// Wait for all threads to complete
99104
for handle in threads {
100105
handle.join().expect("Thread panicked");
101106
}

0 commit comments

Comments
 (0)