Comments (11)
经过更换数据库连接池,应该解决了。
https://github.com/importcjj/mobc
use std::time::Duration;
use rbatis::rbatis::RBatis;
use rbdc_pool_mobc::MobcPool;
pub async fn init_db() -> RBatis {
let rb = RBatis::new();
let opts = rbdc_mysql::options::MySqlConnectOptions::new()
.host("****")
.username("rust")
.password("*****")
.database("test");
rb.init_option::<rbdc_mysql::driver::MysqlDriver, rbdc_mysql::options::MySqlConnectOptions, MobcPool>(rbdc_mysql::driver::MysqlDriver {}, opts).unwrap();
let pool = rb.get_pool().unwrap();
pool.set_max_open_conns(2).await;
pool.set_max_idle_conns(2).await; // 这个参数设置有效果
let five_seconds = Duration::new(5, 0); // 支持
pool.set_timeout(Option::from(five_seconds)).await;
let five_seconds = Duration::new(20, 0); // 设置貌似没有效果啊,官方解答目前不支持
pool.set_conn_max_lifetime(Option::from(five_seconds)).await;
return rb;
}
from axum-admin.
依赖有升级不
没有,就改了数据库,我确定golang连接这个数据库没有问题,数据库也是默认配置。没啥修改。
今天有空闲下来测了下,没问题,我现在把项目依赖升级了一下,可以拉下最新代码看看
from axum-admin.
from axum-admin.
依赖有升级不
from axum-admin.
依赖有升级不
没有,就改了数据库,我确定golang连接这个数据库没有问题,数据库也是默认配置。没啥修改。
from axum-admin.
用命令SHOW PROCESSLIST 看下数据库的连接情况,是不是只有这个应用连接上的
from axum-admin.
@feihua 上图可以看出来,我就是用了SHOW PROCESSLIST
分析出来了。
from axum-admin.
启动程序,发起请求。
每个请求,就增加三个,一直到10个。基本上确定程序连接池没有问题。
from axum-admin.
我修改了连接池大小
use std::time::Duration;
use rbatis::rbatis::RBatis;
pub async fn init_db() -> RBatis {
let rb = RBatis::new();
rb.init(rbdc_mysql::driver::MysqlDriver {}, "mysql://**:**@*****:3306/test").unwrap();
let pool = rb.get_pool().unwrap();
pool.set_max_open_conns(3).await;
pool.set_max_idle_conns(3).await; // 这个参数设置有效果
let five_seconds = Duration::new(120, 0); // 设置貌似没有效果啊,官方解答目前不支持
pool.set_conn_max_lifetime(Option::from(five_seconds)).await;
return rb;
}
数据库连接确实只有3个了。但是过段时间后,还是会出现连接不上的情况。
from axum-admin.
经过测试,确实是超过数据库连接池的数之后,访问正常了。
我设置的池最大连接数是3,当我第四次访问的时候,就可以查询了。
from axum-admin.
from axum-admin.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axum-admin.