使用脚本循环请求时sqlx报错
“等待打开连接时池超时”
这个游泳池在下面
Pool { size: 5, num_idle: 5, is_closed: false, options: PoolOptions { max_connections: 5, min_connections: 0, connect_timeout: 30s, max_lifetime: Some(1800s), idle_timeout: Some(600s), test_before_acquire: true } }
这是我的代码
rust main.rs
#[derive(Serialize)]
struct JsonResp {
id: i32
}
#[derive(Clone)]
struct AppState {
pub pool: MySqlPool
}
#[async_std::main]
async fn main() -> tide::Result<()> {
let pool = MySqlPoolOptions::new()
.max_connections(5)
.connect("mysql://root:123456@localhost:3306/blog").await?;
println!("{:?}", pool);
let app_state = AppState { pool: pool };
let mut app = tide::with_state(app_state);
app.at("/test").get(test);
app.listen("127.0.0.1:8080").await?;
Ok(())
}
async fn test(req: Request<(AppState)>) -> tide::Result<tide::Body> {
println!("order_shoes");
let app_state = req.state();
let pool = &app_state.pool;
println!("{:?}", pool);
let (id, color) = sqlx::query_as::<_, (i32, String)>("select id, color from tags where id = 1").fetch_one(&mut pool.acquire().await?).await?;
println!("{}", color);
Ok(tide::Body::from_json( &JsonResp { id: id})?)
}
测试脚本
ruby_send.rb
require 'net/http'
require 'uri'
loop do
url = URI.parse("http://localhost:8080/test")
response = Net::HTTP.get(url)
p response
end
开始.shell
for i in {1..20}; do
nohup ruby ruby_send.rb > send.log &;
done
运行 start.shell 并没有响应请求