Browse Source

ntex: use mimalloc for db (#6488)

Nikolay Kim 4 years ago
parent
commit
44772ad4d7

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

@@ -16,8 +16,9 @@ name = "ntex-raw"
 path = "src/main_raw.rs"
 path = "src/main_raw.rs"
 
 
 [dependencies]
 [dependencies]
-ntex = "0.3.6"
-snmalloc-rs = { version = "0.2.25", features = ["1mib", "native-cpu"] }
+ntex = "0.3.12"
+mimalloc = { version = "0.1.25", default-features = false }
+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"] }
 env_logger = "0.8"
 env_logger = "0.8"
 random-fast-rng = "0.1.1"
 random-fast-rng = "0.1.1"

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

@@ -47,8 +47,7 @@ async fn main() -> std::io::Result<()> {
                 .keep_alive(http::KeepAlive::Os)
                 .keep_alive(http::KeepAlive::Os)
                 .client_timeout(0)
                 .client_timeout(0)
                 .disconnect_timeout(0)
                 .disconnect_timeout(0)
-                .read_high_watermark(65535)
-                .write_high_watermark(65535)
+                .buffer_params(65535, 65535, 1024)
                 .h1(web::App::new()
                 .h1(web::App::new()
                     .service(json)
                     .service(json)
                     .service(plaintext)
                     .service(plaintext)

+ 3 - 3
frameworks/Rust/ntex/src/main_db.rs

@@ -1,5 +1,5 @@
 #[global_allocator]
 #[global_allocator]
-static GLOBAL: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
+static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
 
 
 use std::{pin::Pin, task::Context, task::Poll};
 use std::{pin::Pin, task::Context, task::Poll};
 
 
@@ -99,11 +99,11 @@ async fn main() -> std::io::Result<()> {
                 .keep_alive(KeepAlive::Os)
                 .keep_alive(KeepAlive::Os)
                 .client_timeout(0)
                 .client_timeout(0)
                 .disconnect_timeout(0)
                 .disconnect_timeout(0)
-                .read_high_watermark(65535)
-                .write_high_watermark(65535)
+                .buffer_params(65535, 65535, 1024)
                 .h1(AppFactory)
                 .h1(AppFactory)
                 .tcp()
                 .tcp()
         })?
         })?
+        .workers((num_cpus::get() as f32 * 1.2) as usize)
         .start()
         .start()
         .await
         .await
 }
 }

+ 7 - 10
frameworks/Rust/ntex/src/main_raw.rs

@@ -39,11 +39,12 @@ impl Future for App {
             return Poll::Ready(Ok(()));
             return Poll::Ready(Ok(()));
         }
         }
 
 
-        let mut updated = false;
+        let read = this.state.read();
+        let write = this.state.write();
         loop {
         loop {
-            match this.state.decode_item(&this.codec) {
+            match read.decode(&this.codec) {
                 Ok(Some((req, _))) => {
                 Ok(Some((req, _))) => {
-                    this.state.with_write_buf(|buf| {
+                    write.with_buf(|buf| {
                         // make sure we've got room
                         // make sure we've got room
                         let remaining = buf.capacity() - buf.len();
                         let remaining = buf.capacity() - buf.len();
                         if remaining < 1024 {
                         if remaining < 1024 {
@@ -70,7 +71,6 @@ impl Future for App {
                             }
                             }
                         }
                         }
                     });
                     });
-                    updated = true;
                 }
                 }
                 Ok(None) => break,
                 Ok(None) => break,
                 _ => {
                 _ => {
@@ -79,13 +79,10 @@ impl Future for App {
                 }
                 }
             }
             }
         }
         }
-        if updated {
-            this.state.dsp_restart_write_task();
-        }
-        if this.state.is_read_ready() {
-            this.state.dsp_register_task(cx.waker());
+        if read.is_ready() {
+            this.state.register_dispatcher(cx.waker());
         } else {
         } else {
-            this.state.dsp_read_more_data(cx.waker());
+            read.wake(cx.waker())
         }
         }
         Poll::Pending
         Poll::Pending
     }
     }