[英]How do I limit the Tokio threadpool to a certain number of native threads?
将Tokio(v 0.1.11)线程池限制为n
操作系统本机线程的正确方法是什么,其中n
是任意数字,最好是在运行时可配置?
据我所知,可以使用tokio_current_thread::block_on_all
而不是tokio::run
和tokio_current_thread::spawn
而不是tokio::spawn
在单线程模式下使用Tokio。
我想要一个类似的解决方案,但n >= 1
。
您可以使用tokio::runtime::Builder
来构建Tokio Runtime
对象。 该构建器提供了一个core_threads()
方法,该方法可用于配置线程数,例如
let mut rt = runtime::Builder::new()
.core_threads(4)
.build()
.unwrap();
然后,您可以使用rt.spawn(some_future)
在此运行时上运行将来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.