Explorar o código

Upgrade hyperlane (#9719)

* feat: update & fortune

* feat: randomNumber

* feat: max row 500

* feat: update

* feat: Fortune

* feat: fortunes

* feat: update

* feat: update

* feat: update

* feat: update

* feat: fortunes

* feat: fortunes

* feat: fortunes

* feat: fortunes

* feat: fortunes

* feat: fortunes

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: cache

* feat: cache

* feat: config

* feat: config

* feat: config

* feat: v4.36.1

* docs: readme

* feat: remove dyn

* docs: readme

* feat: lock

* feat: lock

* feat: lock

* feat: lock

* feat: db pool

* feat: db pool

* feat: lock

* feat: lock

* feat: db

* feat: db

* feat: db

* feat: db

* feat: db

* feat: db

* feat: db

* feat: db

* feat: rand

* feat: rand

* feat: rand

* feat: rand

* feat: rand

* feat: port

* feat: port

* feat: port

* feat: db

* feat: db

* feat: db

* feat: lock

* feat: lock

* feat: v4.41.0

* feat: v4.42.0

* Merge remote-tracking branch 'upstream/master'

* Merge remote-tracking branch 'upstream/master'

* feat: inline

* feat: dockerfile

* feat: v4.52.1

* feat: remove key

* remove: log

* remove: log

* feat: async

* remove: empty loop

* feat: utf8

* change: pool_size

* remove: utf8

* feat: log

* feat: log

* feat: v3.14.1
尤雨东 hai 5 meses
pai
achega
a6fdf666ea

+ 1 - 1
frameworks/Rust/hyperlane/Cargo.toml

@@ -18,7 +18,7 @@ exclude = [
 ]
 
 [dependencies]
-hyperlane = "4.42.1"
+hyperlane = "4.56.1"
 rand = "0.9.0"
 serde = "1.0.219"
 sqlx = { version = "0.8.3", features = ["runtime-tokio", "postgres"] }

+ 2 - 1
frameworks/Rust/hyperlane/src/constant.rs

@@ -1,4 +1,5 @@
-pub static RESPONSEDATA: &str = "Hello, World!";
+pub static RESPONSEDATA_STR: &str = "Hello, World!";
+pub static RESPONSEDATA_BIN: &[u8] = b"Hello, World!";
 pub static DATABASE_TYPE: &str = "postgres";
 pub static DATABASE_HOST: &str = "tfb-database";
 pub static DATABASE_USER_NAME: &str = "benchmarkdbuser";

+ 8 - 21
frameworks/Rust/hyperlane/src/db.rs

@@ -1,6 +1,5 @@
 use crate::*;
 
-#[inline]
 pub async fn get_db_connection() -> DbPoolConnection {
     if let Some(db_pool) = DB.get() {
         return db_pool.clone();
@@ -11,7 +10,6 @@ pub async fn get_db_connection() -> DbPoolConnection {
     db_pool
 }
 
-#[inline]
 #[cfg(feature = "dev")]
 pub async fn create_database() {
     let db_pool: DbPoolConnection = get_db_connection().await;
@@ -20,7 +18,6 @@ pub async fn create_database() {
         .await;
 }
 
-#[inline]
 #[cfg(feature = "dev")]
 pub async fn create_table() {
     let db_pool: DbPoolConnection = get_db_connection().await;
@@ -42,7 +39,6 @@ pub async fn create_table() {
     .await;
 }
 
-#[inline]
 #[cfg(feature = "dev")]
 pub async fn insert_records() {
     let db_pool: DbPoolConnection = get_db_connection().await;
@@ -80,7 +76,6 @@ pub async fn insert_records() {
     let _ = query(&sql).execute(&db_pool).await;
 }
 
-#[inline]
 pub async fn init_cache() {
     let mut res: Vec<QueryRow> = Vec::with_capacity(RANDOM_MAX as usize);
     let db_pool: DbPoolConnection = get_db_connection().await;
@@ -98,7 +93,6 @@ pub async fn init_cache() {
     let _ = CACHE.set(res);
 }
 
-#[inline]
 pub async fn connection_db() -> DbPoolConnection {
     let db_url: &str = match option_env!("POSTGRES_URL") {
         Some(it) => it,
@@ -112,7 +106,7 @@ pub async fn connection_db() -> DbPoolConnection {
             DATABASE_NAME
         ),
     };
-    let pool_size: u32 = (get_thread_count() >> 2).max(10).min(100) as u32;
+    let pool_size: u32 = (get_thread_count() << 2).max(10).min(100) as u32;
     let max_pool_size: u32 = option_env!("POSTGRES_MAX_POOL_SIZE")
         .unwrap_or(&pool_size.to_string())
         .parse::<u32>()
@@ -133,7 +127,6 @@ pub async fn connection_db() -> DbPoolConnection {
     pool
 }
 
-#[inline]
 pub async fn get_update_data(
     limit: Queries,
 ) -> (String, Vec<QueryRow>, Vec<Queries>, Vec<Queries>) {
@@ -165,7 +158,6 @@ pub async fn get_update_data(
     (sql, query_res_list, id_list, random_numbers)
 }
 
-#[inline]
 pub async fn init_db() {
     get_db_connection().await;
     #[cfg(feature = "dev")]
@@ -177,13 +169,11 @@ pub async fn init_db() {
     init_cache().await;
 }
 
-#[inline]
 pub async fn random_world_row(db_pool: &DbPoolConnection) -> QueryRow {
     let random_id: Queries = get_random_id();
     query_world_row(db_pool, random_id).await
 }
 
-#[inline]
 pub async fn query_world_row(db_pool: &DbPoolConnection, id: Queries) -> QueryRow {
     let sql: String = format!(
         "SELECT id, randomNumber FROM {} WHERE id = {} LIMIT 1",
@@ -196,7 +186,6 @@ pub async fn query_world_row(db_pool: &DbPoolConnection, id: Queries) -> QueryRo
     return QueryRow::new(id as i32, 1);
 }
 
-#[inline]
 pub async fn update_world_rows(limit: Queries) -> Vec<QueryRow> {
     let db_pool: DbPoolConnection = get_db_connection().await;
     let (sql, data, id_list, random_numbers) = get_update_data(limit).await;
@@ -211,7 +200,6 @@ pub async fn update_world_rows(limit: Queries) -> Vec<QueryRow> {
     data
 }
 
-#[inline]
 pub async fn all_world_row() -> Vec<PgRow> {
     let db_pool: DbPoolConnection = get_db_connection().await;
     let sql: String = format!("SELECT id, message FROM {}", TABLE_NAME_FORTUNE);
@@ -219,13 +207,12 @@ pub async fn all_world_row() -> Vec<PgRow> {
     return res;
 }
 
-#[inline]
 pub async fn get_some_row_id(limit: Queries, db_pool: &DbPoolConnection) -> Vec<QueryRow> {
-    let mut res: Vec<QueryRow> = Vec::with_capacity(limit as usize);
-    for _ in 0..limit {
-        let id: i32 = get_random_id();
-        let tem: QueryRow = query_world_row(db_pool, id).await;
-        res.push(tem);
-    }
-    res
+    let futures: Vec<_> = (0..limit)
+        .map(|_| async {
+            let id: i32 = get_random_id();
+            query_world_row(db_pool, id).await
+        })
+        .collect();
+    join_all(futures).await
 }

+ 7 - 1
frameworks/Rust/hyperlane/src/main.rs

@@ -10,7 +10,13 @@ pub(crate) mod utils;
 
 pub(crate) use constant::*;
 pub(crate) use db::*;
-pub(crate) use hyperlane::{once_cell::sync::OnceCell, serde::*, serde_json::json, *};
+pub(crate) use futures::future::join_all;
+pub(crate) use hyperlane::{
+    once_cell::sync::OnceCell,
+    serde::*,
+    serde_json::{Value, json},
+    *,
+};
 pub(crate) use lazy::*;
 pub(crate) use rand::{Rng, SeedableRng, rng, rngs::SmallRng};
 pub(crate) use request_middleware::*;

+ 0 - 1
frameworks/Rust/hyperlane/src/request_middleware.rs

@@ -1,6 +1,5 @@
 use crate::*;
 
-#[inline]
 pub async fn request(controller_data: ControllerData) {
     let _ = controller_data
         .set_response_header(CONNECTION, CONNECTION_KEEP_ALIVE)

+ 0 - 1
frameworks/Rust/hyperlane/src/response_middleware.rs

@@ -1,6 +1,5 @@
 use crate::*;
 
-#[inline]
 pub async fn response(controller_data: ControllerData) {
     let _ = controller_data.send().await;
 }

+ 11 - 20
frameworks/Rust/hyperlane/src/route.rs

@@ -1,25 +1,22 @@
 use crate::*;
 
-#[inline]
 pub async fn json(controller_data: ControllerData) {
-    let json: serde_json::Value = json!({
-        "message": RESPONSEDATA
+    let json: Value = json!({
+        "message": RESPONSEDATA_STR
     });
     let _ = controller_data
         .set_response_body(serde_json::to_string(&json).unwrap_or_default())
         .await;
 }
 
-#[inline]
 pub async fn plaintext(controller_data: ControllerData) {
     let _ = controller_data
         .set_response_header(CONTENT_TYPE, TEXT_PLAIN)
         .await
-        .set_response_body(RESPONSEDATA)
+        .set_response_body(RESPONSEDATA_BIN)
         .await;
 }
 
-#[inline]
 pub async fn db(controller_data: ControllerData) {
     let db_connection: DbPoolConnection = get_db_connection().await;
     let query_row: QueryRow = random_world_row(&db_connection).await;
@@ -28,7 +25,6 @@ pub async fn db(controller_data: ControllerData) {
         .await;
 }
 
-#[inline]
 pub async fn queries(controller_data: ControllerData) {
     let queries: Queries = controller_data
         .get_request_query("q")
@@ -37,18 +33,13 @@ pub async fn queries(controller_data: ControllerData) {
         .unwrap_or_default()
         .min(ROW_LIMIT as Queries)
         .max(1);
-    let mut data: Vec<QueryRow> = Vec::with_capacity(queries as usize);
     let db_pool: DbPoolConnection = get_db_connection().await;
-    for _ in 0..queries {
-        let row: QueryRow = random_world_row(&db_pool).await;
-        data.push(row);
-    }
+    let data: Vec<QueryRow> = get_some_row_id(queries, &db_pool).await;
     let _ = controller_data
         .set_response_body(serde_json::to_string(&data).unwrap_or_default())
         .await;
 }
 
-#[inline]
 pub async fn fortunes(controller_data: ControllerData) {
     let all_rows: Vec<PgRow> = all_world_row().await;
     let mut fortunes_list: Vec<Fortunes> = all_rows
@@ -72,7 +63,6 @@ pub async fn fortunes(controller_data: ControllerData) {
         .await;
 }
 
-#[inline]
 pub async fn updates(controller_data: ControllerData) {
     let queries: Queries = controller_data
         .get_request_query("q")
@@ -87,7 +77,6 @@ pub async fn updates(controller_data: ControllerData) {
         .await;
 }
 
-#[inline]
 pub async fn cached_queries(controller_data: ControllerData) {
     let count: Queries = controller_data
         .get_request_query("c")
@@ -96,11 +85,13 @@ pub async fn cached_queries(controller_data: ControllerData) {
         .unwrap_or_default()
         .min(ROW_LIMIT as Queries)
         .max(1);
-    let mut res: Vec<QueryRow> = Vec::with_capacity(count as usize);
-    let cache: Vec<QueryRow> = CACHE.get().cloned().unwrap_or_default();
-    for i in 0..count {
-        res.push(cache[i as usize].clone());
-    }
+    let res: Vec<QueryRow> = CACHE
+        .get()
+        .unwrap_or(&Vec::new())
+        .iter()
+        .take(count as usize)
+        .cloned()
+        .collect();
     let _ = controller_data
         .set_response_body(serde_json::to_string(&res).unwrap_or_default())
         .await;

+ 4 - 4
frameworks/Rust/hyperlane/src/server.rs

@@ -1,14 +1,14 @@
 use crate::*;
 
-#[inline]
 pub async fn run_server() {
-    let mut server: Server = Server::new();
+    let server: Server = Server::new();
     server.host("0.0.0.0").await;
     server.port(8080).await;
-    server.log_dir("./logs").await;
-    server.log_interval_millis(1_000_000_000).await;
+    server.disable_log().await;
     server.disable_inner_log().await;
     server.disable_inner_print().await;
+    server.http_line_buffer_size(512).await;
+    server.websocket_buffer_size(512).await;
     server.route("/plaintext", plaintext).await;
     server.route("/json", json).await;
     server.route("/cached-quer", cached_queries).await;

+ 0 - 4
frameworks/Rust/hyperlane/src/type.rs

@@ -11,7 +11,6 @@ pub struct QueryRow {
 }
 
 impl QueryRow {
-    #[inline]
     pub fn new(id: Queries, random_number: Queries) -> Self {
         Self {
             id,
@@ -27,7 +26,6 @@ pub struct Fortunes {
 }
 
 impl Fortunes {
-    #[inline]
     pub fn new(id: Queries, message: String) -> Self {
         Self { id, message }
     }
@@ -37,14 +35,12 @@ impl Fortunes {
 pub struct FortunesTemplate(pub Vec<Fortunes>);
 
 impl FortunesTemplate {
-    #[inline]
     pub fn new(list: Vec<Fortunes>) -> Self {
         Self(list)
     }
 }
 
 impl fmt::Display for FortunesTemplate {
-    #[inline]
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         let fortunes: &Vec<Fortunes> = &self.0;
         let _ = write!(

+ 0 - 2
frameworks/Rust/hyperlane/src/utils.rs

@@ -1,6 +1,5 @@
 use crate::*;
 
-#[inline]
 pub fn escape_html(input: &str) -> String {
     let mut result: String = String::new();
     for ch in input.chars() {
@@ -16,7 +15,6 @@ pub fn escape_html(input: &str) -> String {
     result
 }
 
-#[inline]
 pub fn get_random_id() -> Queries {
     let mut rng: SmallRng = SmallRng::from_rng(&mut rng());
     let random_id: u32 = rng.random_range(1..RANDOM_MAX_ADD_ONE);