Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Synapse should close idle database connections #5728

Open
jo-so opened this issue Jul 21, 2019 · 5 comments
Open

Synapse should close idle database connections #5728

jo-so opened this issue Jul 21, 2019 · 5 comments
Labels
T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. z-p3 (Deprecated Label)

Comments

@jo-so
Copy link

jo-so commented Jul 21, 2019

It seems the database connection pooling doesn't shut down idle database connections:

SELECT application_name, datname, usename, state, age(now(), query_start), wait_event_type, wait_event, query FROM pg_stat_activity WHERE now() - interval '10s' > query_start ORDER BY age;
 application_name | datname |    usename     | state |       age       | wait_event_type | wait_event | query  
------------------+---------+----------------+-------+-----------------+-----------------+------------+--------
 synapse-media    | matrix  | matrix-synapse | idle  | 00:00:14.840869 | Client          | ClientRead | COMMIT
 synapse-event    | matrix  | matrix-synapse | idle  | 00:08:34.818956 | Client          | ClientRead | COMMIT
 synapse-event    | matrix  | matrix-synapse | idle  | 00:08:34.836956 | Client          | ClientRead | COMMIT
 synapse-cl-rdr   | matrix  | matrix-synapse | idle  | 00:08:34.837199 | Client          | ClientRead | COMMIT
 synapse-cl-rdr   | matrix  | matrix-synapse | idle  | 00:08:40.64963  | Client          | ClientRead | COMMIT
(5 rows)

Because every Postgres process uses 150MB RSS at me, it would the helpful if Synapse could close the database connections when not needed.

@Half-Shot
Copy link
Collaborator

Connection pooling is handled by https://twistedmatrix.com/documents/8.0.0/api/twisted.enterprise.adbapi.ConnectionPool.html

@jo-so what have you set your cp_min and cp_max values too. They control the minimum and maximum number of connections open.

@jo-so
Copy link
Author

jo-so commented Jul 22, 2019 via email

@reivilibre
Copy link
Contributor

I've set cp_max. Synapse opens on high pressure up to these connections, but never closes them. In the code of ConnectionPool is nothing that closes idle connections. Maybe you should use a better connection pool.

Try cp_min. By default, it is 5 iirc, so 5 connections will always stay open

@jo-so
Copy link
Author

jo-so commented Aug 5, 2019 via email

@anothatuber
Copy link

I support jo-sos request. I also set cp_min to 1 and it goes up to 4 right after starting Synapse and the to 5 a few minutes later.
I'm running a non-federated 2-user-family setup pf synapse, so I don't see pressure for so much connections.
cp_max is obeyed, setting it to 2 and Synapse will open 2 idle connections right at the start. But I'd like to have some more headroom.

@richvdh richvdh added enhancement z-p3 (Deprecated Label) labels Mar 30, 2020
@DMRobertson DMRobertson added T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. and removed z-enhancement labels Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. z-p3 (Deprecated Label)
Projects
None yet
Development

No branches or pull requests

6 participants