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

Batch cache invalidation over replication #4671

Merged
merged 5 commits into from
Feb 19, 2019

Conversation

erikjohnston
Copy link
Member

Currently whenever the current state changes in a room invalidate a lot
of caches, which cause a lot of traffic over replication. Instead,
lets batch up all those invalidations and send a single poke down
the replication streams.

Hopefully this will reduce load on the master process by substantially
reducing traffic.

Currently whenever the current state changes in a room invalidate a lot
of caches, which cause *a lot* of traffic over replication. Instead,
lets batch up all those invalidations and send a single poke down
the replication streams.

Hopefully this will reduce load on the master process by substantially
reducing traffic.
@erikjohnston erikjohnston requested a review from a team February 18, 2019 17:58
@erikjohnston
Copy link
Member Author

This passes the sytests worker config locally (and breaks when I break the cache invalidation)

@codecov-io
Copy link

codecov-io commented Feb 18, 2019

Codecov Report

Merging #4671 into develop will increase coverage by <.01%.
The diff coverage is 82.14%.

@@             Coverage Diff             @@
##           develop    #4671      +/-   ##
===========================================
+ Coverage    75.17%   75.18%   +<.01%     
===========================================
  Files          340      340              
  Lines        34712    34736      +24     
  Branches      5677     5680       +3     
===========================================
+ Hits         26096    26116      +20     
- Misses        7013     7015       +2     
- Partials      1603     1605       +2

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm apart from some quibbling

# We probably haven't pulled in the cache in this worker,
# which is fine.
pass
if row.cache_func == _CURRENT_STATE_CACHE_NAME:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see some words about this (and in general what the 'caches' stream means) documented in docs/tcp_replication.tcp.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some words. I haven't specified exactly what _CURRENT_STATE_CACHE_NAME means, as I feel like that's just going to quickly get out of date with the code and is probably unnecessary.

synapse/storage/_base.py Outdated Show resolved Hide resolved
synapse/storage/_base.py Outdated Show resolved Hide resolved
synapse/storage/_base.py Outdated Show resolved Hide resolved
synapse/storage/_base.py Outdated Show resolved Hide resolved
synapse/storage/_base.py Outdated Show resolved Hide resolved
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm otherwise


However, there are times when a number of caches need to be invalidated at the
same time with the same key. To reduce traffic we batch those invalidations into
a single poke by defining a special cache name that workers understand to mean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind not listing the exact caches, but please can you define the special cache name?

synapse/storage/_base.py Outdated Show resolved Hide resolved
synapse/storage/_base.py Outdated Show resolved Hide resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants