You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Move update_client_ips to the background worker #10425
I have a feeling that we wanted to keep this on the main process as it needs to only be run by one, single process. However, this is no longer a concern now that we can dedicate all background work to a single worker through the run_background_tasks_on: <worker_name> config option.
This operation has been reported as potentially CPU intensive on some deployments, so moving it off the main process would be a win.
(Also random thought: can this be converted to something that operates entirely in the database (postgres)?)
It doesn't look like #8500 has any info on why this wasn't done.
I believe it was because insert_client_ip is what caches the IP batch info (by writing to _batch_row_update). This gets called by the master process, so it isn't as simple as just saying "run this other code on the background worker" since...that worker will have the in-memory cache updated.
You might be able to send those over replication, but that would be more invasive.
In addition, there's a simple optimisation we could make to the function to likely make it a bit lighter on the database.
Currently we iterate over the list of all IP entries and make one or (more often) 2 separate queries against the database server. This results in both a high amount of DB and CPU usage.
Activity
anoadragon453 commentedon Jul 19, 2021
I think all that needs to happen is wrapping the
looping_callin a conditional forrun_background_tasks_on:synapse/synapse/storage/databases/main/client_ips.py
Lines 435 to 452 in c0df6ba
So something like:
as well as the other bits in the constructor.
clokep commentedon Jul 19, 2021
It doesn't look like #8500 has any info on why this wasn't done.
I believe it was because
insert_client_ipis what caches the IP batch info (by writing to_batch_row_update). This gets called by the master process, so it isn't as simple as just saying "run this other code on the background worker" since...that worker will have the in-memory cache updated.You might be able to send those over replication, but that would be more invasive.
anoadragon453 commentedon Jul 28, 2021
@clokep does that imply that IP addresses are only noted in the database for the main process, not any workers?
clokep commentedon Jul 29, 2021
I think so but it has been a while since I looked at this. 😄
anoadragon453 commentedon Jul 29, 2021
In addition, there's a simple optimisation we could make to the function to likely make it a bit lighter on the database.
Currently we iterate over the list of all IP entries and make one or (more often) 2 separate queries against the database server. This results in both a high amount of DB and CPU usage.
synapse/synapse/storage/databases/main/client_ips.py
Lines 494 to 524 in c0df6ba
One simple solution we could do is to simply execute a single batch query against the server containing all modifications. We could:
simple_upsert_txnto a singlesimple_upsert_many_txn, which utilisestxn.execute_batch.simple_update_txndoes not (yet) have a_manyderivative. I'm not sure whether we'd want to create that for this purpose.