chore: update benchmark script
This commit is contained in:
@@ -3,13 +3,19 @@
|
||||
## Benchmark
|
||||
|
||||
```shell
|
||||
./benchmark.sh
|
||||
$ ./benchmark.sh
|
||||
Semaphore initialized with 2666 slots.
|
||||
Setup...
|
||||
[+] Running 1/0
|
||||
✔ Container bit-app-1 Running 0.0s
|
||||
2024-05-20T16:39:53.818306Z INFO - micrate: No migrations to run. current version: 20240513130054
|
||||
Captured API Key: 4y2mblZDneZLcI-YywHGFA
|
||||
[+] Running 2/2
|
||||
✔ Network bit_default Created 0.0s
|
||||
✔ Container bit-app-1 Started 0.2s
|
||||
2024-07-12T18:41:20.962052Z INFO - micrate: Migrating db, current version: 0, target: 20240711224103
|
||||
2024-07-12T18:41:20.965729Z INFO - micrate: OK 20240512214223_create_links.sql
|
||||
2024-07-12T18:41:20.969198Z INFO - micrate: OK 20240512225208_add_slug_index_to_links.sql
|
||||
2024-07-12T18:41:20.973136Z INFO - micrate: OK 20240513115731_create_users.sql
|
||||
2024-07-12T18:41:20.975525Z INFO - micrate: OK 20240513130054_add_api_key_index_to_users.sql
|
||||
2024-07-12T18:41:20.979195Z INFO - micrate: OK 20240711224103_create_clicks.sql
|
||||
Captured API Key: Z01Qk4M5E0xhggZUCdQAPw
|
||||
Waiting for database to be ready...
|
||||
Creating 1000 short links...
|
||||
Created short link 100/1000
|
||||
@@ -24,11 +30,9 @@ Created short link 900/1000
|
||||
Created short link 1000/1000
|
||||
Accessing each link 10 times concurrently...
|
||||
****Results****
|
||||
Average Memory Usage: 11.00 MiB
|
||||
Average Response Time: 5.28 µs
|
||||
[+] Running 2/2
|
||||
✔ Container bit-app-1 Removed 10.2s
|
||||
✔ Network bit_default Removed
|
||||
Average Memory Usage: 16.36 MiB
|
||||
Average CPU Usage: 0%
|
||||
Average Response Time: 12.37 µs
|
||||
```
|
||||
|
||||
## Self-hosted
|
||||
|
||||
+11
-12
@@ -21,34 +21,33 @@ echo "Semaphore initialized with $max_concurrent_processes slots."
|
||||
|
||||
function get_resource_usage {
|
||||
while true; do
|
||||
docker stats --no-stream --format "{{.MemUsage}} {{.CPUPerc}}" bit >> resource_usage.txt
|
||||
docker stats --no-stream --format "table {{.MemUsage}} {{.CPUPerc}}" bit-app-1 | awk 'NR>1 {print "Memory:", $1, "CPU:", $2}' >> resource_usage.txt
|
||||
sleep $resource_usage_interval
|
||||
done
|
||||
}
|
||||
|
||||
function calculate_average_usage {
|
||||
total_mem=0
|
||||
total_cpu=0
|
||||
count=0
|
||||
|
||||
while read -r line; do
|
||||
mem=$(echo $line | awk '{print $1}')
|
||||
|
||||
# Convert memory to MiB if necessary
|
||||
if [[ $mem == *MiB ]]; then
|
||||
mem=$(echo $mem | sed 's/MiB//')
|
||||
elif [[ $mem == *GiB ]]; then
|
||||
mem=$(echo $mem | sed 's/GiB//')
|
||||
mem=$(echo "$mem * 1024" | bc)
|
||||
if echo $line | grep -q 'Memory'; then
|
||||
mem=$(echo $line | awk '{print $2}' | sed 's/MiB//')
|
||||
total_mem=$(echo "$total_mem + $mem" | bc)
|
||||
elif echo $line | grep -q 'CPU'; then
|
||||
cpu=$(echo $line | awk '{print $2}' | sed 's/%//')
|
||||
total_cpu=$(echo "$total_cpu + $cpu" | bc)
|
||||
fi
|
||||
|
||||
total_mem=$(echo "$total_mem + $mem" | bc)
|
||||
((count++))
|
||||
done < resource_usage.txt
|
||||
|
||||
avg_mem=$(echo "scale=2; $total_mem / $count" | bc)
|
||||
avg_mem=$(echo "scale=2; $total_mem / ($count / 2)" | bc) # Since there are 2 lines per interval
|
||||
avg_cpu=$(echo "scale=2; $total_cpu / ($count / 2)" | bc)
|
||||
rm resource_usage.txt
|
||||
|
||||
echo "Average Memory Usage: $avg_mem MiB"
|
||||
echo "Average CPU Usage: $avg_cpu%"
|
||||
}
|
||||
|
||||
function measure {
|
||||
|
||||
Reference in New Issue
Block a user