Browse Source

Merge pull request #9627 from fafhrd91/ntex-fixes-11

[ntex] update version
Mike Smith 5 months ago
parent
commit
3c194d8f1b

+ 24 - 3
frameworks/Rust/ntex/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "ntex-bench"
-version = "2.0.0"
+version = "2.1.0"
 edition = "2018"
 
 [[bin]]
@@ -11,6 +11,10 @@ path = "src/main.rs"
 name = "ntex-compio"
 path = "src/main.rs"
 
+[[bin]]
+name = "ntex-neon"
+path = "src/main.rs"
+
 [[bin]]
 name = "ntex-db"
 path = "src/main_db.rs"
@@ -19,6 +23,10 @@ path = "src/main_db.rs"
 name = "ntex-db-compio"
 path = "src/main_db.rs"
 
+[[bin]]
+name = "ntex-db-neon"
+path = "src/main_db.rs"
+
 [[bin]]
 name = "ntex-plt"
 path = "src/main_plt.rs"
@@ -27,6 +35,10 @@ path = "src/main_plt.rs"
 name = "ntex-plt-compio"
 path = "src/main_plt.rs"
 
+[[bin]]
+name = "ntex-plt-neon"
+path = "src/main_plt.rs"
+
 [features]
 default = []
 
@@ -36,8 +48,11 @@ tokio = ["ntex/tokio"]
 # compio runtime
 compio = ["ntex/compio"]
 
+# neon runtime
+neon = ["ntex/neon"]
+
 [dependencies]
-ntex = "2.8"
+ntex = "2.12"
 ntex-compio = "0.2"
 ntex-bytes = { version = "0.1.21", features=["simd"] }
 mimalloc = { version = "0.1.25", default-features = false }
@@ -47,7 +62,6 @@ buf-min = { version = "0.7", features = ["ntex-bytes"] }
 env_logger = "0.11"
 nanorand = { version = "0.7", default-features = false, features = ["std", "wyrand", "tls"] }
 atoi = "2.0"
-core_affinity = "0.8"
 futures = "0.3"
 sonic-rs = "0.3.16"
 serde = { version = "1", features = ["derive"] }
@@ -59,6 +73,13 @@ tokio-postgres = { git="https://github.com/fafhrd91/postgres.git", branch="ntex-
 [target.'cfg(target_os = "linux")'.dependencies]
 compio-driver = { version = "*", features = ["io-uring"]}
 
+[patch.crates-io]
+ntex = { git = "https://github.com/ntex-rs/ntex.git" }
+ntex-io = { git = "https://github.com/ntex-rs/ntex.git" }
+ntex-net = { git = "https://github.com/ntex-rs/ntex.git" }
+ntex-rt = { git = "https://github.com/ntex-rs/ntex.git" }
+ntex-neon = { git = "https://github.com/ntex-rs/ntex.git" }
+
 [profile.release]
 opt-level = 3
 codegen-units = 1

+ 56 - 0
frameworks/Rust/ntex/benchmark_config.json

@@ -37,6 +37,24 @@
         "notes": "",
         "versus": ""
     },
+    "neon": {
+        "json_url": "/json",
+        "plaintext_url": "/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "Postgres",
+        "framework": "ntex",
+        "language": "Rust",
+        "orm": "Raw",
+        "platform": "None",
+        "webserver": "ntex",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ntex [neon]",
+        "notes": "",
+        "versus": ""
+    },
     "db": {
         "fortune_url": "/fortunes",
         "db_url": "/db",
@@ -77,6 +95,26 @@
         "notes": "",
         "versus": ""
     },
+    "db-neon": {
+        "fortune_url": "/fortunes",
+        "db_url": "/db",
+        "query_url": "/query?q=",
+        "update_url": "/update?q=",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "Postgres",
+        "framework": "ntex",
+        "language": "Rust",
+        "orm": "Raw",
+        "platform": "None",
+        "webserver": "ntex",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ntex [neon,db]",
+        "notes": "",
+        "versus": ""
+    },
     "plt": {
         "json_url": "/json",
         "plaintext_url": "/plaintext",
@@ -112,6 +150,24 @@
         "display_name": "ntex [compio,platform]",
         "notes": "",
         "versus": ""
+    },
+    "plt-neon": {
+        "json_url": "/json",
+        "plaintext_url": "/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Platform",
+        "database": "Postgres",
+        "framework": "ntex",
+        "language": "Rust",
+        "orm": "Raw",
+        "platform": "None",
+        "webserver": "ntex",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ntex [neon,platform]",
+        "notes": "",
+        "versus": ""
     }
   }]
 }

+ 41 - 0
frameworks/Rust/ntex/config.toml

@@ -27,6 +27,19 @@ platform = "None"
 webserver = "ntex"
 versus = ""
 
+[neon]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+approach = "Realistic"
+classification = "Micro"
+database = "Postgres"
+database_os = "Linux"
+os = "Linux"
+orm = "Raw"
+platform = "None"
+webserver = "ntex"
+versus = ""
+
 [db]
 urls.db = "/db"
 urls.query = "/query?q="
@@ -57,6 +70,21 @@ platform = "None"
 webserver = "ntex"
 versus = ""
 
+[db-neon]
+urls.db = "/db"
+urls.query = "/query?q="
+urls.update = "/update?q="
+urls.fortune = "/fortunes"
+approach = "Realistic"
+classification = "Micro"
+database = "Postgres"
+database_os = "Linux"
+os = "Linux"
+orm = "Raw"
+platform = "None"
+webserver = "ntex"
+versus = ""
+
 [plt]
 urls.plaintext = "/plaintext"
 urls.json = "/json"
@@ -82,3 +110,16 @@ orm = "Raw"
 platform = "None"
 webserver = "ntex"
 versus = ""
+
+[plt-neon]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+approach = "Realistic"
+classification = "Platform"
+database = "Postgres"
+database_os = "Linux"
+os = "Linux"
+orm = "Raw"
+platform = "None"
+webserver = "ntex"
+versus = ""

+ 16 - 0
frameworks/Rust/ntex/ntex-db-neon.dockerfile

@@ -0,0 +1,16 @@
+FROM rust:latest
+
+# Disable simd at jsonescape
+# ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=
+
+RUN apt-get update -yqq && apt-get install -yqq cmake g++
+
+ADD ./ /ntex
+WORKDIR /ntex
+
+RUN cargo clean
+RUN RUSTFLAGS="-C target-cpu=native" cargo build --release --features="neon"
+
+EXPOSE 8080
+
+CMD ./target/release/ntex-db-neon

+ 16 - 0
frameworks/Rust/ntex/ntex-neon.dockerfile

@@ -0,0 +1,16 @@
+FROM rust:latest
+
+# Disable simd at jsonescape
+# ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=
+
+RUN apt-get update -yqq && apt-get install -yqq cmake g++
+
+ADD ./ /ntex
+WORKDIR /ntex
+
+RUN cargo clean
+RUN RUSTFLAGS="-C target-cpu=native" cargo build --release --features="neon"
+
+EXPOSE 8080
+
+CMD ./target/release/ntex-neon

+ 16 - 0
frameworks/Rust/ntex/ntex-plt-neon.dockerfile

@@ -0,0 +1,16 @@
+FROM rust:latest
+
+# Disable simd at jsonescape
+# ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=
+
+RUN apt-get update -yqq && apt-get install -yqq cmake g++
+
+ADD ./ /ntex
+WORKDIR /ntex
+
+RUN cargo clean
+RUN RUSTFLAGS="-C target-cpu=native" cargo build --release --features="neon"
+
+EXPOSE 8080
+
+CMD ./target/release/ntex-plt-neon

+ 1 - 1
frameworks/Rust/ntex/src/db.rs

@@ -173,7 +173,7 @@ impl PgConnection {
         utils::reserve(&mut body, 4 * 1024);
 
         FortunesTemplate {
-            fortunes: &*fortunes,
+            fortunes: &fortunes,
         }
         .write_call(&mut body);
         fortunes.clear();

+ 2 - 16
frameworks/Rust/ntex/src/main.rs

@@ -2,7 +2,7 @@
 static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
 
 use ntex::http::header::{CONTENT_TYPE, SERVER};
-use ntex::{http, time::Seconds, util::BytesMut, util::PoolId, util::Ready, web};
+use ntex::{http, time::Seconds, util::BytesMut, util::PoolId, web};
 use sonic_rs::Serialize;
 
 mod utils;
@@ -48,13 +48,10 @@ async fn plaintext() -> web::HttpResponse {
 async fn main() -> std::io::Result<()> {
     println!("Started http server: 127.0.0.1:8080");
 
-    let cores = core_affinity::get_core_ids().unwrap();
-    let total_cores = cores.len();
-    let cores = std::sync::Arc::new(std::sync::Mutex::new(cores));
-
     // start http server
     ntex::server::build()
         .backlog(1024)
+        .enable_affinity()
         .bind("techempower", "0.0.0.0:8080", |cfg| {
             cfg.memory_pool(PoolId::P1);
             PoolId::P1.set_read_params(65535, 2048);
@@ -67,17 +64,6 @@ async fn main() -> std::io::Result<()> {
                 .payload_read_rate(Seconds::ZERO, Seconds::ZERO, 0)
                 .h1(web::App::new().service(json).service(plaintext).finish())
         })?
-        .configure(move |cfg| {
-            let cores = cores.clone();
-            cfg.on_worker_start(move |_| {
-                if let Some(core) = cores.lock().unwrap().pop() {
-                    core_affinity::set_for_current(core);
-                }
-                Ready::<_, &str>::Ok(())
-            });
-            Ok(())
-        })?
-        .workers(total_cores)
         .run()
         .await
 }

+ 2 - 16
frameworks/Rust/ntex/src/main_db.rs

@@ -6,7 +6,7 @@ use ntex::http::header::{CONTENT_TYPE, SERVER};
 use ntex::http::{HttpService, KeepAlive, Request, Response, StatusCode};
 use ntex::service::{Service, ServiceCtx, ServiceFactory};
 use ntex::web::{Error, HttpResponse};
-use ntex::{time::Seconds, util::PoolId, util::Ready};
+use ntex::{time::Seconds, util::PoolId};
 
 mod db;
 mod utils;
@@ -82,12 +82,9 @@ impl ServiceFactory<Request> for AppFactory {
 async fn main() -> std::io::Result<()> {
     println!("Starting http server: 127.0.0.1:8080");
 
-    let cores = core_affinity::get_core_ids().unwrap();
-    let total_cores = cores.len();
-    let cores = std::sync::Arc::new(std::sync::Mutex::new(cores));
-
     ntex::server::build()
         .backlog(1024)
+        .enable_affinity()
         .bind("techempower", "0.0.0.0:8080", |cfg| {
             cfg.memory_pool(PoolId::P1);
             PoolId::P1.set_read_params(65535, 2048);
@@ -100,17 +97,6 @@ async fn main() -> std::io::Result<()> {
                 .payload_read_rate(Seconds::ZERO, Seconds::ZERO, 0)
                 .h1(AppFactory)
         })?
-        .configure(move |cfg| {
-            let cores = cores.clone();
-            cfg.on_worker_start(move |_| {
-                if let Some(core) = cores.lock().unwrap().pop() {
-                    core_affinity::set_for_current(core);
-                }
-                Ready::<_, &str>::Ok(())
-            });
-            Ok(())
-        })?
-        .workers(total_cores)
         .run()
         .await
 }

+ 3 - 18
frameworks/Rust/ntex/src/main_plt.rs

@@ -1,10 +1,9 @@
 #[global_allocator]
 static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
 
-use std::{future::Future, io, pin::Pin, task::Context, task::Poll};
+use std::{future::Future, io, pin::Pin, task::ready, task::Context, task::Poll};
 
-use ntex::util::{ready, PoolId, Ready};
-use ntex::{fn_service, http::h1, io::Io, io::RecvError};
+use ntex::{fn_service, http::h1, io::Io, io::RecvError, util::PoolId};
 use sonic_rs::Serialize;
 
 mod utils;
@@ -79,13 +78,10 @@ impl Future for App {
 async fn main() -> io::Result<()> {
     println!("Started http server: 127.0.0.1:8080");
 
-    let cores = core_affinity::get_core_ids().unwrap();
-    let total_cores = cores.len();
-    let cores = std::sync::Arc::new(std::sync::Mutex::new(cores));
-
     // start http server
     ntex::server::build()
         .backlog(1024)
+        .enable_affinity()
         .bind("techempower", "0.0.0.0:8080", |cfg| {
             cfg.memory_pool(PoolId::P1);
             PoolId::P1.set_read_params(65535, 2048);
@@ -96,17 +92,6 @@ async fn main() -> io::Result<()> {
                 codec: h1::Codec::default(),
             })
         })?
-        .configure(move |cfg| {
-            let cores = cores.clone();
-            cfg.on_worker_start(move |_| {
-                if let Some(core) = cores.lock().unwrap().pop() {
-                    core_affinity::set_for_current(core);
-                }
-                Ready::<_, &str>::Ok(())
-            });
-            Ok(())
-        })?
-        .workers(total_cores)
         .run()
         .await
 }

+ 2 - 2
frameworks/Rust/ntex/src/utils.rs

@@ -34,7 +34,7 @@ pub fn reserve(buf: &mut BytesMut, lw: usize) {
 
 pub struct BytesWriter<'a>(pub &'a mut BytesMut);
 
-impl<'a> Write for BytesWriter<'a> {
+impl Write for BytesWriter<'_> {
     fn write(&mut self, src: &[u8]) -> Result<usize, io::Error> {
         self.0.extend_from_slice(src);
         Ok(src.len())
@@ -45,7 +45,7 @@ impl<'a> Write for BytesWriter<'a> {
     }
 }
 
-impl<'a> WriteExt for BytesWriter<'a> {
+impl WriteExt for BytesWriter<'_> {
     #[inline(always)]
     fn reserve_with(&mut self, additional: usize) -> Result<&mut [MaybeUninit<u8>], io::Error> {
         self.0.reserve(additional);