Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fwbrasil: fix warmup to avoid OOM #1649

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions participantes/fwbrasil/docker-compose.logs

This file was deleted.

11 changes: 8 additions & 3 deletions participantes/fwbrasil/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ services:
retries: 999

warmup:
image: grafana/k6:latest
image: registry.access.redhat.com/ubi9/ubi:9.3-1610
volumes:
- ./warmup/warmup.js:/opt/warmup.js
command: run /opt/warmup.js
- ./warmup/warmup.sh:/opt/warmup.sh
command: ./opt/warmup.sh
deploy:
resources:
limits:
cpus: "0.3"
memory: "10MB"
network_mode: host
depends_on:
api01:
Expand Down
2 changes: 0 additions & 2 deletions participantes/fwbrasil/testada

This file was deleted.

44 changes: 0 additions & 44 deletions participantes/fwbrasil/warmup/warmup.js

This file was deleted.

48 changes: 48 additions & 0 deletions participantes/fwbrasil/warmup/warmup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# URLs
transactionUrl1="http://localhost:8081/clientes/0/transacoes"
extratoUrl1="http://localhost:8081/clientes/0/extrato"
transactionUrl2="http://localhost:8082/clientes/0/transacoes"
extratoUrl2="http://localhost:8082/clientes/0/extrato"

# Headers
contentType="Content-Type: application/json"

# Initialize counter
counter=0
batchSize=10 # Control the concurrency level

# Debug message
echo "Starting warmup..."

# Start time
start=$SECONDS

# Loop for approximately 10 seconds
while [ $(($SECONDS - $start)) -lt 10 ]; do
activeJobs=$(jobs -p | wc -l)
if [ "$activeJobs" -lt "$batchSize" ]; then
# Increment counter
((counter++))

# Alternating transaction type for each iteration
transactionType=$([ $(($counter % 2)) -eq 0 ] && echo "c" || echo "d")

payload="{\"valor\": 1, \"tipo\": \"$transactionType\", \"descricao\": \"warmup\"}"

# Execute curl commands in parallel & silently
curl -s -X POST -H "$contentType" -d "$payload" "$transactionUrl1" --max-time 1 > /dev/null 2>&1 &
curl -s -X POST -H "$contentType" -d "$payload" "$transactionUrl2" --max-time 1 > /dev/null 2>&1 &
curl -s -X GET "$extratoUrl1" --max-time 1 > /dev/null 2>&1 &
curl -s -X GET "$extratoUrl2" --max-time 1 > /dev/null 2>&1 &

if [ $(($counter % 100)) -eq 0 ]; then
echo "Executed $counter requests..."
fi
fi
done

wait # Wait for all background jobs to finish

echo "Warmup completed. Total requests: $counter"