sabri

sabri

Ecto pool_size?

Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size?

Thanks

Most Liked

josevalim

josevalim

Creator of Elixir

The pool_size controls how many connections you want to the database. The advice of starting one per core is good for CPU work. Connections however do a lot of IO work so I would recommend a minimum of at least 10. To find the ideal number you need to monitor and measure how your queues are behaving in production. A higher number is not necessarily better, as it implies in less re-use between connections and database overload.

12
Post #3
ashneyderman

ashneyderman

The optimal number of connections varies based on the DB engine. For example, Postgres recommends the following:

A formula which has held up pretty well across a lot of benchmarks for years is that for optimal throughput the number of active connections should be somewhere near ((core_count * 2) + effective_spindle_count). Core count should not include HT threads, even if hyperthreading is enabled. Effective spindle count is zero if the active data set is fully cached, and approaches the actual number of spindles as the cache hit rate falls. Benchmarks of WIP for version 9.2 suggest that this formula will need adjustment on that release. There hasn’t been any analysis so far regarding how well the formula works with SSDs.

You can find detailed explanations here: Number Of Database Connections - PostgreSQL wiki

At the end it is like Jose mentioned start with 10 and experiment (although 10 is rather arbitrary number but the formula above is a better starting point). Also consider that you might be running multiple instances of the service that talk to one DB - the formula described above is per DB instance not per clients instances it serves. So, there is plenty to experiment with.

minhajuddin

minhajuddin

I usually start with as many connections as the number of cores on your machine. And then fiddle around with it and do some benchmarking to reach an optimal size.

bobbypriambodo

bobbypriambodo

The answer to your first question can be found on this Wikipedia article on Connection pool. Basically it’s a pool of connections to the DB (e.g. Postgres) being kept around and reused because opening and closing connections are costly operations.

The second question needs a more thorough analysis on your machine spec and your app’s (projected) load. I don’t think I have the knowledge to properly answer that, but my initial hypothesis is that we may set it as high as the machine’s resources let us. I might be wrong, though.

Edit: I stand corrected by Jose’s answer :slight_smile:

sabri

sabri

Thanks all for support, truly friendly community :slight_smile:

In my case, I am having multi-tenancy, as I am using Postgres Schemas in One DB, one schema per each tenancy, isn’t there a safe size that I can go with as a starting point?

What kind of benchmarking is needed?

Where Next?

Popular in Questions Top

Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement