Skip to content

Commit

Permalink
Improve io_uring performance
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexclique committed Jan 21, 2024
1 parent 282996d commit 8bfd624
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Cargo.lock
.idea/
target
examples/target
*.json
2 changes: 1 addition & 1 deletion src/syscore/linux/epoll/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::sys::epoll::*;
use futures::channel::oneshot;
use lever::prelude::*;
use pin_utils::unsafe_pinned;
use ahash::HashMap;
use ahash::{HashMap, HashMapExt};
use std::future::Future;
use std::io::{self, Read, Write};
use std::mem::MaybeUninit;
Expand Down
17 changes: 10 additions & 7 deletions src/syscore/linux/iouring/iouring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ macro_rules! syscall {
///////////////////
///////////////////

use crate::Proactor;
use socket2::SockAddr;
use std::mem;
use std::os::unix::net::SocketAddr as UnixSocketAddr;
use std::sync::{atomic, Mutex};
use rustix_uring::{CompletionQueue, IoUring, SubmissionQueue, Submitter, squeue::Entry as SQEntry, cqueue::Entry as CQEntry};

fn max_len() -> usize {
Expand Down Expand Up @@ -136,7 +134,7 @@ pub(crate) fn shim_to_af_unix(sockaddr: &SockAddr) -> io::Result<UnixSocketAddr>
///////////////////

const MANUAL_TIMEOUT: u64 = -2 as _;
const QUEUE_LEN: u32 = 1 << 10;
const QUEUE_LEN: u32 = 1 << 15;

pub struct SysProactor {
sq: TTas<SubmissionQueue<'static>>,
Expand All @@ -159,12 +157,17 @@ impl SysProactor {
pub(crate) fn new() -> io::Result<SysProactor> {
unsafe {
let ring = IoUring::builder()
.setup_sqpoll(2)

// .setup_coop_taskrun()
// .setup_taskrun_flag()
.build(QUEUE_LEN)
.expect("nuclei: uring can't be initialized");

IO_URING = Some(ring);

let (submitter, sq, cq) = IO_URING.as_mut().unwrap().split();
submitter.register_iowq_max_workers(&mut [16, 16])?;

Ok(SysProactor {
sq: TTas::new(sq),
Expand Down Expand Up @@ -205,10 +208,10 @@ impl SysProactor {
}

pub(crate) fn wake(&self) -> io::Result<()> {
if let (Some(mut sq), Some(mut cq)) = (self.sq.try_lock(), self.cq.try_lock()) {
sq.sync();
cq.sync();
}
// if let (Some(mut sq), Some(mut cq)) = (self.sq.try_lock(), self.cq.try_lock()) {
// sq.sync();
// cq.sync();
// }
Ok(())
}

Expand Down

0 comments on commit 8bfd624

Please sign in to comment.