diff --git a/crates/buffet/src/net/net_uring.rs b/crates/buffet/src/net/net_uring.rs index aa7e8acf..3f54e7c3 100644 --- a/crates/buffet/src/net/net_uring.rs +++ b/crates/buffet/src/net/net_uring.rs @@ -175,34 +175,37 @@ impl WriteOwned for TcpWriteHalf { // TODO: implement writev - // async fn writev_owned(&mut self, list: &PieceList) -> std::io::Result - // { let mut iovecs: Vec = 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 { + use libc::iovec; + use io_uring::opcode::Writev; + + let mut iovecs: Vec = 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"); diff --git a/crates/loona/src/h2/server.rs b/crates/loona/src/h2/server.rs index 66a1a691..d764d9e1 100644 --- a/crates/loona/src/h2/server.rs +++ b/crates/loona/src/h2/server.rs @@ -187,7 +187,6 @@ where let mut goaway_err: Option = 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 diff --git a/scripts/perfstat.sh b/scripts/perfstat.sh index 02a40850..779b90c6 100755 --- a/scripts/perfstat.sh +++ b/scripts/perfstat.sh @@ -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 @@ -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 diff --git a/scripts/syscalls b/scripts/syscalls index 573bb944..81e6fc06 100644 --- a/scripts/syscalls +++ b/scripts/syscalls @@ -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