Skip to content

Commit

Permalink
fwbrasil: fix warmup to avoid OOM (zanfranceschi#1649)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil authored Mar 11, 2024
1 parent 93f6054 commit c1d3726
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 63 deletions.
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"

0 comments on commit c1d3726

Please sign in to comment.