Skip to content

Commit

Permalink
Filter syscsalls better, introduce record mode for perfstat, remove m…
Browse files Browse the repository at this point in the history
…isleading comment
  • Loading branch information
fasterthanlime committed Aug 30, 2024
1 parent ea17212 commit 635d065
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 34 deletions.
59 changes: 31 additions & 28 deletions crates/buffet/src/net/net_uring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,34 +175,37 @@ impl WriteOwned for TcpWriteHalf {

// TODO: implement writev

// async fn writev_owned(&mut self, list: &PieceList) -> std::io::Result<usize>
// { let mut iovecs: Vec<iovec> = vec![];
// for piece in list.pieces.iter() {
// let iov = iovec {
// iov_base: piece.as_ref().as_ptr() as *mut libc::c_void,
// iov_len: piece.len(),
// };
// iovecs.push(iov);
// }
// let iovecs = iovecs.into_boxed_slice();
// let iov_cnt = iovecs.len();
// // FIXME: don't leak, duh
// let iovecs = Box::leak(iovecs);

// let sqe = Writev::new(
// io_uring::types::Fd(self.0.fd),
// iovecs.as_ptr() as *const _,
// iov_cnt as u32,
// )
// .build();

// let cqe = get_ring().push(sqe).await;
// let ret = match cqe.error_for_errno() {
// Ok(ret) => ret,
// Err(e) => return Err(std::io::Error::from(e)),
// };
// Ok(ret as usize)
// }
async fn writev_owned(&mut self, list: &crate::PieceList) -> std::io::Result<usize> {
use libc::iovec;
use io_uring::opcode::Writev;

let mut iovecs: Vec<iovec> = vec![];
for piece in list.pieces.iter() {
let iov = iovec {
iov_base: piece.as_ref().as_ptr() as *mut libc::c_void,
iov_len: piece.len(),
};
iovecs.push(iov);
}
let iovecs = iovecs.into_boxed_slice();
let iov_cnt = iovecs.len();
// FIXME: don't leak, duh
let iovecs = Box::leak(iovecs);

let sqe = Writev::new(
io_uring::types::Fd(self.0.fd),
iovecs.as_ptr() as *const _,
iov_cnt as u32,
)
.build();

let cqe = get_ring().push(sqe).await;
let ret = match cqe.error_for_errno() {
Ok(ret) => ret,
Err(e) => return Err(std::io::Error::from(e)),
};
Ok(ret as usize)
}

async fn shutdown(&mut self) -> std::io::Result<()> {
tracing::debug!("requesting shutdown");
Expand Down
1 change: 0 additions & 1 deletion crates/loona/src/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ where
let mut goaway_err: Option<H2ConnectionError> = None;

{
// read frames and send them into an mpsc buffer of size 1
let (tx, rx) = mpsc::channel::<(Frame, Roll)>(32);

// store max frame size setting as an atomic so we can share it across tasks
Expand Down
27 changes: 25 additions & 2 deletions scripts/perfstat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trap 'kill -TERM -$$' EXIT
mkdir -p /tmp/loona-perfstat

# Kill older processes
for pidfile in /tmp/loona-perfstat/{hyper,loona}.PID; do
for pidfile in /tmp/loona-perfstat/*.PID; do
if [ -f "$pidfile" ]; then
pid=$(cat "$pidfile")
if [ "$pid" != "$$" ]; then
Expand Down Expand Up @@ -97,11 +97,34 @@ CONNS="${CONNS:-40}"
STREAMS="${STREAMS:-8}"
NUM_REQUESTS="${NUM_REQUESTS:-100}"

# Set MODE to 'stat' if not specified
MODE=${MODE:-stat}

if [[ "$MODE" == "record" ]]; then
PERF_CMD="perf record -F 99 -e $PERF_EVENTS -p"
elif [[ "$MODE" == "stat" ]]; then
PERF_CMD="perf stat -e $PERF_EVENTS -p"
else
echo "Error: Unknown MODE '$MODE'"
exit 1
fi

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"
perf stat -e "$PERF_EVENTS" -p "$PID" -- ssh brat "$H2LOAD" "${H2LOAD_ARGS[@]}" --rps "$RPS" -c "$CONNS" -m "$STREAMS" -n "$NUM_REQUESTS" "${ADDR}${ENDPOINT}"
remote_command=("$H2LOAD" "${H2LOAD_ARGS[@]}" --rps "$RPS" -c "$CONNS" -m "$STREAMS" -n "$NUM_REQUESTS" "${ADDR}${ENDPOINT}")

if [[ "$MODE" == "record" ]]; then
samply record -p "$PID" &
SAMPLY_PID=$!
echo $SAMPLY_PID > /tmp/loona-perfstat/samply.PID
ssh brat "${remote_command[@]}"
kill -INT $SAMPLY_PID
wait $SAMPLY_PID
else
perf stat -e "$PERF_EVENTS" -p "$PID" -- ssh brat "${remote_command[@]}"
fi
done
5 changes: 2 additions & 3 deletions scripts/syscalls
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
syscalls:sys_enter_accept*
syscalls:sys_enter_write*
syscalls:sys_enter_brk
syscalls:sys_enter_write
syscalls:sys_enter_writev
syscalls:sys_enter_epoll_wait
syscalls:sys_enter_io_uring_enter

0 comments on commit 635d065

Please sign in to comment.