Browse Source

ntex: use released deps (#9269)

Nikolay Kim 11 months ago
parent
commit
423880cfce
2 changed files with 14 additions and 24 deletions
  1. 3 8
      frameworks/Rust/ntex/Cargo.toml
  2. 11 16
      frameworks/Rust/ntex/src/db.rs

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

@@ -34,10 +34,11 @@ default = []
 tokio = ["ntex/tokio"]
 
 # compio runtime
-compio = ["ntex/compio"]
+compio = ["ntex/compio", ]
 
 [dependencies]
 ntex = "2.4"
+ntex-compio = "0.1.2"
 ntex-bytes = { version = "0.1.21", features=["simd"] }
 mimalloc = { version = "0.1.25", default-features = false }
 snmalloc-rs = { version = "0.3.3", features = ["native-cpu"] }
@@ -52,6 +53,7 @@ futures = "0.3"
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
 log = { version = "0.4", features = ["release_max_level_off"] }
+compio-driver = { version = "0.4", features = ["io-uring", "io-uring-socket"]}
 tok_io = {version = "1", package = "tokio" }
 tokio-postgres = { git="https://github.com/fafhrd91/postgres.git", branch="ntex-2" }
 
@@ -63,10 +65,3 @@ lto = "thin"
 debug = false
 incremental = false
 overflow-checks = false
-
-[patch.crates-io]
-ntex = { git = "https://github.com/ntex-rs/ntex.git", branch = "compio" }
-ntex-io = { git = "https://github.com/ntex-rs/ntex.git", branch = "compio" }
-ntex-rt = { git = "https://github.com/ntex-rs/ntex.git", branch = "compio" }
-ntex-net = { git = "https://github.com/ntex-rs/ntex.git", branch = "compio" }
-ntex-compio = { git = "https://github.com/ntex-rs/ntex.git", branch = "compio" }

+ 11 - 16
frameworks/Rust/ntex/src/db.rs

@@ -68,7 +68,7 @@ impl PgConnection {
             world,
             updates,
             rng: WyRand::new(),
-            buf: RefCell::new(BytesMut::with_capacity(65535)),
+            buf: RefCell::new(BytesMut::with_capacity(10 * 1024 * 1024)),
         }
     }
 }
@@ -80,7 +80,7 @@ impl PgConnection {
         let row = self.cl.query_one(&self.world, &[&random_id]).await.unwrap();
 
         let mut body = self.buf.borrow_mut();
-        utils::reserve(&mut body, 8 * 1024);
+        utils::reserve(&mut body, 1024);
         World {
             id: row.get(0),
             randomnumber: row.get(1),
@@ -107,7 +107,7 @@ impl PgConnection {
         }
 
         let mut body = self.buf.borrow_mut();
-        utils::reserve(&mut body, 8 * 1024);
+        utils::reserve(&mut body, 2 * 1024);
         body.put_u8(b'[');
         worlds.iter().for_each(|w| {
             w.to_bytes_mut(&mut *body);
@@ -119,7 +119,7 @@ impl PgConnection {
     }
 
     pub async fn update(&self, num: usize) -> Bytes {
-        let mut rng = self.rng.clone();
+        let mut rng = nanorand::tls_rng();
         let mut queries = SmallVec::<[_; 32]>::new();
         (0..num).for_each(|_| {
             let w_id = (rng.generate::<u32>() % 10_000 + 1) as i32;
@@ -146,7 +146,7 @@ impl PgConnection {
         let _ = self.cl.query(&self.updates[num - 1], &params).await;
 
         let mut body = self.buf.borrow_mut();
-        utils::reserve(&mut body, 8 * 1024);
+        utils::reserve(&mut body, 2 * 1024);
         body.put_u8(b'[');
         worlds.iter().for_each(|w| {
             w.to_bytes_mut(&mut *body);
@@ -158,25 +158,20 @@ impl PgConnection {
     }
 
     pub async fn tell_fortune(&self) -> Bytes {
-        let fut = self.cl.query_raw(&self.fortune, &[]);
+        let rows = self.cl.query_raw(&self.fortune, &[]).await.unwrap();
 
-        let rows = fut.await.unwrap();
         let mut fortunes: SmallVec<[_; 32]> = smallvec::smallvec![Fortune {
             id: 0,
             message: Cow::Borrowed("Additional fortune added at request time."),
         }];
-
-        for row in rows {
-            fortunes.push(Fortune {
-                id: row.get(0),
-                message: Cow::Owned(row.get(1)),
-            });
-        }
-
+        fortunes.extend(rows.iter().map(|row| Fortune {
+            id: row.get(0),
+            message: Cow::Owned(row.get(1)),
+        }));
         fortunes.sort_by(|it, next| it.message.cmp(&next.message));
 
         let mut body = std::mem::replace(&mut *self.buf.borrow_mut(), BytesMut::new());
-        utils::reserve(&mut body, 8 * 1024);
+        utils::reserve(&mut body, 4 * 1024);
         ywrite_html!(body, "{{> fortune }}");
         let result = body.split().freeze();
         let _ = std::mem::replace(&mut *self.buf.borrow_mut(), body);