Fix api_benchmark.sh and add run_and_benchmark.sh

This commit is contained in:
dullbananas 2023-06-13 19:45:50 +00:00
parent ddc32b2425
commit b4528e5b85
4 changed files with 47 additions and 10 deletions

View file

@ -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,

View file

@ -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

View file

@ -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 $!

View file

@ -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!(