Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Remove Gen2 GC based trigger for compacting memory cache #221 #265

Closed
wants to merge 1 commit into from

Conversation

JunTaoLuo
Copy link
Contributor

#221

Will need approval from @Eilon and @DamianEdwards due to the breaking API change.

@JunTaoLuo JunTaoLuo added this to the 2.0.0 milestone Jan 20, 2017
@Eilon
Copy link
Member

Eilon commented Jan 20, 2017

Do we have any gauge as to whether anyone out there has implemented this API and would be broken?

/// Attempt to remove the given percentage of the total entries in the cache.
/// </summary>
/// <param name="percentage">The percentage of cache entries to remove.</param>
void Compact(double percentage);
Copy link
Member

Choose a reason for hiding this comment

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

Can you update the doc comment in MemoryCache itself to be a proper doc comment? Right now there are some odd /// comments there but not an actual doc comment.

/// Remove at least the given percentage (0.10 for 10%) of the total entries (or estimated memory?), according to the following policy:
/// 1. Remove all expired items.
/// 2. Bucket by CacheItemPriority.
/// 3. Least recently used objects.
/// ?. Items with the soonest absolute expiration.
/// ?. Items with the soonest sliding expiration.
/// ?. Larger objects - estimated by object graph size, inaccurate.

Copy link
Member

Choose a reason for hiding this comment

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

Also, the implementation in MemoryCache doesn't do any argument validation, so that needs to be fixed as well.

/// Attempt to remove the given percentage of the total entries in the cache.
/// </summary>
/// <param name="percentage">The percentage of cache entries to remove.</param>
void Compact(double percentage);
Copy link
Member

@Tratcher Tratcher Jan 20, 2017

Choose a reason for hiding this comment

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

should this return the number of elements removed? or a bool indicating if any elements were removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the argument is in percentage, it would probably make more sense to return the percentage of elements removed?

Copy link
Member

Choose a reason for hiding this comment

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

That doesn't seem very informative. Also, percentages are problematic if you remove 0/0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, since we are exposing Compact, should we expose Count on the interface as well? It's not a good way to gauge cache size but I suspect users will downcast and rely on it to determine how much to compact like in #252.

Copy link
Member

Choose a reason for hiding this comment

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

The point of using percentages is that they don't need to know the size. Otherwise Compact would take a specific amount.

Or we shift it so Compact takes a specific number of elements to purge, returns the actual number removed, and expose Count.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then let's keep using percentages for both the amount to remove and amount removed. In the 0/0 case, just return 0. Returning the number of entry removed is rather strange considering a percentage was passed in. Returning a bool is also very uninformative.

Copy link
Member

Choose a reason for hiding this comment

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

@Eilon except we've punted the decide-when-to-compact duty to the developer, and the number of elements in the cache is one inputs you'd use to decide when and how much to purge.

Copy link
Member

Choose a reason for hiding this comment

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

@JunTaoLuo put this on hold until we can sync in person Monday.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will probably solicit feedback from @davidfowl and @DamianEdwards as well if possible.

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 think anyone can ever reason about how much to clear based on the number of items in the cache. Remember, the cache is generally a shared resource. Someone (including our own codes) might have stashed a thousand small objects there. Or 1 really ginormous one.

But yes, let's discuss.

@JunTaoLuo
Copy link
Contributor Author

We're going with a different design. I will update the issue and open a new PR.

@JunTaoLuo JunTaoLuo closed this Feb 10, 2017
@Wallsmedia
Copy link

Wallsmedia commented Feb 12, 2017

@JunTaoLuo Could have a look at my change proposal,
Add to MemoryCacheOptions the CustomCompactOnMemoryPressureDelegate. #252
It may contribute to design.
I have added example how it woks.
To be clear, I have been using this approach/solution in my web services.

@davidfowl
Copy link
Member

We'll use it as an input but we're basically separating the concept of memory pressure detection out of the cache and adding a first class way to provide compaction logic via an interface. There will also be a way to trigger a compaction via an API exposed from the cache.

Similar so what you delegate can do but less specific.

@natemcmaster natemcmaster deleted the johluo/remove-gc-trigger branch November 7, 2018 04:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants