Viceroy
Viceroy copied to clipboard
Yield during `pending_req_poll`
I think pending_req_poll
should call tokio::task::yield_now
before returning when the request is not ready.
A guest which invokes that hostcall in a loop, like the upstream-async test fixture, may not give Tokio any other opportunities to do I/O. Viceroy currently addresses that by using Wasmtime's "fuel" mechanism to interrupt the loop periodically, but in between those interruptions the loop spins without any way to make progress.
Note that Tokio's implementation of yield_now
is very similar to Wasmtime's implementation of an async yield in response to either fuel-based or epoch interruption: both return Pending
on the first poll and Ready
on the second.
So I think yielding in pending_req_poll
will tend to reduce both latency and CPU usage. In addition I think it means the upstream-async test would pass without either fuel-based or epoch interruptions, although there may be other situations which still require those interruptions in order to make progress.