Skip to content

Commit c9e3243

Browse files
committed
feat: dockerfile
1 parent a4026c2 commit c9e3243

File tree

5 files changed

+13
-24
lines changed

5 files changed

+13
-24
lines changed

frameworks/Rust/hyperlane/hyperlane.dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM rust:1.85
22

3+
RUN apt-get update -yqq && apt-get install -yqq cmake g++ binutils lld
4+
35
ENV POSTGRES_URL=postgres://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world
46

57
ADD ./ /hyperlane_techempower

frameworks/Rust/hyperlane/src/db.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ use crate::*;
22

33
#[inline]
44
pub async fn get_db_connection() -> DbPoolConnection {
5-
if let Some(db_pool) = DB.read().await.clone() {
6-
return db_pool;
5+
if let Some(db_pool) = DB.get() {
6+
return db_pool.clone();
77
};
88
let db_pool: DbPoolConnection = connection_db().await;
9-
{
10-
let mut db_pool_lock: RwLockWriteGuard<'_, Option<DbPoolConnection>> = DB.write().await;
11-
*db_pool_lock = Some(db_pool.clone());
12-
}
9+
DB.set(db_pool.clone())
10+
.expect("Failed to initialize DB_POOL");
1311
db_pool
1412
}
1513

@@ -97,8 +95,7 @@ pub async fn init_cache() {
9795
res.push(QueryRow::new(id, random_number));
9896
}
9997
}
100-
let mut cache: RwLockWriteGuard<'_, Vec<QueryRow>> = CACHE.write().await;
101-
*cache = res;
98+
let _ = CACHE.set(res);
10299
}
103100

104101
#[inline]
@@ -170,10 +167,7 @@ pub async fn get_update_data(
170167

171168
#[inline]
172169
pub async fn init_db() {
173-
{
174-
let mut db_pool_lock: RwLockWriteGuard<'_, Option<DbPoolConnection>> = DB.write().await;
175-
*db_pool_lock = Some(connection_db().await);
176-
}
170+
get_db_connection().await;
177171
#[cfg(feature = "dev")]
178172
{
179173
create_database().await;
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::*;
22

3-
pub static DB: Lazy<ArcRwLock<Option<DbPoolConnection>>> =
4-
Lazy::new(|| Arc::new(RwLock::new(None)));
5-
pub static CACHE: Lazy<ArcRwLock<Vec<QueryRow>>> = Lazy::new(|| arc_rwlock(vec![]));
3+
pub static DB: OnceCell<DbPoolConnection> = OnceCell::new();
4+
pub static CACHE: OnceCell<Vec<QueryRow>> = OnceCell::new();

frameworks/Rust/hyperlane/src/main.rs

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

1111
pub(crate) use constant::*;
1212
pub(crate) use db::*;
13-
pub(crate) use hyperlane::{
14-
once_cell::sync::Lazy,
15-
serde::*,
16-
serde_json::json,
17-
tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard},
18-
*,
19-
};
13+
pub(crate) use hyperlane::{once_cell::sync::OnceCell, serde::*, serde_json::json, *};
2014
pub(crate) use lazy::*;
2115
pub(crate) use rand::{Rng, SeedableRng, rng, rngs::SmallRng};
2216
pub(crate) use request_middleware::*;
@@ -27,7 +21,7 @@ pub(crate) use sqlx::{
2721
postgres::{PgPoolOptions, PgRow},
2822
*,
2923
};
30-
pub(crate) use std::{fmt, sync::Arc};
24+
pub(crate) use std::fmt;
3125
pub(crate) use r#type::*;
3226
pub(crate) use utils::*;
3327

frameworks/Rust/hyperlane/src/route.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub async fn cached_queries(controller_data: ControllerData) {
9797
.min(ROW_LIMIT as Queries)
9898
.max(1);
9999
let mut res: Vec<QueryRow> = Vec::with_capacity(count as usize);
100-
let cache: RwLockReadGuard<'_, Vec<QueryRow>> = CACHE.read().await;
100+
let cache: Vec<QueryRow> = CACHE.get().cloned().unwrap_or_default();
101101
for i in 0..count {
102102
res.push(cache[i as usize].clone());
103103
}

0 commit comments

Comments
 (0)