Pārlūkot izejas kodu

Salvo: upgrade to version 0.29 (#7513)

* Salvo: upgrade to version 0.29

* optimize plaintext test
Chrislearn Young 3 gadi atpakaļ
vecāks
revīzija
75e690a453
2 mainītis faili ar 10 papildinājumiem un 20 dzēšanām
  1. 4 4
      frameworks/Rust/salvo/Cargo.toml
  2. 6 16
      frameworks/Rust/salvo/src/main.rs

+ 4 - 4
frameworks/Rust/salvo/Cargo.toml

@@ -22,18 +22,18 @@ bytes = "1.1.0"
 diesel = { version = "1.4", features = ["postgres", "r2d2"] }
 futures = "0.3"
 markup = "0.13.0"
-# mimalloc = { version = "0.1.25", default-features = false }
+mimalloc = { version = "0.1.25", default-features = false }
 once_cell = "1.5.2"
 rand = { version = "0.8.3", features = ["min_const_gen", "small_rng"] }
 random-fast-rng = "0.1.1"
-salvo = { version = "0.27", features = ["anyhow"] }
-serde = { version = "1.0", features = ["derive"] }
+salvo = { version = "0.29", default-features = false, features = ["anyhow"] }
+serde = { version = "1", features = ["derive"] }
 serde_json = "1.0.81"
 smallvec = "1.6.1"
 snmalloc-rs = { version = "0.3", features = ["native-cpu"] }
 tokio = { version = "1", features = ["macros", "rt"] }
 tokio-postgres = "0.7.2"
-v_htmlescape = "0.14"
+v_htmlescape = "0.15"
 
 [profile.release]
 lto = true

+ 6 - 16
frameworks/Rust/salvo/src/main.rs

@@ -1,8 +1,7 @@
-// #[global_allocator]
-// static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
+#[global_allocator]
+static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
 
 use std::sync::Arc;
-use std::thread::available_parallelism;
 
 use bytes::Bytes;
 use salvo::http::header::{self, HeaderValue};
@@ -38,31 +37,22 @@ fn plaintext(res: &mut Response) {
     res.set_body(Body::Once(Bytes::from_static(HELLO_WORLD)));
 }
 
-fn main() {
+#[tokio::main]
+async fn main() {
     let router = Arc::new(
         Router::new()
             .push(Router::with_path("plaintext").get(plaintext))
             .push(Router::with_path("json").get(json)),
     );
 
-    for _ in 1..available_parallelism().map(|n| n.get()).unwrap_or(16) {
-        let router = router.clone();
-        std::thread::spawn(move || {
-            let rt = tokio::runtime::Builder::new_current_thread()
-                .enable_all()
-                .build()
-                .unwrap();
-            rt.block_on(serve(router));
-        });
-    }
     println!("Started http server: 127.0.0.1:8080");
     let rt = tokio::runtime::Builder::new_current_thread()
         .enable_all()
         .build()
         .unwrap();
-    rt.block_on(serve(router));
+    serve(router).await;
 }
-
+#[inline]
 async fn serve(router: Arc<Router>) {
     server::builder()
         .http1_pipeline_flush(true)