Skip to content

Commit

Permalink
Change the default polling trigger to 1 second (#8751)
Browse files Browse the repository at this point in the history
* Change the default polling trigger to 1 second

The current default trigger for the poller is 10 milliseconds fixed delay.
This is very tight policy for Microservices where we might not have too many
scheduled threads to distribute polling endpoint jobs evenly.

* Change the default trigger to 1 second to align with what Spring Boot already
claims.
Same 1 second policy is used in Spring Cloud Stream as well

* Fix language in Docs

Co-authored-by: Gary Russell <grussell@vmware.com>

---------

Co-authored-by: Gary Russell <grussell@vmware.com>
  • Loading branch information
artembilan and garyrussell committed Oct 9, 2023
1 parent fa06940 commit af609ca
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public abstract class AbstractPollingEndpoint extends AbstractEndpoint implement
/**
* A default polling period for {@link PeriodicTrigger}.
*/
public static final long DEFAULT_POLLING_PERIOD = 10;
public static final long DEFAULT_POLLING_PERIOD = 1000;

private final Collection<Advice> appliedAdvices = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,16 @@ public void testBridgeAnnotations() {
assertThat(testMessage).isSameAs(receive);
assertThat(this.bridgeOutput.receive(10)).isNull();

PollingConsumer pollableBridge = this.context.getBean("pollableBridge", PollingConsumer.class);
PeriodicTrigger periodicTrigger = TestUtils.getPropertyValue(pollableBridge, "trigger", PeriodicTrigger.class);
assertThat(periodicTrigger.getPeriodDuration()).isEqualTo(Duration.ofSeconds(1));

this.pollableBridgeInput.send(testMessage);
receive = this.pollableBridgeOutput.receive(10_000);
assertThat(receive).isNotNull();
assertThat(testMessage).isSameAs(receive);
assertThat(this.pollableBridgeOutput.receive(10)).isNull();


assertThatExceptionOfType(MessageDeliveryException.class)
.isThrownBy(() -> this.metaBridgeInput.send(testMessage))
.withMessageContaining("Dispatcher has no subscribers");
Expand Down Expand Up @@ -948,7 +951,8 @@ public PollableChannel pollableBridgeInput() {


@Bean
@BridgeFrom(value = "pollableBridgeInput", poller = @Poller(fixedDelay = "1000"))
@BridgeFrom(value = "pollableBridgeInput", poller = @Poller)
@EndpointId("pollableBridge")
public QueueChannel pollableBridgeOutput() {
return new QueueChannel();
}
Expand Down
2 changes: 2 additions & 0 deletions src/reference/antora/modules/ROOT/pages/channel-adapter.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ See also xref:channel-adapter.adoc#channel-adapter-expressions-and-scripts[Chann
NOTE: If no poller is provided, then a single default poller must be registered within the context.
See xref:endpoint.adoc#endpoint-namespace[Endpoint Namespace Support] for more detail.

NOTE: The default trigger for polling endpoint is a `PeriodicTrigger` instance with a 1 second fixed delay period.

[IMPORTANT]
.Important: Poller Configuration
=====
Expand Down
3 changes: 2 additions & 1 deletion src/reference/antora/modules/ROOT/pages/endpoint.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ PollingConsumer consumer = new PollingConsumer(channel, exampleHandler);
NOTE: For more information regarding polling consumers, see xref:overview.adoc#overview-endpoints-channeladapter[Channel Adapter] and xref:channel-adapter.adoc#channel-adapter[Channel Adapter].

There are many other configuration options for the polling consumer.
For example, the trigger is a required property.
The following example shows how to set the trigger:

[source,java]
Expand Down Expand Up @@ -112,6 +111,8 @@ CronTrigger trigger = new CronTrigger("*/10 * * * * MON-FRI");

The result of the trigger defined in the previous example is a trigger that triggers every ten seconds, Monday through Friday.

NOTE: The default trigger for polling endpoint is a `PeriodicTrigger` instance with a 1 second fixed delay period.

In addition to the trigger, you can specify two other polling-related configuration properties: `maxMessagesPerPoll` and `receiveTimeout`.
The following example shows how to set these two properties:

Expand Down
3 changes: 3 additions & 0 deletions src/reference/antora/modules/ROOT/pages/whats-new.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ See xref:gateway.adoc#gateway-no-response[Gateway Behavior When No response Arri
- The `LockRegistry` provides template-like API to execute provided task while locked.
See xref:distributed-locks.adoc[Distributed Locks] for more information.

- The default trigger for polling endpoint is now a `PeriodicTrigger` instance with a 1 second fixed delay period; previously, the default was 10 milliseconds.
See xref:endpoint.adoc#endpoint-pollingconsumer[Polling Consumer] for more information.

[[x6.2-websockets]]
=== WebSockets Changes

Expand Down

0 comments on commit af609ca

Please sign in to comment.