Axum instead of actix-web

Especiallly because of my inability to find a solution the issue I discussed here: how to spawn task from actix-web handler I'm interested it looking for a solid rust framework that compares to actix_web in features.

So far I like what I'm seeing with axum. One thing that I can report is that the following assert dropped into a request handler, does indeed work using axum:

    assert_eq!(tokio::spawn(async { 1 }).await.unwrap(), 1);

and I like how it doesn't have to depend on an actix_rt wrapper, and can directly use the tokio::spawn, which suggests a thinner, hopefully less prone to failure layer ( less gotchas? ) for accessing other tokio internals.

Does anyone have advice on their usages with axum or perhaps a different framework good for building complex REST servers?

Thank you!

I haven't tried any web server frameworks recently, but I've heard a lot of people say they like axum recently. And it certainly is a thinner wrapper than most alternatives are.

That said, you should be able to use tokio::spawn directly from actix-web (assuming the versions match).

2 Likes

I've been maintaining a significant size application with forks in both actix-web, and axum. I prefer axum. I have ended up with more concise endpoint code and fewer lines overall using axum. Stress testing has shown little difference in performance.

They are both excellent. Axum is worth considering IMHO.

3 Likes

We use Axum for backend of real-time application .

We have 5 Machine
Each have 15 Cpu , 30 Ram
they working amazing without any problem .

First we wrote in acitx_web it use shared-nothing technique, it increase performance for io bound server ( it is best ) , but for Complex server is not best because not use work-stealing , each thread is seperate worker.

Actix-web for complex server
Result is -> Increase latency sometimes
If your latency not very important for you
or your app is more io-bound use actix_web its great .

If your app is cpu-bound and latency is important . It is not best choice.

Thanks for the reply!

So far I am liking axum better. I have been able to easily use the tokio::spawn directly with it and so far I'm not able to get it to work with actix-web. If you try to use it directly you get a complaint that the tokio runtime has not been started, and then when you use the wrapped up method to do it which presumably goes through the tokio runtime launched under the hood, I get the error listed in my post. This is all using the latest stuff. Fwiw, goolging around the various other posts on this topics the only suggestions I found were that you needed to use an earlier version of tokio. Which I'm happy to report is not necessary with axum.

Thank you!

Indeed, you have to match up the actix and Tokio versions properly.

Thanks for the reply!

I'm curious here.

That is of interest to me. I'm hoping that each tokio::spawn is s separete async task, and not necessarily a separate thread. I'm assuming all that complexity would be hidden by tokio. My guess is that axum would not interfere with any of tokios choices in this realm.

What they referred to is whether tasks are fixed to a particular thread, or whether they can be moved to more evenly spread out the load.

My hope is that whatever framework I choose, if it's based on tokio, that question would be entirely up to tokio, and whatever choices I might make to be optimal with my own threading would be no different than working with tokio without the web framework.

I recall seeing in the lit on tokio that if you're interest is in maximizing multiple core usage, you should be using something like rayon. I have used that on a different project (that did not require a web server.) I'm curious whether tokio and rayon play nicely together, but that's getting off topic a bit! :wink:

The default option in Tokio is to turn work stealing on. However, in some situations where all of your tasks are short-lived, it is more efficient to turn it off and not pay for it, since the tasks are so short-lived, that moving the tasks is not necessary to even the load.

You can use rayon with Tokio.

All very helpful information.

Thank you very much!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.