Skip to content

Commit

Permalink
Add sync profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil committed Feb 15, 2025
1 parent 3ec8418 commit b4e91bd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,15 @@ estimate-fee-heap: juno-cached ## Heap profile estimateFee
estimate-fee-block: juno-cached ## Goroutine blocking profile estimateFee
./scripts/profile_juno.sh block 60 scripts/payload/estimateFee.json sepolia-integration estimateFee_block.out ./p2p-dbs/sepolia-integration_node
go tool pprof -http=:3005 estimateFee_block.out

sync-profile: juno-cached ## Goroutine blocking profile estimateFee
./scripts/profile_juno.sh profile 60 none sepolia sync-profile.out ""
go tool pprof -http=:3006 sync-profile.out

sync-heap: juno-cached ## Goroutine blocking profile estimateFee
./scripts/profile_juno.sh heap 60 none sepolia sync-heap.out ""
go tool pprof -http=:3007 sync-heap.out

sync-block: juno-cached ## Goroutine blocking profile estimateFee
./scripts/profile_juno.sh block 60 none sepolia sync-block.out ""
go tool pprof -http=:3008 sync-block.out
65 changes: 34 additions & 31 deletions scripts/profile_juno.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ JUNO_ARGS="--network=$NETWORK \
--pprof-port "$PPROF_PORT" \
--disable-l1-verification"

# Ensure the request file exists
if [ ! -f "$REQUEST_FILE" ]; then
# Ensure the request file exists if not set to "none"
if [ "$REQUEST_FILE" != "none" ] && [ ! -f "$REQUEST_FILE" ]; then
echo "Error: Request file '$REQUEST_FILE' not found."
exit 1
fi

REQUEST_PAYLOAD=$(cat "$REQUEST_FILE")
if [ "$REQUEST_FILE" != "none" ]; then
REQUEST_PAYLOAD=$(cat "$REQUEST_FILE")
fi

echo "Using profiling duration: $PROFILE_DURATION seconds"
echo "Using request file: $REQUEST_FILE"
Expand All @@ -50,17 +52,16 @@ echo "Using request file: $REQUEST_FILE"
echo "Starting Juno..."
tmux new-session -d -s juno_session "bash -c '$JUNO_BINARY $JUNO_ARGS > juno.log 2>&1'"


# 2. Wait for Juno to be ready
echo "Waiting for Juno to start..."
MAX_WAIT=60
WAIT_TIME=0
while ! curl --silent --fail --location 'http://localhost:6060' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc":"2.0",
"method":"juno_version",
"id":1
"jsonrpc":"2.0",
"method":"juno_version",
"id":1
}'; do
if ! tmux has-session -t juno_session 2>/dev/null; then
echo "Error: Juno crashed during startup."
Expand All @@ -81,35 +82,37 @@ echo "Juno is up and running."
echo "Capturing profile for $PROFILE_DURATION seconds..."
curl -o $OUTPUT_FILE "http://localhost:$PPROF_PORT/debug/pprof/$PROFILE?seconds=$PROFILE_DURATION" &

# 4. Send requests and count responses
echo "Sending requests for $PROFILE_DURATION seconds..."
END_TIME=$((SECONDS + PROFILE_DURATION))
TOTAL_REQUESTS=0
SUCCESSFUL_REQUESTS=0

while [ $SECONDS -lt $END_TIME ]; do
RESPONSE=$(curl --silent --location "http://localhost:$JUNO_PORT" \
--header "Content-Type: application/json" \
--data "$REQUEST_PAYLOAD")

((TOTAL_REQUESTS++))

# Check if response contains a result field
if echo "$RESPONSE" | jq -e '.result' > /dev/null 2>&1; then
((SUCCESSFUL_REQUESTS++))
else
echo "Error in response: $RESPONSE"
fi
done
if [ "$REQUEST_FILE" != "none" ]; then
# 4. Send requests and count responses
echo "Sending requests for $PROFILE_DURATION seconds..."
END_TIME=$((SECONDS + PROFILE_DURATION))
TOTAL_REQUESTS=0
SUCCESSFUL_REQUESTS=0

while [ $SECONDS -lt $END_TIME ]; do
RESPONSE=$(curl --silent --location "http://localhost:$JUNO_PORT" \
--header "Content-Type: application/json" \
--data "$REQUEST_PAYLOAD")

((TOTAL_REQUESTS++))

# Check if response contains a result field
if echo "$RESPONSE" | jq -e '.result' > /dev/null 2>&1; then
((SUCCESSFUL_REQUESTS++))
else
echo "Error in response: $RESPONSE"
fi
done

# Print request statistics
echo "Total requests sent: $TOTAL_REQUESTS"
echo "Successful requests: $SUCCESSFUL_REQUESTS"
fi

# Wait for profiling and requests to complete
wait
echo "CPU profile saved to trace.out"

# Print request statistics
echo "Total requests sent: $TOTAL_REQUESTS"
echo "Successful requests: $SUCCESSFUL_REQUESTS"

# 5. Stop Juno
echo "Stopping Juno..."
tmux kill-session -t juno_session
Expand Down

0 comments on commit b4e91bd

Please sign in to comment.