diff --git a/crates/utils/src/rate_limit/mod.rs b/crates/utils/src/rate_limit/mod.rs index 0fbda430e..d27867933 100644 --- a/crates/utils/src/rate_limit/mod.rs +++ b/crates/utils/src/rate_limit/mod.rs @@ -57,6 +57,28 @@ pub struct RateLimitConfig { pub search_per_second: i32, } +impl RateLimitConfig { + pub fn benchmark_mode() -> Self { + let max = 1000000; + let interval = 1; + + RateLimitConfig { + message: max, + post: max, + register: max, + image: max, + comment: max, + search: max, + message_per_second: interval, + post_per_second: interval, + register_per_second: interval, + image_per_second: interval, + comment_per_second: interval, + search_per_second: interval, + } + } +} + #[derive(Debug, Clone)] struct RateLimit { pub rate_limiter: RateLimitStorage, diff --git a/scripts/query_testing/api_benchmark.sh b/scripts/query_testing/api_benchmark.sh index 4c1ee9e1f..6ad4e7fde 100755 --- a/scripts/query_testing/api_benchmark.sh +++ b/scripts/query_testing/api_benchmark.sh @@ -6,13 +6,12 @@ set -e DOMAIN=${1:-"http://127.0.0.1:8536"} declare -a arr=( -"/api/v1/site" -"/api/v1/categories" -"/api/v1/modlog" -"/api/v1/search?q=test&type_=Posts&sort=Hot" -"/api/v1/community" -"/api/v1/community/list?sort=Hot" -"/api/v1/post/list?sort=Hot&type_=All" +"/api/v3/site" +"/api/v3/modlog" +"/api/v3/search?q=test&type_=Posts&sort=Hot" +"/api/v3/community/list?sort=Hot" +"/api/v3/federated_instances" +"/api/v3/post/list?sort=Hot&type_=All" ) ## check if ab installed diff --git a/scripts/query_testing/run_and_benchmark.sh b/scripts/query_testing/run_and_benchmark.sh new file mode 100755 index 000000000..ac0a05939 --- /dev/null +++ b/scripts/query_testing/run_and_benchmark.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +LEMMY_BENCHMARK=1 cargo build --release + +RUST_LOG=error target/release/lemmy_server & + +# Wait for port to be opened by server +sleep 3 + +scripts/query_testing/api_benchmark.sh + +kill $! diff --git a/src/lib.rs b/src/lib.rs index 0136c60d9..113fdf18a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,7 @@ use lemmy_db_schema::{ use lemmy_routes::{feeds, images, nodeinfo, webfinger}; use lemmy_utils::{ error::LemmyError, - rate_limit::RateLimitCell, + rate_limit::{RateLimitCell, RateLimitConfig}, settings::{structs::Settings, SETTINGS}, }; use reqwest::Client; @@ -94,8 +94,11 @@ pub async fn start_lemmy_server() -> Result<(), LemmyError> { check_private_instance_and_federation_enabled(&local_site)?; // Set up the rate limiter - let rate_limit_config = - local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit); + let rate_limit_config = if option_env!("LEMMY_BENCHMARK") == Some("1") { + RateLimitConfig::benchmark_mode() + } else { + local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit) + }; let rate_limit_cell = RateLimitCell::new(rate_limit_config).await; println!(