-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use new instance of cache map instead of cleaning #5473
Conversation
Creation of a new map instance was used instead of map.clear() to clear a cache. We need it because map.clear() doesn't shrink already allocated map capacity, size of which can be significant.
public void removeOutdated(long ttlInMillis) { | ||
long now = System.currentTimeMillis(); | ||
map.entrySet().removeIf(entry -> now - entry.getValue().getTime() > ttlInMillis); | ||
if (map.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to resize the map anyway, because if there is one element left, we keep a map with one element and some bigger capacity.
There is a HashMap
constructor taking a map that creates a new map with capacity just enough to accommodate the existing elements. As an option, it could be done either if the map is empty or the size is small enough so that the copy is not too expensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but it is very rare case because to face with the case we must
- Had a significant capacity before.
- Expire most of datapoints, but not all of them
- Be in this state for a long time. (in other case the last datapoint will expire too).
I can't imagine how we can put system in such state.
After deactivating/activating stats/flowmonitoring/opentsdb topologies, the required statistics are available.
|
Creation of a new map instance was used instead of map.clear() to clear a cache. We need it because map.clear() doesn't shrink already allocated map capacity, size of which can be significant.
INFO for QAs:
Following topologies was updated:
How to check that PR works correctly:
kilda.flow.packets
kilda.flow.rtt
with tagorigin=flow-monitoring
(can be missed if server42 is active for the flow)