Browse Source

ntex: add native support for async-std runtime (#7000)

* add ntex on top of async-std runtime

* fix async-std compilation

* update min ver

* upgrade to ntex 0.5 release

* uncomment dep
Nikolay Kim 3 years ago
parent
commit
43555cc468

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

@@ -7,16 +7,37 @@ edition = "2018"
 name = "ntex"
 name = "ntex"
 path = "src/main.rs"
 path = "src/main.rs"
 
 
+[[bin]]
+name = "ntex-astd"
+path = "src/main.rs"
+
 [[bin]]
 [[bin]]
 name = "ntex-db"
 name = "ntex-db"
 path = "src/main_db.rs"
 path = "src/main_db.rs"
 
 
 [[bin]]
 [[bin]]
-name = "ntex-raw"
-path = "src/main_raw.rs"
+name = "ntex-db-astd"
+path = "src/main_db.rs"
+
+[[bin]]
+name = "ntex-plt"
+path = "src/main_plt.rs"
+
+[[bin]]
+name = "ntex-plt-astd"
+path = "src/main_plt.rs"
+
+[features]
+default = []
+
+# tokio runtime
+tokio = ["ntex/tokio"]
+
+# async-std runtime
+async-std = ["ntex/async-std"]
 
 
 [dependencies]
 [dependencies]
-ntex = "0.5.0-b.4"
+ntex = { version = "0.5.0", default-features = false }
 mimalloc = { version = "0.1.25", default-features = false }
 mimalloc = { version = "0.1.25", default-features = false }
 snmalloc-rs = { version = "0.2.26", features = ["1mib", "native-cpu"] }
 snmalloc-rs = { version = "0.2.26", features = ["1mib", "native-cpu"] }
 yarte = { version = "0.15", features = ["bytes-buf", "json"] }
 yarte = { version = "0.15", features = ["bytes-buf", "json"] }
@@ -32,7 +53,6 @@ simd-json-derive = "0.2.2"
 serde = { version = "1.0", features = ["derive"] }
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
 serde_json = "1.0"
 log = { version = "0.4", features = ["release_max_level_off"] }
 log = { version = "0.4", features = ["release_max_level_off"] }
-tokio = { version = "1", default-features = false }
 tokio-postgres = { git="https://github.com/fafhrd91/postgres.git" }
 tokio-postgres = { git="https://github.com/fafhrd91/postgres.git" }
 
 
 [profile.release]
 [profile.release]

+ 60 - 4
frameworks/Rust/ntex/benchmark_config.json

@@ -15,7 +15,25 @@
       "webserver": "ntex",
       "webserver": "ntex",
       "os": "Linux",
       "os": "Linux",
       "database_os": "Linux",
       "database_os": "Linux",
-      "display_name": "ntex",
+      "display_name": "ntex [tokio]",
+      "notes": "",
+      "versus": ""
+    },
+    "astd": {
+      "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 [async-std]",
       "notes": "",
       "notes": "",
       "versus": ""
       "versus": ""
     },
     },
@@ -35,11 +53,49 @@
       "webserver": "ntex",
       "webserver": "ntex",
       "os": "Linux",
       "os": "Linux",
       "database_os": "Linux",
       "database_os": "Linux",
-      "display_name": "ntex [db]",
+      "display_name": "ntex [tokio,db]",
+      "notes": "",
+      "versus": ""
+    },
+    "db-astd": {
+      "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 [async-std,db]",
+      "notes": "",
+      "versus": ""
+    },
+    "plt": {
+      "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 [tokio,platform]",
       "notes": "",
       "notes": "",
       "versus": ""
       "versus": ""
     },
     },
-    "raw": {
+    "plt-astd": {
       "json_url": "/json",
       "json_url": "/json",
       "plaintext_url": "/plaintext",
       "plaintext_url": "/plaintext",
       "port": 8080,
       "port": 8080,
@@ -53,7 +109,7 @@
       "webserver": "ntex",
       "webserver": "ntex",
       "os": "Linux",
       "os": "Linux",
       "database_os": "Linux",
       "database_os": "Linux",
-      "display_name": "ntex [raw]",
+      "display_name": "ntex [async-std,platform]",
       "notes": "",
       "notes": "",
       "versus": ""
       "versus": ""
     }
     }

+ 42 - 1
frameworks/Rust/ntex/config.toml

@@ -14,6 +14,19 @@ platform = "None"
 webserver = "ntex"
 webserver = "ntex"
 versus = ""
 versus = ""
 
 
+[astd]
+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]
 [db]
 urls.db = "/db"
 urls.db = "/db"
 urls.query = "/query?q="
 urls.query = "/query?q="
@@ -29,7 +42,35 @@ platform = "None"
 webserver = "ntex"
 webserver = "ntex"
 versus = ""
 versus = ""
 
 
-[raw]
+[db-astd]
+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"
+approach = "Realistic"
+classification = "Platform"
+database = "Postgres"
+database_os = "Linux"
+os = "Linux"
+orm = "Raw"
+platform = "None"
+webserver = "ntex"
+versus = ""
+
+[plt-astd]
 urls.plaintext = "/plaintext"
 urls.plaintext = "/plaintext"
 urls.json = "/json"
 urls.json = "/json"
 approach = "Realistic"
 approach = "Realistic"

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

@@ -0,0 +1,16 @@
+FROM rust:1.57.0
+
+# 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="async-std"
+
+EXPOSE 8080
+
+CMD ./target/release/ntex-astd

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

@@ -0,0 +1,16 @@
+FROM rust:1.57.0
+
+# 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="async-std"
+
+EXPOSE 8080
+
+CMD ./target/release/ntex-db-astd

+ 1 - 1
frameworks/Rust/ntex/ntex-db.dockerfile

@@ -9,7 +9,7 @@ ADD ./ /ntex
 WORKDIR /ntex
 WORKDIR /ntex
 
 
 RUN cargo clean
 RUN cargo clean
-RUN RUSTFLAGS="-C target-cpu=native" cargo build --release
+RUN RUSTFLAGS="-C target-cpu=native" cargo build --release --features="tokio"
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 

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

@@ -0,0 +1,16 @@
+FROM rust:1.57.0
+
+# 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="async-std"
+
+EXPOSE 8080
+
+CMD ./target/release/ntex-plt-astd

+ 2 - 2
frameworks/Rust/ntex/ntex-raw.dockerfile → frameworks/Rust/ntex/ntex-plt.dockerfile

@@ -9,8 +9,8 @@ ADD ./ /ntex
 WORKDIR /ntex
 WORKDIR /ntex
 
 
 RUN cargo clean
 RUN cargo clean
-RUN RUSTFLAGS="-C target-cpu=native" cargo build --release
+RUN RUSTFLAGS="-C target-cpu=native" cargo build --release --features="tokio"
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 
-CMD ./target/release/ntex-raw
+CMD ./target/release/ntex-plt

+ 1 - 1
frameworks/Rust/ntex/ntex.dockerfile

@@ -9,7 +9,7 @@ ADD ./ /ntex
 WORKDIR /ntex
 WORKDIR /ntex
 
 
 RUN cargo clean
 RUN cargo clean
-RUN RUSTFLAGS="-C target-cpu=native" cargo build --release
+RUN RUSTFLAGS="-C target-cpu=native" cargo build --release --features="tokio"
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 

+ 3 - 1
frameworks/Rust/ntex/src/main_raw.rs → frameworks/Rust/ntex/src/main_plt.rs

@@ -2,7 +2,9 @@
 static GLOBAL: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
 static GLOBAL: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
 use std::{future::Future, io, pin::Pin, task::Context, task::Poll};
 use std::{future::Future, io, pin::Pin, task::Context, task::Poll};
 
 
-use ntex::{fn_service, http::h1, io::Io, io::RecvError, util::ready, util::BufMut, util::PoolId};
+use ntex::{
+    fn_service, http::h1, io::Io, io::RecvError, util::ready, util::BufMut, util::PoolId,
+};
 mod utils;
 mod utils;
 
 
 #[cfg(target_os = "macos")]
 #[cfg(target_os = "macos")]