我知道Axum是建立在Tokio之上的,Tokio有一个多线程调度程序和当前线程调度程序。
是否可以设置运行时,使其在单线程中服务请求?
发布于 2022-07-15 04:18:11
因为axum只是在tokio运行时与您设置的#[tokio::main]宏或系统一起生成的。未来的处理方式与您配置运行时的方式相同。
如果您使用的是宏,只需这样做:
#[tokio::main(flavor = "current_thread")]
async fn main() {
// Axum code here...
}下面是有关宏的更多信息的文档:https://docs.rs/tokio/0.3.3/tokio/attr.main.html#current-thread-runtime
下面是设置tokio运行时的非推荐方法:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html#method.new_current_thread
https://stackoverflow.com/questions/72988812
复制相似问题