Browse Source

[Rust|may-minihttp] update may_postgres (#9150)

Xudong Huang 1 year ago
parent
commit
b0c5935e9b

+ 1 - 1
frameworks/Rust/may-minihttp/Cargo.toml

@@ -19,7 +19,7 @@ buf-min = { version = "0.7", features = ["bytes"] }
 
 
 may = { version = "0.3", default-features = false }
 may = { version = "0.3", default-features = false }
 may_minihttp = { version = "0.1", default-features = false }
 may_minihttp = { version = "0.1", default-features = false }
-may_postgres = { git = "https://github.com/Xudong-Huang/may_postgres.git", rev = "5ea3fb9", default-features = false }
+may_postgres = { git = "https://github.com/Xudong-Huang/may_postgres.git", rev = "917ed78", default-features = false }
 
 
 [profile.release]
 [profile.release]
 opt-level = 3
 opt-level = 3

+ 1 - 1
frameworks/Rust/may-minihttp/may-minihttp.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.78
+FROM rust:1.79
 
 
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 
 

+ 3 - 2
frameworks/Rust/may-minihttp/src/main.rs

@@ -49,7 +49,7 @@ struct PgConnectionPool {
 impl PgConnectionPool {
 impl PgConnectionPool {
     fn new(db_url: &'static str, size: usize) -> PgConnectionPool {
     fn new(db_url: &'static str, size: usize) -> PgConnectionPool {
         let clients = (0..size)
         let clients = (0..size)
-            .map(|_| std::thread::spawn(move || PgConnection::new(db_url)))
+            .map(|_| may::go!(move || PgConnection::new(db_url)))
             .collect::<Vec<_>>();
             .collect::<Vec<_>>();
         let mut clients: Vec<_> = clients.into_iter().map(|t| t.join().unwrap()).collect();
         let mut clients: Vec<_> = clients.into_iter().map(|t| t.join().unwrap()).collect();
         clients.sort_by(|a, b| (a.client.id() % size).cmp(&(b.client.id() % size)));
         clients.sort_by(|a, b| (a.client.id() % size).cmp(&(b.client.id() % size)));
@@ -59,6 +59,7 @@ impl PgConnectionPool {
     fn get_connection(&self, id: usize) -> PgConnection {
     fn get_connection(&self, id: usize) -> PgConnection {
         let len = self.clients.len();
         let len = self.clients.len();
         let connection = &self.clients[id % len];
         let connection = &self.clients[id % len];
+        // assert_eq!(connection.client.id() % len, id % len);
         PgConnection {
         PgConnection {
             client: connection.client.clone(),
             client: connection.client.clone(),
             statement: connection.statement.clone(),
             statement: connection.statement.clone(),
@@ -282,7 +283,7 @@ impl HttpServiceFactory for HttpServer {
 
 
 fn main() {
 fn main() {
     may::config().set_pool_capacity(1000).set_stack_size(0x1000);
     may::config().set_pool_capacity(1000).set_stack_size(0x1000);
-    println!("Starting http server: 127.0.0.1:8080");
+    println!("Starting http server: 0.0.0.1:8080");
     let server = HttpServer {
     let server = HttpServer {
         db_pool: PgConnectionPool::new(
         db_pool: PgConnectionPool::new(
             "postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world",
             "postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world",