Skip to content

Impact on using tokio runtime in actix context #1302

Answered by abonander
yageek asked this question in Q&A
Discussion options

You must be logged in to vote

We use this in our projects internally. You can even have both runtimes going in the same binary. In fact, the Actix runtime is just a wrapper around the Tokio runtime that forces it into single-threaded mode, and Tokio's notion of "current runtime" is set on a per-thread basis, so technically you could have a pool of threads each with its own Actix runtime if you want.

Since the Actix runtime is single-threaded, if we have a lot of background work in our app that we don't want clogging up the Actix thread, we'll start a Tokio threaded runtime in the background and spawn tasks into that. The tokio::net::TcpStream that underlies SQLx's connection types doesn't seem to mind being moved back…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yageek
Comment options

Answer selected by yageek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants