How come web framework faster than core library?

How come web framework faster than core library?

On my system I try to benchmark with WRK.

Req/Sec with release flag on multi threads

Library
std tcp : 5.8k
tokio : 3.7k

Framework
Actix: 14k
Warp: 13k

How come frameworks are faster than the core library they are builtin on? Please help me to understand. Thank you.

First of all, actix uses its own actors framework which is not dependent on tokio and std::net (for most of the functional part). Not so sure about warp.

Generally speaking, low level libraries are general purpose use for various applications hence they can be optimized in a specific way if the use case is previously known (for example, some additional invariants may come into play). It requires in depth knowledge of the system architecture though.

Keep in mind that you aren't comparing apples to apples here. I'm guessing your std tcp version uses std::net::TcpListener and blocking IO, while the tokio version uses tokio::net::TcpListener and asynchronous IO.

Asynchronous IO performs really well in these sorts of throughput tests because it lets the server handle other requests while data is being transferred, while blocking IO puts the current thread to sleep.

If you can give us links to the actual code being benchmarked then we can make more specific suggestions, otherwise there's a good chance the tokio is doing something silly that actix and warp avoid.

1 Like

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.