Nothing, blocking threads = 8

This commit is contained in:
Igor Katson 2024-05-03 11:53:53 +01:00
parent 16a28a4d96
commit 122b22c2e5
2 changed files with 17 additions and 11 deletions

View file

@ -31,19 +31,25 @@ impl<U: StorageFactory + Clone> StorageFactory for SlowStorageFactory<U> {
fn init_storage(&self, info: &crate::ManagedTorrentInfo) -> anyhow::Result<Self::Storage> { fn init_storage(&self, info: &crate::ManagedTorrentInfo) -> anyhow::Result<Self::Storage> {
Ok(SlowStorage { Ok(SlowStorage {
underlying: self.underlying_factory.init_storage(info)?, underlying: self.underlying_factory.init_storage(info)?,
pwrite_all_bufread: Mutex::new( pwrite_all_bufread: Mutex::new(Box::new(
BufReader::new( BufReader::new(
File::open("/Users/igor/Downloads/rqbit-log-slow-disk.log-pwrite_all").unwrap(), File::open("/Users/igor/Downloads/rqbit-log-slow-disk.log-pwrite_all").unwrap(),
) )
.lines(), .lines()
), .map(|l| l.unwrap().parse().unwrap())
pread_exact_bufread: Mutex::new( .collect::<Vec<_>>()
.into_iter(),
)),
pread_exact_bufread: Mutex::new(Box::new(
BufReader::new( BufReader::new(
File::open("/Users/igor/Downloads/rqbit-log-slow-disk.log-pread_exact") File::open("/Users/igor/Downloads/rqbit-log-slow-disk.log-pread_exact")
.unwrap(), .unwrap(),
) )
.lines(), .lines()
), .map(|l| l.unwrap().parse().unwrap())
.collect::<Vec<_>>()
.into_iter(),
)),
}) })
} }
@ -58,13 +64,13 @@ impl<U: StorageFactory + Clone> StorageFactory for SlowStorageFactory<U> {
pub struct SlowStorage<U> { pub struct SlowStorage<U> {
underlying: U, underlying: U,
pwrite_all_bufread: Mutex<Lines<BufReader<File>>>, pwrite_all_bufread: Mutex<Box<dyn Iterator<Item = u64> + Send + Sync>>,
pread_exact_bufread: Mutex<Lines<BufReader<File>>>, pread_exact_bufread: Mutex<Box<dyn Iterator<Item = u64> + Send + Sync>>,
} }
fn sleep_from_reader(r: &Mutex<Lines<BufReader<File>>>) { fn sleep_from_reader(r: &Mutex<Box<dyn Iterator<Item = u64> + Send + Sync>>) {
let mut g = r.lock(); let mut g = r.lock();
let micros: u64 = g.next().unwrap().unwrap().parse().unwrap(); let micros: u64 = g.next().unwrap();
let sl = Duration::from_micros(micros); let sl = Duration::from_micros(micros);
std::thread::sleep(sl) std::thread::sleep(sl)
} }

View file

@ -101,7 +101,7 @@ struct Opts {
/// How many blocking tokio threads to spawn to process disk reads/writes. /// How many blocking tokio threads to spawn to process disk reads/writes.
/// Might want to increase if the disk is slow. /// Might want to increase if the disk is slow.
#[arg(long = "max-blocking-threads", default_value = "16")] #[arg(long = "max-blocking-threads", default_value = "8")]
max_blocking_threads: u16, max_blocking_threads: u16,
/// If set, will write to disk in background and not inline with peer. /// If set, will write to disk in background and not inline with peer.