hi, all, i'm new in learning rust..
i intend to learn the best practice for implementing web service in actix.
the use case is simple : querying some records from a postgresql db table, and then displaying/printing those records in json format.
from the result of googling over these words : "rest api with actix web postgresql", i've got this simple example : Rust REST API, Actix-web, PostgreSQL - Part 1: Overview - Turreta
i'm following that example, and then here's my source code : ws-benchmark/implementations/actix-sync at master · sharing-lab/ws-benchmark · GitHub
then i benchmarked it using "ab -n 1000 -c 4 ..." on a Xeon(R) CPU E3-1225 v5 @ 3.30GHz (4 cores), and i got 1623 requests per second (rps)
i think it's a wrong way of using actix, is it? it's synchronous (blocking)
so i made some change, based on the official actix example : https://github.com/actix/examples/blob/master/r2d2/src/main.rs
i changed : .route(web::get().to(color::get_list))
,
into this : .route(web::get().to_async(color::get_list))
and i put / move blocking code inside web::block(move || { ... })
: ws-benchmark/mod.rs at master · sharing-lab/ws-benchmark · GitHub
i also used r2d2. the complete async version is : ws-benchmark/implementations/actix-r2d2 at master · sharing-lab/ws-benchmark · GitHub
then the benchmark result became : 13434 rps. so it's more than 8 x increase in performance/speed (the complete benchmark notes : https://github.com/sharing-lab/ws-benchmark/blob/master/results-xeon_4_core.txt)
is there any more missing point in implementing the correct best practice to develop webservice in actix ?
Thanks very much