Skip to content

Commit

Permalink
chore: increase sql conn acquire rate limits (#915)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
NathanFlurry committed Jun 19, 2024
1 parent dfe5f8b commit deca712
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ async fn crdb_from_env(_client_name: String) -> Result<Option<CrdbPool>, Error>
// Increase lifetime to mitigate: https://github.com/launchbadge/sqlx/issues/2854
//
// See max lifetime https://www.cockroachlabs.com/docs/stable/connection-pooling#set-the-maximum-lifetime-of-connections
.max_lifetime(Duration::from_secs(30 * 60))
.max_lifetime(Duration::from_secs(15 * 60))
// Remove connections after a while in order to reduce load
// on CRDB after bursts
.idle_timeout(Some(Duration::from_secs(3 * 60)))
Expand Down
8 changes: 4 additions & 4 deletions lib/pools/src/utils/sql_query_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ lazy_static::lazy_static! {
governor::clock::DefaultClock,
governor::middleware::NoOpMiddleware
> = governor::RateLimiter::direct(
// Limit how many connections can be created to the database
governor::Quota::per_second(std::num::NonZeroU32::new(10).unwrap())
// Allow creating at most 5 connections at the same time
.allow_burst(std::num::NonZeroU32::new(5).unwrap())
// Limit how fast the pool size can grow in order to encourage reusuing existing
// connections instead of opening new ones.
governor::Quota::per_minute(std::num::NonZeroU32::new(10 * 60).unwrap())
.allow_burst(std::num::NonZeroU32::new(500).unwrap())
);
}

Expand Down
4 changes: 2 additions & 2 deletions svc/pkg/cluster/standalone/default-update/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ pub async fn run_from_env(use_autoscaler: bool) -> GlobalResult<()> {
.into_iter()
.map(|(pool_type, pool)| {
let desired_count = match pool_type {
PoolType::Ats => Some(pool.desired_count),
PoolType::Job | PoolType::Gg => {
PoolType::Ats | PoolType::Gg => Some(pool.desired_count),
PoolType::Job => {
if use_autoscaler {
None
} else {
Expand Down

0 comments on commit deca712

Please sign in to comment.