Skip to content

Commit 5bfa796

Browse files
committed
docs: document the throttling feature of Enterprise Edition
1 parent 3aee054 commit 5bfa796

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

docs/src/modules/ROOT/pages/enterprise-edition/enterprise-edition.adoc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,3 +1030,52 @@ public class MyConstraintProvider implements ConstraintProvider {
10301030
This transformation means that debugging breakpoints placed inside the original `ConstraintProvider` will not be honored in the transformed `ConstraintProvider`.
10311031

10321032
From the above, you can see how this feature allows building blocks to share functionally equivalent parents, without needing the `ConstraintProvider` to be written in an awkward way.
1033+
1034+
1035+
[#throttlingBestSolutionEvents]
1036+
=== Throttling best solution events in `SolverManager`
1037+
1038+
This feature helps you avoid overloading your system with best solution events,
1039+
especially in the early phase of the solving process when the solver is typically improving the solution very rapidly.
1040+
1041+
To enable event throttling, use `ThrottlingBestSolutionConsumer` when starting a new `SolverJob` using `SolverManager`:
1042+
1043+
[source,java,options="nowrap"]
1044+
----
1045+
...
1046+
import ai.timefold.solver.enterprise.core.api.ThrottlingBestSolutionConsumer;
1047+
import java.time.Duration;
1048+
...
1049+
1050+
public class TimetableService {
1051+
1052+
private SolverManager<Timetable, Long> solverManager;
1053+
1054+
public String solve(Timetable problem) {
1055+
Consumer<Timetable> bestSolutionConsumer = ThrottlingBestSolutionConsumer.of(
1056+
solution -> {
1057+
// Your custom event handling code goes here.
1058+
},
1059+
Duration.ofSeconds(1)); // Throttle to 1 event per second.
1060+
1061+
String jobId = ...;
1062+
solverManager.solveBuilder()
1063+
.withProblemId(jobId)
1064+
.withProblem(problem)
1065+
.withBestSolutionConsumer(bestSolutionConsumer)
1066+
.run(); // Start the solver job and listen to best solutions, with throttling.
1067+
return jobId;
1068+
}
1069+
1070+
}
1071+
----
1072+
1073+
This will ensure that your system will never receive more than one best solution event per second.
1074+
Some other important points to note:
1075+
1076+
- If multiple events arrive during the pre-defined 1-second interval, only the last event will be delivered.
1077+
- When the `SolverJob` terminates, the last event received will be delivered regardless of the throttle,
1078+
unless it was already delivered before.
1079+
- If your consumer throws an exception, we will still count the event as delivered.
1080+
- If the system is too occupied to start and execute new threads,
1081+
event delivery will be delayed until a thread can be started.

docs/src/modules/ROOT/pages/using-timefold-solver/running-the-solver.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,3 +667,16 @@ More advanced implementations push the best solutions directly to the UI or a me
667667

668668
If the user is satisfied with the intermediate best solution
669669
and does not want to wait any longer for a better one, call `SolverManager.terminateEarly(problemId)`.
670+
671+
[NOTE]
672+
====
673+
Best solution events may be triggered in a rapid succession,
674+
especially at the start of solving.
675+
676+
Users of our xref:enterprise-edition/enterprise-edition.adoc[Enterprise Edition]
677+
may use the xref:enterprise-edition/enterprise-edition.adoc#throttlingBestSolutionEvents[throttling feature]
678+
to limit the number of best solution events fired over any period of time.
679+
680+
Community Edition users may implement their own throttling mechanism within the `Consumer` itself.
681+
====
682+

0 commit comments

Comments
 (0)