first commit
This commit is contained in:
commit
01d7cb1a80
34 files changed
+5723
No files matched your search
@@ -0,0 +1,82 @@
|
||||
#!/bin/bash
|
||||
# ─────────────────────────────────────────────────────────
|
||||
# benchmark.sh — Testa latência com e sem eBPF sockmap
|
||||
#
|
||||
# Execute: bash scripts/benchmark.sh
|
||||
# ─────────────────────────────────────────────────────────
|
||||
set -euo pipefail
|
||||
|
||||
BLUE='\033[0;34m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
URL="http://localhost:8080/benchmark"
|
||||
CURL_OPTS="-s --connect-timeout 5 --max-time 30"
|
||||
|
||||
echo ""
|
||||
echo -e "${BLUE}═══════════════════════════════════════════════${NC}"
|
||||
echo -e "${BLUE} Benchmark de Latência — eBPF Sockmap${NC}"
|
||||
echo -e "${BLUE}═══════════════════════════════════════════════${NC}"
|
||||
echo ""
|
||||
|
||||
# Verifica se a aplicação está rodando
|
||||
if ! curl $CURL_OPTS "$URL" > /dev/null 2>&1; then
|
||||
echo "❌ Aplicação não está respondendo em $URL"
|
||||
echo " Execute 'make docker-up' primeiro."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${YELLOW}Teste 1: Benchmark via endpoint /benchmark${NC}"
|
||||
echo "(Faz 100 queries SELECT 1 em cada banco de dados)"
|
||||
echo ""
|
||||
curl $CURL_OPTS "$URL" | python3 -m json.tool 2>/dev/null || curl $CURL_OPTS "$URL"
|
||||
|
||||
echo ""
|
||||
echo -e "${YELLOW}Teste 2: Latência HTTP (nginx → node.js)${NC}"
|
||||
echo "(10 requisições sequenciais para /health)"
|
||||
echo ""
|
||||
|
||||
TOTAL=0
|
||||
for i in $(seq 1 10); do
|
||||
TIME=$(curl $CURL_OPTS -o /dev/null -w "%{time_total}" http://localhost:8080/health)
|
||||
TIME_MS=$(echo "$TIME * 1000" | bc)
|
||||
printf " Requisição %2d: %8.3f ms\n" "$i" "$TIME_MS"
|
||||
TOTAL=$(echo "$TOTAL + $TIME_MS" | bc)
|
||||
done
|
||||
|
||||
AVG=$(echo "scale=3; $TOTAL / 10" | bc)
|
||||
echo ""
|
||||
echo -e "${GREEN} Média: ${AVG} ms${NC}"
|
||||
|
||||
echo ""
|
||||
echo -e "${YELLOW}Teste 3: Throughput (requisições por segundo)${NC}"
|
||||
echo "(100 requisições para /health)"
|
||||
echo ""
|
||||
|
||||
if command -v ab &>/dev/null; then
|
||||
ab -n 100 -c 10 http://localhost:8080/health 2>/dev/null | grep -E "Requests per second|Time per request|Transfer rate"
|
||||
elif command -v wrk &>/dev/null; then
|
||||
wrk -t2 -c10 -d5s http://localhost:8080/health
|
||||
else
|
||||
START=$(date +%s%N)
|
||||
for i in $(seq 1 100); do
|
||||
curl $CURL_OPTS -o /dev/null http://localhost:8080/health &
|
||||
done
|
||||
wait
|
||||
END=$(date +%s%N)
|
||||
ELAPSED=$(echo "scale=3; ($END - $START) / 1000000" | bc)
|
||||
RPS=$(echo "scale=1; 100 / ($ELAPSED / 1000)" | bc)
|
||||
echo " 100 requisições em ${ELAPSED} ms"
|
||||
echo -e "${GREEN} ~${RPS} requisições/segundo${NC}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "─────────────────────────────────────────────"
|
||||
echo "💡 Dica: Execute este benchmark antes e depois do 'make load'"
|
||||
echo " para comparar a performance com e sem eBPF sockmap!"
|
||||
echo ""
|
||||
echo " SEM sockmap: make unload → bash scripts/benchmark.sh"
|
||||
echo " COM sockmap: make load → bash scripts/benchmark.sh"
|
||||
echo "─────────────────────────────────────────────"
|
||||
echo ""
|
||||
Reference in new issue
Block a user