Przeglądaj źródła

Bump sib to v0.0.12 (#10111)

* bump sib to v0.0.12

* fix: readme
Outer Heaven Legacy 2 dni temu
rodzic
commit
2481f23006

+ 11 - 5
frameworks/Rust/sib/Cargo.toml

@@ -12,14 +12,20 @@ categories = ["development-tools"]
 readme = "README.md"
 
 [dependencies]
-sib = { version = "0.0.10", default-features = false, features = [
+sib = { version = "0.0.12", 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.17.0" }
-serde = { version = "1.0.219", default-features = false, features = ["derive"] }
-serde_json = { version = "1.0.141" }
+heapless = { version = "0.9.1", default-features = false }
+http = { version = "1.3.1", default-features = false }
+mimalloc = { version = "0.1.48", default-features = false, features = [
+    "secure",
+] }
+num_cpus = { version = "1.17.0", default-features = false }
+serde = { version = "1.0.221", default-features = false, features = ["derive"] }
+serde_json = { version = "1.0.144", default-features = false, features = [
+    "std",
+] }
 
 [profile.release]
 opt-level = 3

+ 1 - 2
frameworks/Rust/sib/README.md

@@ -2,8 +2,7 @@
 
 ## 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.
+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.
 
 ## Test URLs
 

+ 1 - 0
frameworks/Rust/sib/sib.dockerfile

@@ -3,6 +3,7 @@ FROM rust:latest
 ADD ./ /sib
 WORKDIR /sib
 
+RUN apt-get update && apt-get install -y cmake clang lld llvm libclang-dev
 RUN cargo clean
 RUN RUSTFLAGS="-C target-cpu=native" cargo build --release
 

+ 49 - 44
frameworks/Rust/sib/src/main.rs

@@ -1,9 +1,6 @@
-use bytes::Bytes;
 use sib::network::http::{
-    server::HFactory, session::{HService, Session}, util::Status
-};
-use std::{
-    fs
+    server::{H1Config, HFactory},
+    session::{HService, Session},
 };
 
 #[global_allocator]
@@ -26,28 +23,47 @@ struct Server;
 
 impl HService for Server {
     fn call<S: Session>(&mut self, session: &mut S) -> std::io::Result<()> {
-        if session.req_path() == Some("/json") {
+        use core::fmt::Write;
+        use sib::network::http::h1_session;
+        if session.req_path() == "/json" {
             // Respond with JSON
+            let mut res: heapless::String<192> = heapless::String::new();
             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(());
+            write!(
+                res,
+                "HTTP/1.1 200 OK\r\n\
+                Server: sib\r\n\
+                Date: {}\r\n\
+                Content-Type: application/json\r\n\
+                Content-Length: {}\r\n\
+                \r\n\
+                    {}",
+                h1_session::CURRENT_DATE.load(),
+                &json.len().to_string(),
+                String::from_utf8_lossy(&json)
+            )
+            .unwrap();
+            session.write_all_eom(res.as_bytes())
+        } else {
+            let mut res: heapless::String<160> = heapless::String::new();
+            write!(
+                res,
+                "HTTP/1.1 200 OK\r\n\
+             Server: sib\r\n\
+             Date: {}\r\n\
+             Content-Type: text/plain\r\n\
+             Content-Length: 13\r\n\
+             \r\n\
+             Hello, World!",
+                h1_session::CURRENT_DATE.load()
+            )
+            .unwrap();
+            session.write_all_eom(res.as_bytes())
         }
-        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 HFactory for Server{
+impl HFactory for Server {
     type Service = Server;
 
     fn service(&self, _id: usize) -> Server {
@@ -56,27 +72,10 @@ impl HFactory for Server{
 }
 
 fn main() {
-    // Print number of CPU cores
+    let stack_size = 4 * 1024; // 4 KB stack
     let cpus = num_cpus::get();
-    println!("CPU cores: {cpus}");
-
-    sib::set_num_workers(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;
-            }
-        }
-    }
+    sib::init_global_poller(cpus, stack_size);
 
     // Pick a port and start the server
     let addr = "0.0.0.0:8080";
@@ -87,15 +86,21 @@ fn main() {
             let id = std::thread::current().id();
             println!("Listening {addr} on thread: {id:?}");
             Server
-                .start_h1(addr, 0)
-                .unwrap_or_else(|_| panic!("h1 server failed to start for thread {id:?}"))
+                .start_h1(
+                    addr,
+                    H1Config {
+                        io_timeout: std::time::Duration::from_secs(15),
+                        stack_size,
+                    },
+                )
+                .unwrap_or_else(|_| panic!("H1 server failed to start for thread {id:?}"))
                 .join()
-                .unwrap_or_else(|_| panic!("h1 server failed to joining thread {id:?}"));
+                .unwrap_or_else(|_| panic!("H1 server failed to join thread {id:?}"));
         });
         threads.push(handle);
     }
 
-    // Wait for all threads to complete (they won’t unless crashed)
+    // Wait for all threads to complete
     for handle in threads {
         handle.join().expect("Thread panicked");
     }