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

Fix bug where state cache used lots of memory #3005

Merged
merged 2 commits into from Mar 19, 2018

Conversation

erikjohnston
Copy link
Member

The state cache bases its size on the sum of the size of entries. The
size of the entry is calculated once on insertion, so it is important
that the size of entries does not change.

The DictionaryCache modified the entries size, which caused the state
cache to incorrectly think it was smaller than it actually was.

The state cache bases its size on the sum of the size of entries. The
size of the entry is calculated once on insertion, so it is important
that the size of entries does not change.

The DictionaryCache modified the entries size, which caused the state
cache to incorrectly think it was smaller than it actually was.
@@ -154,14 +154,14 @@ def cache_get(key, default=None, callbacks=[]):
def cache_set(key, value, callbacks=[]):
node = cache.get(key, None)
if node is not None:
if value != node.value:
if node.callbacks and value != node.value:
Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, this was just a cheeky thing to only do the != check if we do actually have node.callbacks

Copy link
Member

Choose a reason for hiding this comment

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

might be worth a comment then?

Copy link
Member

Choose a reason for hiding this comment

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

isn't it outweighed by doing size_callback even when it doesn't change?

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.

looks fine modulo comments

@@ -154,14 +154,14 @@ def cache_get(key, default=None, callbacks=[]):
def cache_set(key, value, callbacks=[]):
node = cache.get(key, None)
if node is not None:
if value != node.value:
if node.callbacks and value != node.value:
Copy link
Member

Choose a reason for hiding this comment

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

might be worth a comment then?

@@ -154,14 +154,14 @@ def cache_get(key, default=None, callbacks=[]):
def cache_set(key, value, callbacks=[]):
node = cache.get(key, None)
if node is not None:
if value != node.value:
if node.callbacks and value != node.value:
Copy link
Member

Choose a reason for hiding this comment

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

isn't it outweighed by doing size_callback even when it doesn't change?

# We pop and reinsert as we need to tell the cache the size may have
# changed

entry = self.cache.pop(key, DictionaryEntry(False, set(), {}))
Copy link
Member

Choose a reason for hiding this comment

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

not entirely relevant here, but I wonder if it would be better to do

entry =  self.cache.pop(key, None)
if entry is None:
    entry = DictionaryEntry(False, set(), {})

to avoid the object creation overhead?

@ara4n
Copy link
Member

ara4n commented Mar 18, 2018

please can we merge this and cut a new RC before any more folks on 0.27-rc1 have explosions?

@erikjohnston
Copy link
Member Author

(The PEP8 error appears spurious and unrelated to this PR)

@erikjohnston erikjohnston merged commit 3f961e6 into develop Mar 19, 2018
krombel added a commit to krombel/synapse that referenced this pull request Mar 22, 2018
Changes in synapse v0.27.0-rc2 (2018-03-19)
===========================================

Pulls in v0.26.1

Bug fixes:

* Fix bug introduced in v0.27.0-rc1 that causes much increased memory
  usage in state cache (PR matrix-org#3005)

Changes in synapse v0.26.1 (2018-03-15)
=======================================

Bug fixes:

* Fix bug where an invalid event caused server to stop functioning
  correctly, due to parsing and serializing bugs in ujson library
  (PR matrix-org#3008)
@erikjohnston erikjohnston deleted the erikj/fix_cache_size branch September 20, 2018 13:59
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.

None yet

3 participants