Create the connections pool inside the anonymous function (the argument of HttpServer::new()) actually create a pool for each HttpServer worker thread. On my server, this behavior resulted in 16 pools x 10 connections per pool = 160 connections.
HttpServer automatically starts a number of HTTP workers, by default this number is equal to the number of logical CPUs in the system. This number can be overridden with the HttpServer::workers() method.
My CPU has 16 hyper-threads.
10 is the default size of each pool which can be changed via max_size() during construction.
That attempt to get 160 connections to PostgreSQL exceeded the default constraint max_connections = 100. So I got panic messages shouting "Sorry, too many clients already".
I would suggest to follow the implementation from the actixexample. Basically, it creates the pool outside the HttpServer construction.
Create the connections pool inside the anonymous function (the argument of
HttpServer::new()
) actually create a pool for each HttpServer worker thread. On my server, this behavior resulted in16 pools x 10 connections per pool = 160 connections
.The
16
is from actix-web:My CPU has
16
hyper-threads.10
is the default size of each pool which can be changed viamax_size()
during construction.That attempt to get
160
connections to PostgreSQL exceeded the default constraintmax_connections = 100
. So I got panic messages shouting "Sorry, too many clients already".I would suggest to follow the implementation from the
actix
example. Basically, it creates the pool outside the HttpServer construction.Updated, thanks!