Fix execution thread for blocking and adjusts timing

* Fix execution thread for blocking DiscoveryClientServiceInstanceListSupplier.

* Desynchronise HealthCheck and Cache. Add info about using HealthCheck without Cache to docs.

See gh-760
This commit is contained in:
Olga Maciaszek-Sharma
2020-05-27 09:13:55 -05:00
committed by GitHub
parent 587f5f568a
commit 87e5d7a62b
7 changed files with 22 additions and 23 deletions

View File

@@ -29,9 +29,9 @@
|spring.cloud.inetutils.use-only-site-local-interfaces | false | Whether to use only interfaces with site local addresses. See {@link InetAddress#isSiteLocalAddress()} for more details.
|spring.cloud.loadbalancer.cache.caffeine.spec | | The spec to use to create caches. See CaffeineSpec for more details on the spec format.
|spring.cloud.loadbalancer.cache.capacity | 256 | Initial cache capacity expressed as int.
|spring.cloud.loadbalancer.cache.ttl | 30s | Time To Live - time counted from writing of the record, after which cache entries are expired, expressed as a {@link Duration}. The property {@link String} has to be in keeping with the appropriate syntax as specified in Spring Boot <code>StringToDurationConverter</code>. @see <a href= "https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/StringToDurationConverter.java">StringToDurationConverter.java</a>
|spring.cloud.loadbalancer.cache.ttl | 35s | Time To Live - time counted from writing of the record, after which cache entries are expired, expressed as a {@link Duration}. The property {@link String} has to be in keeping with the appropriate syntax as specified in Spring Boot <code>StringToDurationConverter</code>. @see <a href= "https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/StringToDurationConverter.java">StringToDurationConverter.java</a>
|spring.cloud.loadbalancer.health-check.initial-delay | 0 | Initial delay value for the HealthCheck scheduler.
|spring.cloud.loadbalancer.health-check.interval | 30s | Interval for rerunning the HealthCheck scheduler.
|spring.cloud.loadbalancer.health-check.interval | 25s | Interval for rerunning the HealthCheck scheduler.
|spring.cloud.loadbalancer.health-check.path | |
|spring.cloud.loadbalancer.retry.enabled | true |
|spring.cloud.loadbalancer.ribbon.enabled | true | Causes `RibbonLoadBalancerClient` to be used by default.

View File

@@ -882,7 +882,7 @@ You can set your own `ttl` value (the time after write after which entries shoul
as the value of the `spring.cloud.loadbalancer.cache.ttl` property.
You can also set your own LoadBalancer cache initial capacity by setting the value of the `spring.cloud.loadbalancer.cache.capacity` property.
The default setup includes `ttl` set to 30 seconds and the default `initialCapacity` is `256`.
The default setup includes `ttl` set to 35 seconds and the default `initialCapacity` is `256`.
You can also altogether disable loadBalancer caching by setting the value of `spring.cloud.loadbalancer.cache.enabled`
to `false`.
@@ -951,7 +951,7 @@ We suggest passing a `DiscoveryClientServiceInstanceListSupplier` delegate in th
You could use this sample configuration to set it up:
[[zoned-based-custom-loadbalancer-configuration]]
[[health-check-based-custom-loadbalancer-configuration]]
[source,java,indent=0]
----
public class CustomLoadBalancerConfiguration {
@@ -962,12 +962,13 @@ public class CustomLoadBalancerConfiguration {
return ServiceInstanceListSupplier.builder()
.withDiscoveryClient()
.withHealthChecks()
.withCaching()
.build(context);
}
}
----
NOTE:: `HealthCheckServiceInstanceListSupplier` has its own caching mechanism based on Reactor Flux `replay()`, therefore, if it's being used, you may want to skip wrapping that supplier with `CachingServiceInstanceListSupplier`.
TIP:: In order to make working on your own LoadBalancer configuration easier, we have added a `builder()` method to the `ServiceInstanceListSupplier` class.
TIP:: You can also use our alternative predefined configurations in place of the default ones by setting the value of `spring.cloud.loadbalancer.configurations` property to `zone-preference` to use `ZonePreferenceServiceInstanceListSupplier` with caching or to `health-check` to use `HealthCheckServiceInstanceListSupplier` with caching.

View File

@@ -54,7 +54,7 @@ public class LoadBalancerProperties {
/**
* Interval for rerunning the HealthCheck scheduler.
*/
private Duration interval = Duration.ofSeconds(30);
private Duration interval = Duration.ofSeconds(25);
private Map<String, String> path = new LinkedCaseInsensitiveMap<>();

View File

@@ -22,6 +22,7 @@ import static org.springframework.cloud.bootstrap.config.PropertySourceBootstrap
/**
* Simple, non-enumerable PropertySource wrapper.
*
* @author Ryan Baxter
*/
public class SimpleBootstrapPropertySource<T> extends PropertySource<T> {

View File

@@ -39,7 +39,7 @@ public class LoadBalancerCacheProperties {
* @see <a href=
* "https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/StringToDurationConverter.java">StringToDurationConverter.java</a>
*/
private Duration ttl = Duration.ofSeconds(30);
private Duration ttl = Duration.ofSeconds(35);
/**
* Initial cache capacity expressed as int.

View File

@@ -47,8 +47,8 @@ public class DiscoveryClientServiceInstanceListSupplier
Environment environment) {
this.serviceId = environment.getProperty(PROPERTY_NAME);
this.serviceInstances = Flux
.defer(() -> Flux.fromIterable(delegate.getInstances(serviceId))
.collectList().flux().subscribeOn(Schedulers.boundedElastic()));
.defer(() -> Flux.just(delegate.getInstances(serviceId)))
.subscribeOn(Schedulers.boundedElastic());
}
public DiscoveryClientServiceInstanceListSupplier(ReactiveDiscoveryClient delegate,

View File

@@ -109,21 +109,18 @@ class DiscoveryClientServiceInstanceListSupplierTests {
@Test
void shouldUpdateReturnRetrievedInstancesBlockingClient() {
when(discoveryClient.getInstances(SERVICE_ID)).thenReturn(
Lists.list(instance("1host", false), instance("2host-secure", true)));
supplier = new DiscoveryClientServiceInstanceListSupplier(discoveryClient,
environment);
StepVerifier.withVirtualTime(() -> {
when(discoveryClient.getInstances(SERVICE_ID)).thenReturn(
Lists.list(instance("1host", false), instance("2host-secure", true)));
supplier = new DiscoveryClientServiceInstanceListSupplier(discoveryClient,
environment);
supplier.get();
StepVerifier.withVirtualTime(() -> supplier.get()).expectSubscription()
.expectNext(Lists.list(instance("1host", false),
instance("2host-secure", true)))
.thenCancel().verify();
when(discoveryClient.getInstances(SERVICE_ID))
.thenReturn(Lists.list(instance("1host", false),
instance("2host-secure", true), instance("3host", false)));
StepVerifier.withVirtualTime(() -> supplier.get()).expectSubscription()
when(discoveryClient.getInstances(SERVICE_ID))
.thenReturn(Lists.list(instance("1host", false),
instance("2host-secure", true), instance("3host", false)));
return supplier.get();
}).expectSubscription()
.expectNext(Lists.list(instance("1host", false),
instance("2host-secure", true), instance("3host", false)))
.thenCancel().verify();