Browse Source

upgrade ntex (#6605)

Nikolay Kim 4 years ago
parent
commit
235d791be8

+ 5 - 5
frameworks/Rust/ntex/Cargo.toml

@@ -16,20 +16,20 @@ name = "ntex-raw"
 path = "src/main_raw.rs"
 path = "src/main_raw.rs"
 
 
 [dependencies]
 [dependencies]
-ntex = "0.3.15"
+ntex = "0.3.17"
 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"] }
 env_logger = "0.8"
 env_logger = "0.8"
 nanorand = { version = "0.5", default-features = false, features = ["std", "wyrand"] }
 nanorand = { version = "0.5", default-features = false, features = ["std", "wyrand"] }
 bytes = "1.0"
 bytes = "1.0"
-atoi = "0.4.0"
+atoi = "0.4"
 num_cpus = "1.13"
 num_cpus = "1.13"
-futures = "0.3.13"
+futures = "0.3"
 http = "0.2"
 http = "0.2"
 smallvec = "1.6.1"
 smallvec = "1.6.1"
-simd-json = "0.3.24"
-simd-json-derive = "0.1.15"
+simd-json = "0.4.6"
+simd-json-derive = "0.2.2"
 serde = { version = "1.0", features = ["derive"] }
 serde = { version = "1.0", features = ["derive"] }
 log = { version = "0.4", features = ["release_max_level_off"] }
 log = { version = "0.4", features = ["release_max_level_off"] }
 tokio = "1"
 tokio = "1"

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

@@ -1,7 +1,7 @@
-FROM rust:1.50
+FROM rust:1.52.1
 
 
 # Disable simd at jsonescape
 # Disable simd at jsonescape
-ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=
+# ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=
 
 
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 
 

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

@@ -1,7 +1,7 @@
-FROM rust:1.50
+FROM rust:1.52.1
 
 
 # Disable simd at jsonescape
 # Disable simd at jsonescape
-ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=
+# ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=
 
 
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 
 

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

@@ -1,7 +1,7 @@
-FROM rust:1.50
+FROM rust:1.52.1
 
 
 # Disable simd at jsonescape
 # Disable simd at jsonescape
-ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=
+# ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=
 
 
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 
 

+ 7 - 29
frameworks/Rust/ntex/src/main_db.rs

@@ -1,7 +1,7 @@
 #[global_allocator]
 #[global_allocator]
 static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
 static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
 
 
-use std::{cell::Cell, pin::Pin, task::Context, task::Poll};
+use std::{pin::Pin, task::Context, task::Poll};
 
 
 use bytes::BytesMut;
 use bytes::BytesMut;
 use futures::future::{ok, Future, FutureExt};
 use futures::future::{ok, Future, FutureExt};
@@ -14,23 +14,7 @@ use yarte::Serialize;
 mod db;
 mod db;
 mod utils;
 mod utils;
 
 
-struct App {
-    c1: db::PgConnection,
-    c2: db::PgConnection,
-    next: Cell<bool>,
-}
-
-impl App {
-    fn get_db(&self) -> &db::PgConnection {
-        if self.next.get() {
-            self.next.set(!self.next.get());
-            &self.c1
-        } else {
-            self.next.set(!self.next.get());
-            &self.c2
-        }
-    }
-}
+struct App(db::PgConnection);
 
 
 impl Service for App {
 impl Service for App {
     type Request = Request;
     type Request = Request;
@@ -45,13 +29,13 @@ impl Service for App {
 
 
     fn call(&self, req: Request) -> Self::Future {
     fn call(&self, req: Request) -> Self::Future {
         match req.path() {
         match req.path() {
-            "/db" => Box::pin(self.get_db().get_world().map(|body| {
+            "/db" => Box::pin(self.0.get_world().map(|body| {
                 Ok(HttpResponse::Ok()
                 Ok(HttpResponse::Ok()
                     .header(SERVER, HeaderValue::from_static("N"))
                     .header(SERVER, HeaderValue::from_static("N"))
                     .header(CONTENT_TYPE, HeaderValue::from_static("application/json"))
                     .header(CONTENT_TYPE, HeaderValue::from_static("application/json"))
                     .body(body))
                     .body(body))
             })),
             })),
-            "/fortunes" => Box::pin(self.get_db().tell_fortune().map(|body| {
+            "/fortunes" => Box::pin(self.0.tell_fortune().map(|body| {
                 Ok(HttpResponse::Ok()
                 Ok(HttpResponse::Ok()
                     .header(SERVER, HeaderValue::from_static("N"))
                     .header(SERVER, HeaderValue::from_static("N"))
                     .header(
                     .header(
@@ -61,7 +45,7 @@ impl Service for App {
                     .body(body))
                     .body(body))
             })),
             })),
             "/query" => Box::pin(
             "/query" => Box::pin(
-                self.get_db()
+                self.0
                     .get_worlds(utils::get_query_param(req.uri().query()))
                     .get_worlds(utils::get_query_param(req.uri().query()))
                     .map(|worlds| {
                     .map(|worlds| {
                         Ok(HttpResponse::Ok()
                         Ok(HttpResponse::Ok()
@@ -71,7 +55,7 @@ impl Service for App {
                     }),
                     }),
             ),
             ),
             "/update" => Box::pin(
             "/update" => Box::pin(
-                self.get_db()
+                self.0
                     .update(utils::get_query_param(req.uri().query()))
                     .update(utils::get_query_param(req.uri().query()))
                     .map(|worlds| {
                     .map(|worlds| {
                         Ok(HttpResponse::Ok()
                         Ok(HttpResponse::Ok()
@@ -100,13 +84,7 @@ impl ServiceFactory for AppFactory {
         const DB_URL: &str =
         const DB_URL: &str =
             "postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world";
             "postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world";
 
 
-        Box::pin(async move {
-            Ok(App {
-                next: Cell::new(true),
-                c1: db::PgConnection::connect(DB_URL).await,
-                c2: db::PgConnection::connect(DB_URL).await,
-            })
-        })
+        Box::pin(async move { Ok(App(db::PgConnection::connect(DB_URL).await)) })
     }
     }
 }
 }