I'm trying to use boost::beast to implement a web service providing some REST APIs. These APIs are CPU-heavy, almost no disk or db I/O. My goal is to optimize for latency with OK throughput. Should I use sync or async way to implement them?
Thanks!
Generally speaking, when you are doing I/O-intensive work with little to no CPU-overhead, non-blocking or async is best. When the operations are, however, CPU-intensive, a threaded model tends to make more sense.
The reason for this is simple: It's usually a bad idea to block the event loop for longer periods of time - as would happen when using an asynchronous model for CPU-heavy computations.
When you start blocking the event loop, things like timers don't behave like they should, since they can only trigger once you return control to the event loop. This is usually not what you want.
If you want timeouts, you have no choice but to use the asynchronous APIs provided by Boost.Beast / Boost.Asio / Asio / Networking TS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With