marcosbarbero / spring-cloud-zuul-ratelimit

Rate limit auto-configure for Spring Cloud Netflix Zuul

Home Page:https://blog.marcosbarbero.com/spring-cloud-netflix-zuul-rate-limit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Should we manually implement the eviction for the infinispan cache ?

Arveti opened this issue · comments

commented

I am using spring-cloud-zuul-ratelimit with Bucket4j Infinispan implementation. My question is that will spring-cloud-zuul-ratelimit also evict the cache or even though expiration time / reset time pass, will the entry be in the cache? I don't want the inifinispan in-memory cache in the VM to grow exponentially for each originated request. Hence asking.
Awaiting reply.

Hello @Arveti, thanks for getting in touch, we will get back to you asap! If you have issues in the 1.x.x.RELEASE line we recommend you to update to the latest version, unfortunately this line is not supported anymore.

Hello @Arveti

Bucket4j does not manage expiration by itself. Instead, you need to configure a write-expire strategy for your cache.

commented

@vladimir-bukhtoyarov
Got it. Just need help with my code. I wrote the following bean to remove the cache.
@Bean @Qualifier("RateLimit") public ReadWriteMap<String, GridBucketState> map() { DefaultCacheManager cacheManager = new DefaultCacheManager(); cacheManager.defineConfiguration("rateLimit", new ConfigurationBuilder().clustering() .cacheMode(CacheMode.LOCAL).eviction().strategy(EvictionStrategy.REMOVE).type(EvictionType.COUNT).size(1000).build()); AdvancedCache<String, GridBucketState> cache = cacheManager.<String, GridBucketState>getCache("rateLimit").getAdvancedCache(); FunctionalMapImpl<String, GridBucketState> functionalMap = FunctionalMapImpl.create(cache); return ReadWriteMapImpl.create(functionalMap); }

I couldn't find enough documentation and so asking this question. With the above code, Am I removing the whole cache with EvictionStrategy.REMOVE when 1000 COUNT is reached abruptly ? What happens to the requests whose quota is being tracked in origin based rate limiting ?

@Arveti which version of Infinispan do you use?

commented

@vladimir-bukhtoyarov I am using 9.4.0

ConfigurationBuilder config = new ConfigurationBuilder();
config.expiration().maxIdle(60, TimeUnit.SECONDS); // bucket will be evicted after one minute of inactivity

Also, remember that max-idle parameter should not be less than the refill period of bucket.

commented

Great. Thank you so much. This helps a lot. Just one last question -
Is refill period same as zuul.ratelimit.default-policy-list[0].refresh-interval?
If not what is it/how to set it ?
I am using only default policy no serviceId specific settings are there.

For some reason, I missed this issue yesterday.
Thanks @vladimir-bukhtoyarov for your support, I can't help but love OSS 😃

commented

@vladimir-bukhtoyarov / @marcosbarbero Can you please confirm if policy refresh interval and bucket4j refill period both are same ? Would be really great. Thank you.

Hi @Arveti, yes the refresh-internal changes the bucket configuration on the fly so both are aligned. You can see it happening on this line

commented

Thanks. Closing this.