]> Untitled Git - lemmy.git/blob - server/query_testing/api_benchmark.sh
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / server / query_testing / api_benchmark.sh
1 #!/bin/bash
2 set -e
3
4 # By default, this script runs against `http://127.0.0.1:8536`, but you can pass a different Lemmy instance,
5 # eg `./api_benchmark.sh "https://example.com"`.
6 DOMAIN=${1:-"http://127.0.0.1:8536"}
7
8 declare -a arr=(
9 "/api/v1/site"
10 "/api/v1/categories"
11 "/api/v1/modlog"
12 "/api/v1/search?q=test&type_=Posts&sort=Hot"
13 "/api/v1/community"
14 "/api/v1/community/list?sort=Hot"
15 "/api/v1/post/list?sort=Hot&type_=All"
16 )
17
18 ## check if ab installed
19 if ! [ -x "$(command -v ab)" ]; then
20   echo 'Error: ab (Apache Bench) is not installed. https://httpd.apache.org/docs/2.4/programs/ab.html' >&2
21   exit 1
22 fi
23
24 ## now loop through the above array
25 for path in "${arr[@]}"
26 do
27   URL="$DOMAIN$path"
28   printf "\n\n\n"
29   echo "testing $URL"
30   curl --show-error --fail --silent "$URL" >/dev/null
31   ab -c 64 -t 10 "$URL" > out.abtest
32   grep "Server Hostname:" out.abtest
33   grep "Document Path:" out.abtest
34   grep "Requests per second" out.abtest
35   grep "(mean, across all concurrent requests)" out.abtest
36   grep "Transfer rate:" out.abtest
37   echo "---"
38 done
39
40 rm *.abtest