Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a bug? #71

Closed
rustMyGod opened this issue Jan 24, 2022 · 4 comments
Closed

a bug? #71

rustMyGod opened this issue Jan 24, 2022 · 4 comments

Comments

@rustMyGod
Copy link

hello
I want to test performance on mmap,BIO,AIO,and iouring(by tokio-uring) by write 1KB data to 1G files 1024 times . then i write the code bellow.when program running i find something unexpected.

  1. too many threads created and destroyed,maybe 20+ thousands.(my test server is 8c16g,5.15.10-1.el7.elrepo.x86_64)
  2. some file succeed ,some not,no exception throwed,program is still alive,but no worker threads work now .many file are only 794MB and not growing, the others are 1024MB. bug here?
  3. the writing speed is much more slowly than tranditional io(maybe all AIO model slowly the same).
use std::thread;
use std::time::Duration;
use std::time::Instant;
use std::{path::PathBuf, sync::Arc};
use tokio::sync::mpsc;
use tokio::sync::mpsc::UnboundedSender;
use tokio::sync::Mutex;
use tokio::time::sleep;
use tokio_uring::fs::{File, OpenOptions};
fn main() {
    tokio_uring::start(async {
        let (tx, mut rx) = mpsc::unbounded_channel::<()>();
        let txx = Arc::new(tx);
        let count = Instant::now();
        for i in 0..1024 {
            let t = txx.clone();
            tokio_uring::spawn(create(i, t));
        }

        drop(txx);
        while let Some(_) = rx.recv().await {}
        println!("{:?}", count.elapsed());
    });
}

async fn create(idx: i32, tx: Arc<UnboundedSender<()>>) {
    let path = PathBuf::from(r"/data2/testuring/".to_owned() + idx.to_string().as_str());
    let mut file = OpenOptions::new()
        .read(true)
        .write(true)
        .create(true)
        .open(&path)
        .await
        .unwrap();
    // file.set_len(1024 * 1024 * 1024).await.unwrap();
    println!("create file={} {:?}", idx, thread::current().id());
    let x=b"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
    let y=&x[..];
    let size_1_g = 1024 * 1024 * 1024;
    let mut idx = 0;
    while idx < size_1_g {
        let (_, _) = file.write_at(y, idx).await;
        idx = idx + 1024;
    }
    println!("end file={:?} {:?}", &path, thread::current().id());
    file.close().await.unwrap();
    drop(tx);
}
@rustMyGod
Copy link
Author

I watched 20+threads created and destoryed by htop.

@rustMyGod
Copy link
Author

20+thousands threads

@Noah-Kennedy
Copy link
Contributor

I am unable to reproduce. I ran your code and only saw 33 threads.

@Noah-Kennedy
Copy link
Contributor

Also, as far as perf, this is going to be slow. You are making a lot of tiny writes sequentially.

@tokio-rs tokio-rs locked and limited conversation to collaborators Jan 26, 2022
@Noah-Kennedy Noah-Kennedy converted this issue into discussion #72 Jan 26, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants