Skip to content

Commit

Permalink
Fix up perfstat script
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Aug 30, 2024
1 parent 1d42579 commit ea17212
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
4 changes: 2 additions & 2 deletions crates/httpwg-loona/src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ pub(super) async fn handle_tls_conn(stream: TcpStream) -> b_x::Result<()> {
client_buf.put(&drained[..])?;

if is_h2 {
tracing::info!("Using HTTP/2");
tracing::debug!("Using HTTP/2");
h2::serve(stream.into_halves(), h2_conf, client_buf, Rc::new(driver)).await?;
} else {
tracing::info!("Using HTTP/1.1");
tracing::debug!("Using HTTP/1.1");
h1::serve(stream.into_halves(), h1_conf, client_buf, driver).await?;
}
Ok(())
Expand Down
64 changes: 45 additions & 19 deletions scripts/perfstat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@
# Change to the script's directory
cd "$(dirname "$0")"

# Create a new process group
set -m

# Set trap to kill the process group on script exit
trap 'kill -TERM -$$' EXIT

# Create directory if it doesn't exist
mkdir -p /tmp/loona-perfstat

# Kill older processes
for pidfile in /tmp/loona-perfstat/{hyper,loona}.PID; do
if [ -f "$pidfile" ]; then
pid=$(cat "$pidfile")
if [ "$pid" != "$$" ]; then
kill "$pid" 2>/dev/null || true
fi
rm -f "$pidfile"
fi
done

#PERF_EVENTS="cpu-clock,context-switches,cycles,instructions,branches,branch-misses,cache-references,cache-misses,page-faults,$(paste -sd ',' syscalls)"
PERF_EVENTS="cpu-clock,cycles,branch-misses,cache-misses,page-faults,$(paste -sd ',' syscalls)"

Expand All @@ -13,39 +33,39 @@ LOONA_DIR=~/bearcove/loona
# Build the servers
cargo build --release --manifest-path="$LOONA_DIR/Cargo.toml" -F tracing/release_max_level_info

# Create a new process group
set -m

# Set trap to kill the process group on script exit
trap 'kill -TERM -$$' EXIT

pkill -9 -f httpwg-hyper
pkill -9 -f httpwg-loona

# Set protocol, default to h2c
PROTO=${PROTO:-h2c}
export PROTO

OUR_PUBLIC_IP=$(curl -4 ifconfig.me)
if [[ "$PROTO" == "tls" ]]; then
HTTP_OR_HTTPS="https"
else
HTTP_OR_HTTPS="http"
fi

# Launch hyper server
ADDR=0.0.0.0 PORT=8001 "$LOONA_DIR/target/release/httpwg-hyper" &
HYPER_PID=$!
echo $HYPER_PID > /tmp/loona-perfstat/hyper.PID
echo "hyper PID: $HYPER_PID"
HYPER_ADDR="http://localhost:8001"

# Launch loona server
ADDR=0.0.0.0 PORT=8002 "$LOONA_DIR/target/release/httpwg-loona" &
LOONA_PID=$!
echo $LOONA_PID > /tmp/loona-perfstat/loona.PID
echo "loona PID: $LOONA_PID"
LOONA_ADDR="http://localhost:8002"

ENDPOINT="${ENDPOINT:-/repeat-4k-blocks/128}"
HYPER_ADDR="${HTTP_OR_HTTPS}://${OUR_PUBLIC_IP}:8001"
LOONA_ADDR="${HTTP_OR_HTTPS}://${OUR_PUBLIC_IP}:8002"

# Declare h2load args based on PROTO
declare -a H2LOAD_ARGS
if [[ "$PROTO" == "h1" ]]; then
H2LOAD_ARGS=()
echo "Error: h1 is not supported"
exit 1
elif [[ "$PROTO" == "h2c" ]]; then
H2LOAD_ARGS=(--h1)
H2LOAD_ARGS=()
elif [[ "$PROTO" == "tls" ]]; then
ALPN_LIST=${ALPN_LIST:-"h2,http/1.1"}
H2LOAD_ARGS=(--alpn-list="$ALPN_LIST")
Expand All @@ -69,13 +89,19 @@ if [[ -n "${SERVER:-}" ]]; then
fi
fi

H2LOAD="/nix/var/nix/profiles/default/bin/h2load"

ENDPOINT="${ENDPOINT:-/repeat-4k-blocks/128}"
RPS="${RPS:-2}"
CONNS="${CONNS:-40}"
STREAMS="${STREAMS:-8}"
NUM_REQUESTS="${NUM_REQUESTS:-100}"

echo -e "\033[1;34m📊 Benchmark parameters: RPS=$RPS, CONNS=$CONNS, STREAMS=$STREAMS, NUM_REQUESTS=$NUM_REQUESTS, ENDPOINT=$ENDPOINT\033[0m"

for server in "${!servers[@]}"; do
read -r PID ADDR <<< "${servers[$server]}"
echo -e "\033[1;36mLoona Git SHA: $(cd ~/bearcove/loona && git rev-parse --short HEAD)\033[0m"
echo -e "\033[1;33m🚀 Benchmarking \033[1;32m$(cat /proc/$PID/cmdline | tr '\0' ' ')\033[0m"
echo -e "\033[1;34m📊 Benchmark parameters: RPS=${RPS:-2}, CONNS=${CONNS:-40}, STREAMS=${STREAMS:-8}, NUM_REQUESTS=${NUM_REQUESTS:-100}, ENDPOINT=${ENDPOINT:-/stream-big-body}\033[0m"
perf stat -e "$PERF_EVENTS" -p "$PID" -- h2load "${H2LOAD_ARGS[@]}" --rps "${RPS:-2}" -c "${CONNS:-40}" -m "${STREAMS:-8}" -n "${NUM_REQUESTS:-100}" "${ADDR}${ENDPOINT}"
perf stat -e "$PERF_EVENTS" -p "$PID" -- ssh brat "$H2LOAD" "${H2LOAD_ARGS[@]}" --rps "$RPS" -c "$CONNS" -m "$STREAMS" -n "$NUM_REQUESTS" "${ADDR}${ENDPOINT}"
done

# Kill the servers
kill $HYPER_PID $LOONA_PID

0 comments on commit ea17212

Please sign in to comment.