Replace LimitedSizeDict with cachetools #40
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When receiving game reports from Pyrogenesis, it regularly happens that we never receive a report from both players of a rated game. This happens in the following situations:
As we cache game reports in memory until we received and compared them from both players of a rated game, this means that the
LimitedSizeDict
used for that would reach its maximum size of 4096 items pretty fast. While that doesn't impact functionality, it's using up way more memory than necessary.Additionally EcheLOn contained a bug which wouldn't even remove games from the
LimitedSizeDict
, where we did receive all reports for.While we can (and actually do in this commit) fix the bug in EcheLOn, we have no control over the situations where we don't receive reports from both players. However, what we can do is to remove reports for games where we're pretty certain, that we'll never receive the missing report anymore.
To do so, this commit replaces the custom
LimitedSizeDict
class with a dependency oncachetools
. For tracking reports from rated games a size-limitedTTLCache
is now used which evicts reports belonging to games after 1 hour, as we don't expect to receive reports later than a few seconds after the end of a rated game.This should result in a significant reduction of the memory required by EcheLOn.