diff --git a/frameworks/Rust/khttp/Cargo.lock b/frameworks/Rust/khttp/Cargo.lock index 47c239fec8b..5278faf3a17 100644 --- a/frameworks/Rust/khttp/Cargo.lock +++ b/frameworks/Rust/khttp/Cargo.lock @@ -50,9 +50,9 @@ checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" [[package]] name = "cc" -version = "1.2.39" +version = "1.2.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1354349954c6fc9cb0deab020f27f783cf0b604e8bb754dc4658ecf0d29c35f" +checksum = "e1d05d92f4b1fd76aad469d46cdd858ca761576082cd37df81416691e50199fb" dependencies = [ "find-msvc-tools", "shlex", @@ -110,9 +110,9 @@ checksum = "d6add3b8cff394282be81f3fc1a0605db594ed69890078ca6e2cab1c408bcf04" [[package]] name = "find-msvc-tools" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ced73b1dacfc750a6db6c0a0c3a3853c8b41997e2e2c563dc90804ae6867959" +checksum = "0399f9d26e5191ce32c498bebd31e7a3ceabc2745f0ac54af3f335126c3f24b3" [[package]] name = "iana-time-zone" @@ -169,6 +169,7 @@ name = "khttp-techempower" version = "0.1.0" dependencies = [ "khttp", + "mimalloc", "pq-sys", "yarte", ] @@ -179,6 +180,16 @@ version = "0.2.176" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174" +[[package]] +name = "libmimalloc-sys" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "667f4fec20f29dfc6bc7357c582d91796c169ad7e2fce709468aefeb2c099870" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "log" version = "0.4.28" @@ -191,6 +202,15 @@ version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +[[package]] +name = "mimalloc" +version = "0.1.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1ee66a4b64c74f4ef288bcbb9192ad9c3feaad75193129ac8509af543894fd8" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -206,13 +226,20 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "pq-sys" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfd6cf44cca8f9624bc19df234fc4112873432f5fda1caff174527846d026fa9" +checksum = "412a4cb9e93795c0594dab7c1c4ec1c8b42b514e1baf6e9f63d14aa376e5bd04" dependencies = [ "libc", + "pkg-config", "vcpkg", ] @@ -237,9 +264,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" dependencies = [ "proc-macro2", ] @@ -302,9 +329,9 @@ checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" [[package]] name = "serde" -version = "1.0.227" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80ece43fc6fbed4eb5392ab50c07334d3e577cbf40997ee896fe7af40bba4245" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ "serde_core", "serde_derive", @@ -312,18 +339,18 @@ dependencies = [ [[package]] name = "serde_core" -version = "1.0.227" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a576275b607a2c86ea29e410193df32bc680303c82f31e275bbfcafe8b33be5" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.227" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51e694923b8824cf0e9b382adf0f60d4e05f348f357b38833a3fa5ed7c2ede04" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -515,9 +542,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-core" -version = "0.62.1" +version = "0.62.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6844ee5416b285084d3d3fffd743b925a6c9385455f64f6d4fa3031c4c2749a9" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" dependencies = [ "windows-implement", "windows-interface", @@ -528,9 +555,9 @@ dependencies = [ [[package]] name = "windows-implement" -version = "0.60.1" +version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edb307e42a74fb6de9bf3a02d9712678b22399c87e6fa869d6dfcd8c1b7754e0" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", @@ -539,9 +566,9 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.59.2" +version = "0.59.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0abd1ddbc6964ac14db11c7213d6532ef34bd9aa042c2e5935f59d7908b46a5" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", @@ -550,24 +577,24 @@ dependencies = [ [[package]] name = "windows-link" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] name = "windows-result" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7084dcc306f89883455a206237404d3eaf961e5bd7e0f312f7c91f57eb44167f" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" dependencies = [ "windows-link", ] [[package]] name = "windows-strings" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7218c655a553b0bed4426cf54b20d7ba363ef543b52d515b3e48d7fd55318dda" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" dependencies = [ "windows-link", ] diff --git a/frameworks/Rust/khttp/Cargo.toml b/frameworks/Rust/khttp/Cargo.toml index 21a5bb042d4..68af03b1cb8 100644 --- a/frameworks/Rust/khttp/Cargo.toml +++ b/frameworks/Rust/khttp/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" khttp = { version = "0.2", features = ["epoll"] } yarte = { version = "0.15", features = ["json"] } pq-sys = "0.7" +mimalloc = "0.1" [profile.release] opt-level = 3 diff --git a/frameworks/Rust/khttp/README.md b/frameworks/Rust/khttp/README.md index a0a5ad4d398..02671bc3d7f 100755 --- a/frameworks/Rust/khttp/README.md +++ b/frameworks/Rust/khttp/README.md @@ -5,7 +5,6 @@ Benchmark for [khttp](https://github.com/karlivory/khttp) - a low-level HTTP/1.1 ### Test Type Implementation Source Code * [JSON](./src/main.rs) -* [PLAINTEXT](./src/main.rs) * [FORTUNES](./src/main.rs) ## Test URLs @@ -14,10 +13,6 @@ Benchmark for [khttp](https://github.com/karlivory/khttp) - a low-level HTTP/1.1 http://localhost:8080/json -### PLAINTEXT - -http://localhost:8080/plaintext - ### FORTUNES http://localhost:8080/fortunes diff --git a/frameworks/Rust/khttp/benchmark_config.json b/frameworks/Rust/khttp/benchmark_config.json index 4e951342ef2..dc1c39a912c 100755 --- a/frameworks/Rust/khttp/benchmark_config.json +++ b/frameworks/Rust/khttp/benchmark_config.json @@ -4,7 +4,6 @@ { "default": { "json_url": "/json", - "plaintext_url": "/plaintext", "fortune_url": "/fortunes", "port": 8080, "approach": "Realistic", diff --git a/frameworks/Rust/khttp/src/main.rs b/frameworks/Rust/khttp/src/main.rs index 38d0755dadc..8a147f21705 100644 --- a/frameworks/Rust/khttp/src/main.rs +++ b/frameworks/Rust/khttp/src/main.rs @@ -1,5 +1,12 @@ +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + use khttp::{Headers, Method::*, RequestContext, ResponseHandle, Server, Status}; -use std::{ffi::CStr, io, ptr}; +use pq_sys::{ + ConnStatusType, ExecStatusType, PGconn, PQclear, PQconnectdb, PQerrorMessage, PQexecPrepared, + PQfinish, PQgetlength, PQgetvalue, PQntuples, PQprepare, PQresultStatus, PQstatus, +}; +use std::{ffi::CStr, io, ptr, sync::LazyLock}; use yarte::{Serialize, ywrite_html}; #[derive(Serialize)] @@ -7,25 +14,17 @@ struct HelloMessage { message: &'static str, } +static JSON_HEADERS: LazyLock> = LazyLock::new(|| { + let mut headers = Headers::new(); + headers.add(Headers::CONTENT_TYPE, b"application/json"); + headers.add("server", b"khttp"); + headers +}); + fn main() { let mut app = Server::builder("0.0.0.0:8080").unwrap(); - app.route(Get, "/plaintext", |_ctx, res| { - // headers - let mut headers = Headers::new(); - headers.add(Headers::CONTENT_TYPE, b"text/plain"); - headers.add("server", b"khttp"); - - // response - res.ok(&headers, "Hello, World!") - }); - app.route(Get, "/json", |_ctx, res| { - // headers - let mut headers = Headers::new(); - headers.add(Headers::CONTENT_TYPE, b"application/json"); - headers.add("server", b"khttp"); - // body let msg = HelloMessage { message: "Hello, World!", @@ -34,7 +33,7 @@ fn main() { msg.to_bytes_mut(&mut buf); // response - res.ok(&headers, buf) + res.ok(&JSON_HEADERS, buf) }); app.route(Get, "/fortunes", handle_fortunes); @@ -63,11 +62,6 @@ fn handle_fortunes(_ctx: RequestContext, res: &mut ResponseHandle) -> io::Result // /fortunes query implementation using postgres (libpq) // --------------------------------------------------------------------- -use pq_sys::{ - ConnStatusType, ExecStatusType, PGconn, PQclear, PQconnectdb, PQerrorMessage, PQexecPrepared, - PQfinish, PQgetlength, PQgetvalue, PQntuples, PQprepare, PQresultStatus, PQstatus, -}; - const DB_CONNINFO: &CStr = c"postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world"; const PG_FORTUNES_SQL: &CStr = c"SELECT id, message FROM fortune"; const PG_FORTUNES_PREPARED_STMT: &CStr = c"s_fortunes"; @@ -78,7 +72,7 @@ struct Fortune<'a> { message: &'a str, } -fn fetch_fortunes_html() -> Result, String> { +fn fetch_fortunes_html() -> Result, &'static str> { PG_CONN.with(|pg| unsafe { let res = PQexecPrepared( pg.conn, @@ -90,11 +84,11 @@ fn fetch_fortunes_html() -> Result, String> { 1, // resultFormat = 1 (binary) ); if res.is_null() { - return Err("PQexecPrepared returned null".to_owned()); + return Err("PQexecPrepared returned null"); } if PQresultStatus(res) != ExecStatusType::PGRES_TUPLES_OK { PQclear(res); - return Err("PQexecPrepared non-ok result status".to_owned()); + return Err("PQexecPrepared non-ok result status"); } let rows = PQntuples(res); @@ -164,7 +158,6 @@ impl PgConnection { PQfinish(conn); panic!("PQprepare returned null"); } - let st = PQresultStatus(res); PQclear(res); if st != ExecStatusType::PGRES_COMMAND_OK {