fairingrey/actix-realworld-example-app

Will heavy database query make one of cpu cores idle?

Opened this issue · 3 comments

Hi, I'm trying to figure this out, since apparently diesel doesn't support async (nor underlying postgres driver).

You're not explicitly specifying number of workers for HttpServer, which means it will create (number of cpu cores)-threads for handling incoming http requests.

Now, when next http request runs heavy database query through diesel it will block current thread. And for example, if my system has 4 cpu cores, it's enough to run 4 heavy http requests simultaneously to completely DoS entire server.

Is that correct?

@art-in I am not the author, but this thing is not using actix 2.0 (currently in release candidate). It is using a pre 1.0 actix. The db call does not spawn a new task, and is blocking (see here). I do not believe that this app is what you should be looking at if you want to use async actix. I would recommend looking here: https://github.com/actix/examples.

@vadixidav So in this example I see that database query is wrapped into web::block(), which run queries on a thread pool while not blocking main http server workers pool.

But web::block() available even in currently released v1.0.9

Probably this project should use this approach too?..

@art-in Most likely, but I have only started using Actix with std::future support.