Skip to content

Commit 87e5d7a

Browse files
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
1 parent 587f5f5 commit 87e5d7a

File tree

7 files changed

+22
-23
lines changed

7 files changed

+22
-23
lines changed

docs/src/main/asciidoc/_configprops.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
|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.
3030
|spring.cloud.loadbalancer.cache.caffeine.spec | | The spec to use to create caches. See CaffeineSpec for more details on the spec format.
3131
|spring.cloud.loadbalancer.cache.capacity | 256 | Initial cache capacity expressed as int.
32-
|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>
32+
|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>
3333
|spring.cloud.loadbalancer.health-check.initial-delay | 0 | Initial delay value for the HealthCheck scheduler.
34-
|spring.cloud.loadbalancer.health-check.interval | 30s | Interval for rerunning the HealthCheck scheduler.
34+
|spring.cloud.loadbalancer.health-check.interval | 25s | Interval for rerunning the HealthCheck scheduler.
3535
|spring.cloud.loadbalancer.health-check.path | |
3636
|spring.cloud.loadbalancer.retry.enabled | true |
3737
|spring.cloud.loadbalancer.ribbon.enabled | true | Causes `RibbonLoadBalancerClient` to be used by default.

docs/src/main/asciidoc/spring-cloud-commons.adoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ You can set your own `ttl` value (the time after write after which entries shoul
882882
as the value of the `spring.cloud.loadbalancer.cache.ttl` property.
883883
You can also set your own LoadBalancer cache initial capacity by setting the value of the `spring.cloud.loadbalancer.cache.capacity` property.
884884

885-
The default setup includes `ttl` set to 30 seconds and the default `initialCapacity` is `256`.
885+
The default setup includes `ttl` set to 35 seconds and the default `initialCapacity` is `256`.
886886

887887
You can also altogether disable loadBalancer caching by setting the value of `spring.cloud.loadbalancer.cache.enabled`
888888
to `false`.
@@ -951,7 +951,7 @@ We suggest passing a `DiscoveryClientServiceInstanceListSupplier` delegate in th
951951

952952
You could use this sample configuration to set it up:
953953

954-
[[zoned-based-custom-loadbalancer-configuration]]
954+
[[health-check-based-custom-loadbalancer-configuration]]
955955
[source,java,indent=0]
956956
----
957957
public class CustomLoadBalancerConfiguration {
@@ -962,12 +962,13 @@ public class CustomLoadBalancerConfiguration {
962962
return ServiceInstanceListSupplier.builder()
963963
.withDiscoveryClient()
964964
.withHealthChecks()
965-
.withCaching()
966965
.build(context);
967966
}
968967
}
969968
----
970969

970+
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`.
971+
971972
TIP:: In order to make working on your own LoadBalancer configuration easier, we have added a `builder()` method to the `ServiceInstanceListSupplier` class.
972973

973974
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.

spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static class HealthCheck {
5454
/**
5555
* Interval for rerunning the HealthCheck scheduler.
5656
*/
57-
private Duration interval = Duration.ofSeconds(30);
57+
private Duration interval = Duration.ofSeconds(25);
5858

5959
private Map<String, String> path = new LinkedCaseInsensitiveMap<>();
6060

spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/SimpleBootstrapPropertySource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
/**
2424
* Simple, non-enumerable PropertySource wrapper.
25+
*
2526
* @author Ryan Baxter
2627
*/
2728
public class SimpleBootstrapPropertySource<T> extends PropertySource<T> {

spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/cache/LoadBalancerCacheProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class LoadBalancerCacheProperties {
3939
* @see <a href=
4040
* "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>
4141
*/
42-
private Duration ttl = Duration.ofSeconds(30);
42+
private Duration ttl = Duration.ofSeconds(35);
4343

4444
/**
4545
* Initial cache capacity expressed as int.

spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/DiscoveryClientServiceInstanceListSupplier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public DiscoveryClientServiceInstanceListSupplier(DiscoveryClient delegate,
4747
Environment environment) {
4848
this.serviceId = environment.getProperty(PROPERTY_NAME);
4949
this.serviceInstances = Flux
50-
.defer(() -> Flux.fromIterable(delegate.getInstances(serviceId))
51-
.collectList().flux().subscribeOn(Schedulers.boundedElastic()));
50+
.defer(() -> Flux.just(delegate.getInstances(serviceId)))
51+
.subscribeOn(Schedulers.boundedElastic());
5252
}
5353

5454
public DiscoveryClientServiceInstanceListSupplier(ReactiveDiscoveryClient delegate,

spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/DiscoveryClientServiceInstanceListSupplierTests.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,18 @@ void shouldReturnRetrievedInstancesBlockingClient() {
109109

110110
@Test
111111
void shouldUpdateReturnRetrievedInstancesBlockingClient() {
112-
when(discoveryClient.getInstances(SERVICE_ID)).thenReturn(
113-
Lists.list(instance("1host", false), instance("2host-secure", true)));
114-
supplier = new DiscoveryClientServiceInstanceListSupplier(discoveryClient,
115-
environment);
116-
117-
StepVerifier.withVirtualTime(() -> supplier.get()).expectSubscription()
118-
.expectNext(Lists.list(instance("1host", false),
119-
instance("2host-secure", true)))
120-
.thenCancel().verify();
121-
122-
when(discoveryClient.getInstances(SERVICE_ID))
123-
.thenReturn(Lists.list(instance("1host", false),
124-
instance("2host-secure", true), instance("3host", false)));
112+
StepVerifier.withVirtualTime(() -> {
113+
when(discoveryClient.getInstances(SERVICE_ID)).thenReturn(
114+
Lists.list(instance("1host", false), instance("2host-secure", true)));
115+
supplier = new DiscoveryClientServiceInstanceListSupplier(discoveryClient,
116+
environment);
117+
supplier.get();
125118

126-
StepVerifier.withVirtualTime(() -> supplier.get()).expectSubscription()
119+
when(discoveryClient.getInstances(SERVICE_ID))
120+
.thenReturn(Lists.list(instance("1host", false),
121+
instance("2host-secure", true), instance("3host", false)));
122+
return supplier.get();
123+
}).expectSubscription()
127124
.expectNext(Lists.list(instance("1host", false),
128125
instance("2host-secure", true), instance("3host", false)))
129126
.thenCancel().verify();

0 commit comments

Comments
 (0)