Skip to content

Commit

Permalink
Merge pull request #246 from changweige/pick-tokio-threads
Browse files Browse the repository at this point in the history
cache: set the number of worker threads of tokio threads pool
  • Loading branch information
imeoer authored Dec 28, 2021
2 parents d562c2d + dddf373 commit e34a553
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion storage/src/cache/filecache/cache_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ impl FileCacheEntry {
let metrics = self.metrics.clone();

metrics.buffered_backend_size.add(buffer.size() as u64);
self.runtime.spawn(async move {
self.runtime.spawn_blocking(move || {
metrics.buffered_backend_size.sub(buffer.size() as u64);
match Self::persist_chunk(&file, offset, buffer.slice()) {
Ok(_) => delayed_chunk_map
Expand Down
14 changes: 12 additions & 2 deletions storage/src/cache/filecache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use std::collections::HashMap;
use std::fs;
use std::io::Result;
use std::sync::{Arc, RwLock};
use std::time::Duration;

use tokio::runtime::{Builder, Runtime};

use nydus_utils::metrics::BlobcacheMetrics;
use tokio::runtime::Runtime;

use self::cache_entry::FileCacheEntry;
use crate::backend::BlobBackend;
Expand Down Expand Up @@ -84,7 +86,15 @@ impl FileCacheMgr {
serde_json::from_value(config.cache_config).map_err(|e| einval!(e))?;
let work_dir = blob_config.get_work_dir()?;
let metrics = BlobcacheMetrics::new(id, work_dir);
let runtime = Arc::new(Runtime::new().map_err(|e| eother!(e))?);
let runtime = Arc::new(
Builder::new_multi_thread()
.worker_threads(1) // Limit the number of worker thread to 1 since this runtime is generally used to do blocking IO.
.thread_keep_alive(Duration::from_secs(10))
.max_blocking_threads(8)
.thread_name("cache-flusher")
.build()
.map_err(|e| eother!(e))?,
);
let prefetch_config: Arc<AsyncPrefetchConfig> = Arc::new(config.prefetch_config.into());
let worker_mgr = AsyncWorkerMgr::new(metrics.clone(), prefetch_config.clone())?;

Expand Down

0 comments on commit e34a553

Please sign in to comment.