spring-cloud / spring-cloud/spring-cloud-commons
LoadBalancerCacheManager supports refresh cache, not just expire cache
@sobelek is already working on this.
Since Oct 31, 2023.
- Dominant language
- Java
- Stars
- 751
- Forks
- 744
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
Is your feature request related to a problem? Please describe.
Spring Cloud LoadBalancer now only supports expired caching, that is, after a period of time, the cache item will become invalid, and when the same content is requested again, it will re-submit a request to the registry blockly to obtain the service instance. In smooth service there will be spikes.
In addition to causing spikes, this also poses a challenge to high availability. When the cache expires, all cache items are evicted. At this time, there are no related service instances in memory. If the registry goes down, the entire None of the client instances can submit a request to the service provider, and the service is completely unavailable. In a refresh cache, this will have no effect. If the registry goes down, we just don't get the latest data, and slightly older data is better than no data (in fact, the service instance changes very frequently low, the impact of old data is negligible).
Describe the solution you'd like
Based on this, I think it is necessary to provide refresh cache instead of just expire cache
A feasible solution is to support configuring the refresh interval and use DiscoveryClient to grab service instances, and at the same time support configuring the expiration time to avoid using expired data for a long time (exposing the problem)
setCaffeine(Caffeine.newBuilder()
.initialCapacity(properties.getCapacity())
.refreshAfterWrite(properties.getTtl().dividedBy(2))
.expireAfterWrite(properties.getTtl())
.softValues());
setCacheLoader((key) -> discoveryClient.getInstances((String) key));
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.