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

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
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement