Skip to content

Commit

Permalink
feat: added relay profiling and improved result readability
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-baldo committed Mar 21, 2024
1 parent 303bef3 commit 3aebc7e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 7 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ inherits = "test"
debug = 1
strip = "none"
inherits = "release"
force-frame-pointers = "yes"

# compromise: minimal optimization on selected dependencies
# to reduce cli bootstrap time by ~5x
Expand Down
1 change: 1 addition & 0 deletions tools/profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This directory contains tools for profiling ockam.
Two scenarios for performance profiling:
- `portal.perf` - local portal, within one node
- `portal_two_nodes.perf` - two nodes, one inlet and outlet
- `relay_port.perf` - one node, one inlet and outlet passing through a relay

And one scenario for heap profiling:
- `portal.valgrind.dhat` - local portal, within one node
Expand Down
7 changes: 5 additions & 2 deletions tools/profile/portal.perf
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ fi

set -e

cargo build --profile profiling -p ockam_command
if [ -z "${OCKAM}" ]; then
RUSTFLAGS="-C force-frame-pointers=yes" cargo build --profile profiling -p ockam_command
OCKAM=target/profiling/ockam
fi

OCKAM=target/profiling/ockam
"${OCKAM}" node delete portal -y >/dev/null 2>&1 || true
export OCKAM_LOG_LEVEL=info
perf record --call-graph dwarf -F 99 --output /tmp/ockam.perf -- "${OCKAM}" node create portal -f &
perf_pid=$!
Expand Down
7 changes: 5 additions & 2 deletions tools/profile/portal.valgrind.dhat
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ fi

set -e

cargo build --profile profiling -p ockam_command
if [ -z "${OCKAM}" ]; then
RUSTFLAGS="-C force-frame-pointers=yes" cargo build --profile profiling -p ockam_command
OCKAM=target/profiling/ockam
fi

OCKAM=target/profiling/ockam
"${OCKAM}" node delete portal -y >/dev/null 2>&1 || true
export OCKAM_LOG_LEVEL=info
valgrind --tool=dhat --trace-children=yes --dhat-out-file=/tmp/ockam.valgrind.dhat -- "${OCKAM}" node create portal

Expand Down
7 changes: 5 additions & 2 deletions tools/profile/portal_two_nodes.perf
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ fi

set -e

cargo build --profile profiling -p ockam_command
if [ -z "${OCKAM}" ]; then
RUSTFLAGS="-C force-frame-pointers=yes" cargo build --profile profiling -p ockam_command
OCKAM=target/profiling/ockam
fi

OCKAM=target/profiling/ockam
"${OCKAM}" node delete portal -y >/dev/null 2>&1 || true
export OCKAM_LOG_LEVEL=info
perf record --call-graph dwarf -F 99 --output /tmp/ockam.inlet.perf -- "${OCKAM}" node create inlet -f &
perf record --call-graph dwarf -F 99 --output /tmp/ockam.outlet.perf -- "${OCKAM}" node create outlet -f &
Expand Down
46 changes: 46 additions & 0 deletions tools/profile/relay_portal.perf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

if ! [ -x "$(command -v iperf3)" ]; then
echo 'Error: iperf3 is not installed.' >&2
exit 1
fi

if ! [ -x "$(command -v perf)" ]; then
echo 'Error: perf is not installed. perf is linux-specific, see dtrace for macos.' >&2
exit 1
fi

set -e

if [ -z "${OCKAM}" ]; then
RUSTFLAGS="-C force-frame-pointers=yes" cargo build --profile profiling -p ockam_command
OCKAM=target/profiling/ockam
fi

"${OCKAM}" node delete portal -y >/dev/null 2>&1 || true
export OCKAM_LOG_LEVEL=info
perf record --call-graph dwarf -F 99 --output /tmp/ockam.perf -- "${OCKAM}" node create portal -f &
perf_pid=$!

sleep 1
"${OCKAM}" tcp-outlet create --to 5000 --at portal
"${OCKAM}" relay create --to portal
"${OCKAM}" tcp-inlet create --from 8000 --to /project/default/service/forward_to_default/secure/api/service/outlet --at portal

iperf3 --server --port 5000 --one-off &
iperf3_server_pid=$!

sleep 0.3 # wait for server to start
iperf3 --zerocopy --client 127.0.0.1 --port 8000 --time 60

kill ${iperf3_server_pid}
"${OCKAM}" node delete portal -y

echo "Waiting for perf to finish writing /tmp/ockam.perf..."
wait ${perf_pid}

echo "Converting perf file to firefox profiler format, could take up to few minutes..."
perf script -F +pid --input /tmp/ockam.perf > /tmp/ockam.perf.firefox

echo "You can use firefox web profiler to open /tmp/ockam.perf.firefox file."
echo "https://profiler.firefox.com/"

0 comments on commit 3aebc7e

Please sign in to comment.