mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
Fix api_benchmark.sh and add run_and_benchmark.sh
This commit is contained in:
parent
ddc32b2425
commit
b4528e5b85
4 changed files with 47 additions and 10 deletions
|
@ -57,6 +57,28 @@ pub struct RateLimitConfig {
|
||||||
pub search_per_second: i32,
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
struct RateLimit {
|
struct RateLimit {
|
||||||
pub rate_limiter: RateLimitStorage,
|
pub rate_limiter: RateLimitStorage,
|
||||||
|
|
|
@ -6,13 +6,12 @@ set -e
|
||||||
DOMAIN=${1:-"http://127.0.0.1:8536"}
|
DOMAIN=${1:-"http://127.0.0.1:8536"}
|
||||||
|
|
||||||
declare -a arr=(
|
declare -a arr=(
|
||||||
"/api/v1/site"
|
"/api/v3/site"
|
||||||
"/api/v1/categories"
|
"/api/v3/modlog"
|
||||||
"/api/v1/modlog"
|
"/api/v3/search?q=test&type_=Posts&sort=Hot"
|
||||||
"/api/v1/search?q=test&type_=Posts&sort=Hot"
|
"/api/v3/community/list?sort=Hot"
|
||||||
"/api/v1/community"
|
"/api/v3/federated_instances"
|
||||||
"/api/v1/community/list?sort=Hot"
|
"/api/v3/post/list?sort=Hot&type_=All"
|
||||||
"/api/v1/post/list?sort=Hot&type_=All"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
## check if ab installed
|
## check if ab installed
|
||||||
|
|
13
scripts/query_testing/run_and_benchmark.sh
Executable file
13
scripts/query_testing/run_and_benchmark.sh
Executable 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 $!
|
|
@ -27,7 +27,7 @@ use lemmy_db_schema::{
|
||||||
use lemmy_routes::{feeds, images, nodeinfo, webfinger};
|
use lemmy_routes::{feeds, images, nodeinfo, webfinger};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
error::LemmyError,
|
error::LemmyError,
|
||||||
rate_limit::RateLimitCell,
|
rate_limit::{RateLimitCell, RateLimitConfig},
|
||||||
settings::{structs::Settings, SETTINGS},
|
settings::{structs::Settings, SETTINGS},
|
||||||
};
|
};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
@ -94,8 +94,11 @@ pub async fn start_lemmy_server() -> Result<(), LemmyError> {
|
||||||
check_private_instance_and_federation_enabled(&local_site)?;
|
check_private_instance_and_federation_enabled(&local_site)?;
|
||||||
|
|
||||||
// Set up the rate limiter
|
// Set up the rate limiter
|
||||||
let rate_limit_config =
|
let rate_limit_config = if option_env!("LEMMY_BENCHMARK") == Some("1") {
|
||||||
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
|
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;
|
let rate_limit_cell = RateLimitCell::new(rate_limit_config).await;
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
|
|
Loading…
Reference in a new issue