Skip to content

Commit a6fdf66

Browse files
authored
Upgrade hyperlane (TechEmpower#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
1 parent 79ff46b commit a6fdf66

File tree

10 files changed

+33
-56
lines changed

10 files changed

+33
-56
lines changed

frameworks/Rust/hyperlane/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ exclude = [
1818
]
1919

2020
[dependencies]
21-
hyperlane = "4.42.1"
21+
hyperlane = "4.56.1"
2222
rand = "0.9.0"
2323
serde = "1.0.219"
2424
sqlx = { version = "0.8.3", features = ["runtime-tokio", "postgres"] }

frameworks/Rust/hyperlane/src/constant.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
pub static RESPONSEDATA: &str = "Hello, World!";
1+
pub static RESPONSEDATA_STR: &str = "Hello, World!";
2+
pub static RESPONSEDATA_BIN: &[u8] = b"Hello, World!";
23
pub static DATABASE_TYPE: &str = "postgres";
34
pub static DATABASE_HOST: &str = "tfb-database";
45
pub static DATABASE_USER_NAME: &str = "benchmarkdbuser";

frameworks/Rust/hyperlane/src/db.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::*;
22

3-
#[inline]
43
pub async fn get_db_connection() -> DbPoolConnection {
54
if let Some(db_pool) = DB.get() {
65
return db_pool.clone();
@@ -11,7 +10,6 @@ pub async fn get_db_connection() -> DbPoolConnection {
1110
db_pool
1211
}
1312

14-
#[inline]
1513
#[cfg(feature = "dev")]
1614
pub async fn create_database() {
1715
let db_pool: DbPoolConnection = get_db_connection().await;
@@ -20,7 +18,6 @@ pub async fn create_database() {
2018
.await;
2119
}
2220

23-
#[inline]
2421
#[cfg(feature = "dev")]
2522
pub async fn create_table() {
2623
let db_pool: DbPoolConnection = get_db_connection().await;
@@ -42,7 +39,6 @@ pub async fn create_table() {
4239
.await;
4340
}
4441

45-
#[inline]
4642
#[cfg(feature = "dev")]
4743
pub async fn insert_records() {
4844
let db_pool: DbPoolConnection = get_db_connection().await;
@@ -80,7 +76,6 @@ pub async fn insert_records() {
8076
let _ = query(&sql).execute(&db_pool).await;
8177
}
8278

83-
#[inline]
8479
pub async fn init_cache() {
8580
let mut res: Vec<QueryRow> = Vec::with_capacity(RANDOM_MAX as usize);
8681
let db_pool: DbPoolConnection = get_db_connection().await;
@@ -98,7 +93,6 @@ pub async fn init_cache() {
9893
let _ = CACHE.set(res);
9994
}
10095

101-
#[inline]
10296
pub async fn connection_db() -> DbPoolConnection {
10397
let db_url: &str = match option_env!("POSTGRES_URL") {
10498
Some(it) => it,
@@ -112,7 +106,7 @@ pub async fn connection_db() -> DbPoolConnection {
112106
DATABASE_NAME
113107
),
114108
};
115-
let pool_size: u32 = (get_thread_count() >> 2).max(10).min(100) as u32;
109+
let pool_size: u32 = (get_thread_count() << 2).max(10).min(100) as u32;
116110
let max_pool_size: u32 = option_env!("POSTGRES_MAX_POOL_SIZE")
117111
.unwrap_or(&pool_size.to_string())
118112
.parse::<u32>()
@@ -133,7 +127,6 @@ pub async fn connection_db() -> DbPoolConnection {
133127
pool
134128
}
135129

136-
#[inline]
137130
pub async fn get_update_data(
138131
limit: Queries,
139132
) -> (String, Vec<QueryRow>, Vec<Queries>, Vec<Queries>) {
@@ -165,7 +158,6 @@ pub async fn get_update_data(
165158
(sql, query_res_list, id_list, random_numbers)
166159
}
167160

168-
#[inline]
169161
pub async fn init_db() {
170162
get_db_connection().await;
171163
#[cfg(feature = "dev")]
@@ -177,13 +169,11 @@ pub async fn init_db() {
177169
init_cache().await;
178170
}
179171

180-
#[inline]
181172
pub async fn random_world_row(db_pool: &DbPoolConnection) -> QueryRow {
182173
let random_id: Queries = get_random_id();
183174
query_world_row(db_pool, random_id).await
184175
}
185176

186-
#[inline]
187177
pub async fn query_world_row(db_pool: &DbPoolConnection, id: Queries) -> QueryRow {
188178
let sql: String = format!(
189179
"SELECT id, randomNumber FROM {} WHERE id = {} LIMIT 1",
@@ -196,7 +186,6 @@ pub async fn query_world_row(db_pool: &DbPoolConnection, id: Queries) -> QueryRo
196186
return QueryRow::new(id as i32, 1);
197187
}
198188

199-
#[inline]
200189
pub async fn update_world_rows(limit: Queries) -> Vec<QueryRow> {
201190
let db_pool: DbPoolConnection = get_db_connection().await;
202191
let (sql, data, id_list, random_numbers) = get_update_data(limit).await;
@@ -211,21 +200,19 @@ pub async fn update_world_rows(limit: Queries) -> Vec<QueryRow> {
211200
data
212201
}
213202

214-
#[inline]
215203
pub async fn all_world_row() -> Vec<PgRow> {
216204
let db_pool: DbPoolConnection = get_db_connection().await;
217205
let sql: String = format!("SELECT id, message FROM {}", TABLE_NAME_FORTUNE);
218206
let res: Vec<PgRow> = query(&sql).fetch_all(&db_pool).await.unwrap_or_default();
219207
return res;
220208
}
221209

222-
#[inline]
223210
pub async fn get_some_row_id(limit: Queries, db_pool: &DbPoolConnection) -> Vec<QueryRow> {
224-
let mut res: Vec<QueryRow> = Vec::with_capacity(limit as usize);
225-
for _ in 0..limit {
226-
let id: i32 = get_random_id();
227-
let tem: QueryRow = query_world_row(db_pool, id).await;
228-
res.push(tem);
229-
}
230-
res
211+
let futures: Vec<_> = (0..limit)
212+
.map(|_| async {
213+
let id: i32 = get_random_id();
214+
query_world_row(db_pool, id).await
215+
})
216+
.collect();
217+
join_all(futures).await
231218
}

frameworks/Rust/hyperlane/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ pub(crate) mod utils;
1010

1111
pub(crate) use constant::*;
1212
pub(crate) use db::*;
13-
pub(crate) use hyperlane::{once_cell::sync::OnceCell, serde::*, serde_json::json, *};
13+
pub(crate) use futures::future::join_all;
14+
pub(crate) use hyperlane::{
15+
once_cell::sync::OnceCell,
16+
serde::*,
17+
serde_json::{Value, json},
18+
*,
19+
};
1420
pub(crate) use lazy::*;
1521
pub(crate) use rand::{Rng, SeedableRng, rng, rngs::SmallRng};
1622
pub(crate) use request_middleware::*;

frameworks/Rust/hyperlane/src/request_middleware.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::*;
22

3-
#[inline]
43
pub async fn request(controller_data: ControllerData) {
54
let _ = controller_data
65
.set_response_header(CONNECTION, CONNECTION_KEEP_ALIVE)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::*;
22

3-
#[inline]
43
pub async fn response(controller_data: ControllerData) {
54
let _ = controller_data.send().await;
65
}

frameworks/Rust/hyperlane/src/route.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
use crate::*;
22

3-
#[inline]
43
pub async fn json(controller_data: ControllerData) {
5-
let json: serde_json::Value = json!({
6-
"message": RESPONSEDATA
4+
let json: Value = json!({
5+
"message": RESPONSEDATA_STR
76
});
87
let _ = controller_data
98
.set_response_body(serde_json::to_string(&json).unwrap_or_default())
109
.await;
1110
}
1211

13-
#[inline]
1412
pub async fn plaintext(controller_data: ControllerData) {
1513
let _ = controller_data
1614
.set_response_header(CONTENT_TYPE, TEXT_PLAIN)
1715
.await
18-
.set_response_body(RESPONSEDATA)
16+
.set_response_body(RESPONSEDATA_BIN)
1917
.await;
2018
}
2119

22-
#[inline]
2320
pub async fn db(controller_data: ControllerData) {
2421
let db_connection: DbPoolConnection = get_db_connection().await;
2522
let query_row: QueryRow = random_world_row(&db_connection).await;
@@ -28,7 +25,6 @@ pub async fn db(controller_data: ControllerData) {
2825
.await;
2926
}
3027

31-
#[inline]
3228
pub async fn queries(controller_data: ControllerData) {
3329
let queries: Queries = controller_data
3430
.get_request_query("q")
@@ -37,18 +33,13 @@ pub async fn queries(controller_data: ControllerData) {
3733
.unwrap_or_default()
3834
.min(ROW_LIMIT as Queries)
3935
.max(1);
40-
let mut data: Vec<QueryRow> = Vec::with_capacity(queries as usize);
4136
let db_pool: DbPoolConnection = get_db_connection().await;
42-
for _ in 0..queries {
43-
let row: QueryRow = random_world_row(&db_pool).await;
44-
data.push(row);
45-
}
37+
let data: Vec<QueryRow> = get_some_row_id(queries, &db_pool).await;
4638
let _ = controller_data
4739
.set_response_body(serde_json::to_string(&data).unwrap_or_default())
4840
.await;
4941
}
5042

51-
#[inline]
5243
pub async fn fortunes(controller_data: ControllerData) {
5344
let all_rows: Vec<PgRow> = all_world_row().await;
5445
let mut fortunes_list: Vec<Fortunes> = all_rows
@@ -72,7 +63,6 @@ pub async fn fortunes(controller_data: ControllerData) {
7263
.await;
7364
}
7465

75-
#[inline]
7666
pub async fn updates(controller_data: ControllerData) {
7767
let queries: Queries = controller_data
7868
.get_request_query("q")
@@ -87,7 +77,6 @@ pub async fn updates(controller_data: ControllerData) {
8777
.await;
8878
}
8979

90-
#[inline]
9180
pub async fn cached_queries(controller_data: ControllerData) {
9281
let count: Queries = controller_data
9382
.get_request_query("c")
@@ -96,11 +85,13 @@ pub async fn cached_queries(controller_data: ControllerData) {
9685
.unwrap_or_default()
9786
.min(ROW_LIMIT as Queries)
9887
.max(1);
99-
let mut res: Vec<QueryRow> = Vec::with_capacity(count as usize);
100-
let cache: Vec<QueryRow> = CACHE.get().cloned().unwrap_or_default();
101-
for i in 0..count {
102-
res.push(cache[i as usize].clone());
103-
}
88+
let res: Vec<QueryRow> = CACHE
89+
.get()
90+
.unwrap_or(&Vec::new())
91+
.iter()
92+
.take(count as usize)
93+
.cloned()
94+
.collect();
10495
let _ = controller_data
10596
.set_response_body(serde_json::to_string(&res).unwrap_or_default())
10697
.await;

frameworks/Rust/hyperlane/src/server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use crate::*;
22

3-
#[inline]
43
pub async fn run_server() {
5-
let mut server: Server = Server::new();
4+
let server: Server = Server::new();
65
server.host("0.0.0.0").await;
76
server.port(8080).await;
8-
server.log_dir("./logs").await;
9-
server.log_interval_millis(1_000_000_000).await;
7+
server.disable_log().await;
108
server.disable_inner_log().await;
119
server.disable_inner_print().await;
10+
server.http_line_buffer_size(512).await;
11+
server.websocket_buffer_size(512).await;
1212
server.route("/plaintext", plaintext).await;
1313
server.route("/json", json).await;
1414
server.route("/cached-quer", cached_queries).await;

frameworks/Rust/hyperlane/src/type.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub struct QueryRow {
1111
}
1212

1313
impl QueryRow {
14-
#[inline]
1514
pub fn new(id: Queries, random_number: Queries) -> Self {
1615
Self {
1716
id,
@@ -27,7 +26,6 @@ pub struct Fortunes {
2726
}
2827

2928
impl Fortunes {
30-
#[inline]
3129
pub fn new(id: Queries, message: String) -> Self {
3230
Self { id, message }
3331
}
@@ -37,14 +35,12 @@ impl Fortunes {
3735
pub struct FortunesTemplate(pub Vec<Fortunes>);
3836

3937
impl FortunesTemplate {
40-
#[inline]
4138
pub fn new(list: Vec<Fortunes>) -> Self {
4239
Self(list)
4340
}
4441
}
4542

4643
impl fmt::Display for FortunesTemplate {
47-
#[inline]
4844
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4945
let fortunes: &Vec<Fortunes> = &self.0;
5046
let _ = write!(

frameworks/Rust/hyperlane/src/utils.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::*;
22

3-
#[inline]
43
pub fn escape_html(input: &str) -> String {
54
let mut result: String = String::new();
65
for ch in input.chars() {
@@ -16,7 +15,6 @@ pub fn escape_html(input: &str) -> String {
1615
result
1716
}
1817

19-
#[inline]
2018
pub fn get_random_id() -> Queries {
2119
let mut rng: SmallRng = SmallRng::from_rng(&mut rng());
2220
let random_id: u32 = rng.random_range(1..RANDOM_MAX_ADD_ONE);

0 commit comments

Comments
 (0)