logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: e58f45abd6fe6cdb4937788c6ff5a9f4cb923d39
parent 984426d9c4cadc59017c6770b033f4d72e497342
Author: rinpatch <rinpatch@sdf.org>
Date:   Tue, 19 Jan 2021 14:15:55 +0300

Improve PostgreSQL optimization article

Move query plan mode setting from OTP installation guide and try
to explain what it does.

Diffstat:

Mdocs/configuration/postgresql.md27++++++++++++++++++++++-----
Mdocs/installation/otp_en.md13++-----------
2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/docs/configuration/postgresql.md b/docs/configuration/postgresql.md @@ -1,10 +1,28 @@ -# Optimizing your PostgreSQL performance +# Optimizing PostgreSQL performance -Pleroma performance depends to a large extent on good database performance. The default PostgreSQL settings are mostly fine, but often you can get better performance by changing a few settings. +Pleroma performance is largely dependent on performance of the underlying database. Better performance can be achieved by adjusting a few settings. -You can use [PGTune](https://pgtune.leopard.in.ua) to get recommendations for your setup. If you do, set the "Number of Connections" field to 20, as Pleroma will only use 10 concurrent connections anyway. If you don't, it will give you advice that might even hurt your performance. +## PGTune -We also recommend not using the "Network Storage" option. +[PgTune](https://pgtune.leopard.in.ua) can be used to get recommended settings. Be sure to set "Number of Connections" to 20, otherwise it might produce settings hurtful to database performance. It is also recommended to not use "Network Storage" option. + +## Disable generic query plans + +When PostgreSQL receives a query, it decides on a strategy for searching the requested data, this is called a query plan. The query planner has two modes: generic and custom. Generic makes a plan for all queries of the same shape, ignoring the parameters, which is then cached and reused. Custom, on the contrary, generates a unique query plan based on query parameters. + +By default PostgreSQL has an algorithm to decide which mode is more efficient for particular query, however this algorithm has been observed to be wrong on some of the queries Pleroma sends, leading to serious performance loss. Therefore, it is recommended to disable generic mode. + + +Pleroma already avoids generic query plans by default, however the method it uses is not the most efficient because it needs to be compatible with all supported PostgreSQL versions. For PostgreSQL 12 and higher additional performance can be gained by adding the following to Pleroma configuration: +```elixir +config :pleroma, Pleroma.Repo, + prepare: :named, + parameters: [ + plan_cache_mode: "force_custom_plan" + ] +``` + +A more detailed explaination of the issue can be found at <https://blog.soykaf.com/post/postgresql-elixir-troubles/>. ## Example configurations @@ -28,4 +46,3 @@ max_worker_processes = 2 max_parallel_workers_per_gather = 1 max_parallel_workers = 2 ``` - diff --git a/docs/installation/otp_en.md b/docs/installation/otp_en.md @@ -89,6 +89,8 @@ RUM indexes are an alternative indexing scheme that is not included in PostgreSQ #### (Optional) Performance configuration It is encouraged to check [Optimizing your PostgreSQL performance](../configuration/postgresql.md) document, for tips on PostgreSQL tuning. +Restart PostgreSQL to apply configuration changes: + === "Alpine" ``` rc-service postgresql restart @@ -99,17 +101,6 @@ It is encouraged to check [Optimizing your PostgreSQL performance](../configurat systemctl restart postgresql ``` -If you are using PostgreSQL 12 or higher, add this to your Ecto database configuration - -```elixir -# -config :pleroma, Pleroma.Repo, -prepare: :named, -parameters: [ - plan_cache_mode: "force_custom_plan" -] -``` - ### Installing Pleroma ```sh # Create a Pleroma user