Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add concurrency limit, fix ttl and tti config #10

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub struct StaticConfig {
multipart_put_threshold: u64,
multipart_get_threshold: u64,
multipart_get_part_size: u64,
concurrency_limit: u32,
}

impl Default for StaticConfig {
Expand All @@ -203,7 +204,8 @@ impl Default for StaticConfig {
cache_tti_secs: 5 * 60,
multipart_put_threshold: 8 * 1024 * 1024,
multipart_get_threshold: 8 * 1024 * 1024,
multipart_get_part_size: 8 * 1024 * 1024
multipart_get_part_size: 8 * 1024 * 1024,
concurrency_limit: 512
}
}
}
Expand Down Expand Up @@ -322,11 +324,15 @@ pub extern "C" fn start(
.expect("failed to create tokio runtime")
).expect("runtime was set before");

let cache = moka::future::CacheBuilder::new(static_config().cache_capacity)
.time_to_live(Duration::from_secs(static_config().cache_ttl_secs))
.time_to_idle(Duration::from_secs(static_config().cache_tti_secs))
.build();

let mut cache_builder = moka::future::CacheBuilder::new(static_config().cache_capacity);
if static_config().cache_ttl_secs != 0 {
cache_builder = cache_builder.time_to_live(Duration::from_secs(static_config().cache_ttl_secs));
}
if static_config().cache_tti_secs != 0 {
cache_builder = cache_builder.time_to_idle(Duration::from_secs(static_config().cache_tti_secs));
}
let cache = cache_builder.build();

CLIENTS.set(cache)
.expect("cache was set before");

Expand Down Expand Up @@ -452,7 +458,7 @@ pub extern "C" fn start(
}
}
}
}).buffer_unordered(512).for_each(|_| async {}).await;
}).buffer_unordered(static_config().concurrency_limit as usize).for_each(|_| async {}).await;
});
CResult::Ok
}
Expand Down