What does queue_target and queue interval exactly mean in DBConnection?

I read the definition in the docs
https://hexdocs.pm/db_connection/DBConnection.html#start_link/2-queue-config

But I am confused as to what they mean and how do they work. The example given is confusing. Can someone explain me this?

1 Like

This answer I wrote a while ago might help you.

1 Like

This is an extremely late reply but would like to provide my own answer in case someone visits.

  • A database connection has a limited number of pool connections.
  • If we set queue interval to be 1s and queue target to 50ms then for every 1s (queue interval) it will check if all connections take longer than 50ms (queue target) to checkout or become available to accept a query. If yes, then it will double the target to 100ms.
  • If again for the next interval it sees that connections take longer than 100ms to checkout then that is the time the connection will drop queries to prevent further burden to the database
2 Likes

See timeout - Elixir: DBConnection queue_target and queue_interval explained - Stack Overflow

The timeouts you’re referring to are set with the :timeout option in execution functions (i.e. execute/4), :queue_target and :queue_interval are only meant to affect the pool’s ability to begin new requests (for requests to checkout connections from the pool), not requests that have already checked out connections and are already being processed.

Keep in mind that all attempts to checkout connections during a :queue_interval must take longer than :queue_target in order for these values to affect anything. Normally you’d test different values and monitor your database’s ability to keep up in order to find optimal values for your environment.

2 Likes