-
Notifications
You must be signed in to change notification settings - Fork 176
feat: add constraint stream profiling #1901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add constraint stream profiling #1901
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this in principle! When it comes to the implementation, I have concerns. See specifically the comment regarding profiling mode.
I also see this hooks itself into tuple lifecycle. But I don't see it tracking propagation overhead anywhere. Arguably it should.
The logging aspect is OK, but I am missing any methods to consume this information at runtime. How about Micrometer metrics? Or custom JFR events? Thinking out loud here: if it triggered an event (micrometer / JFR) every time it finished a single measurement, these could be aggregated at the end as well as queried in-flight. More often than not, we will be run in the platform - people will want a way of monitoring their solvers.
I question the name "profiling"; this doesn't use a profiler, and doesn't work in a way in which profilers work. The name should be changed in order to not invite confusing comparisons with actual profiling.
core/src/main/java/ai/timefold/solver/core/config/score/director/ConstraintProfilingMode.java
Outdated
Show resolved
Hide resolved
...src/test/java/ai/timefold/solver/core/preview/api/move/builtin/ListSwapMoveProviderTest.java
Outdated
Show resolved
Hide resolved
|
In regards to it tracking propagation overhead, it did in a previous implementation (by wrapping all the Propogators). However, this is a form of double counting; the Propogators fundamentally call lifecycles, which are profiled. Additionally, Propogators correspond to parents of nodes instead of nodes themselves, which can cause absurdities such as |
Not sure about that. These lifecycles count for a lot, true. But propagation also deals with the queues, and iterates a lot. IMO it's not necessarily a double count.
Which is another good argument that this should not profile per-method or per-line, but per-constraint. Doesn't matter which part takes such a long amount of time - it's the constraint that's what matters. |
491b14c to
ad8deff
Compare
|
This is what a profile looks like now: By location percentage may add up to over 100% due to node sharing; the rest should always add up to 100%. |
If we remove the package from this, suddenly this will be better readable. The packages are deprecated anyway. When they're gone though, it'll probably be useful to surround the constraint name with quotes. What does "work shared by" mean? I'd understand it if it were only for multiple constraints, but the same is used below when only one constraint is listed.
Wouldn't a breakdown by node/operation make sense here as well? Overall for the entire constraint provider, if 80 % is just joins, that's useful information.
I really don't like that it's there at all. It makes most of the output, you drown in the text, and apparently you also need to understand that the numbers there mean something else than everywhere else. This output doesn't help, only makes things more difficult. |
triceo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output could use being shorter and clearer.
The implementation around LifecycleKind needs rethinking.
core/src/main/java/ai/timefold/solver/core/impl/bavet/common/tuple/LeftTupleLifecycleImpl.java
Outdated
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/bavet/common/tuple/RightTupleLifecycleImpl.java
Outdated
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/bavet/common/AbstractNodeBuildHelper.java
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/bavet/common/LifecycleKind.java
Outdated
Show resolved
Hide resolved
Work performed exclusively by the listed group. When more than one constraint is in the group, that means they are sharing some node, and thus removing a constraint does not remove the work it does in the group (unless all constraints in the group are removed). When it is alone, it means the work done exclusively by a given constraint (where removing the constraint guarantees removing that work).
Acknowledged, but it is the raw captured data. The issue is if we try to humanize the number, then we need to ask questions such as do we convert it to minutes above a certain duration? Then hours? And then there the potential of losing accuracy and making comparisons between constraints harder (as you need to convert them to a common unit).
Useful infomation for who? This information also shows up in the location list.
This is the only text that is actually actionable by the user; it tells them what is actually hot in their code, and they don't need to do a string/constant lookup. |
Arguably if this case used different words, I wouldn't have to ask the question.
You already picked a common unit, just the worst one. :-) I see how this could possibly be hours, days. Or nanos. Practically, it won't be either. It will not be much less (who stops the solver after a millisecond?), and it will not be much more (who needs hours to establish these numbers?). IMO if we use seconds as a baseline, that's a reasonable estimate. Saying "5:25:00" (hms) also isn't too hard, if we decide we need to. The "problem" comes when the time is much smaller than a second - thankfully, it will not be.
You probably noticed that I don't like the location list.
Since it doesn't cross-link to code, you're copy-pasting anyway. IMO constraint names work much better; those will always be the same. With line numbers, you're making many assumptions; that the code over there is the same as the one you're looking at, that the code was compiled to include those line numbers, that no crazy tooling modified that code. (I love Lombok, which always points me to places that don't really exist.) I know that this is one way how you can report node sharing. IMO the downsides outweigh that; this will not be reliable, and only leads to questions. |
175885f to
bb327ad
Compare
triceo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once documented.
3f5c365 to
606a799
Compare
docs/src/modules/ROOT/pages/constraints-and-score/performance.adoc
Outdated
Show resolved
Hide resolved
docs/src/modules/ROOT/pages/constraints-and-score/performance.adoc
Outdated
Show resolved
Hide resolved
docs/src/modules/ROOT/pages/constraints-and-score/performance.adoc
Outdated
Show resolved
Hide resolved
docs/src/modules/ROOT/pages/constraints-and-score/performance.adoc
Outdated
Show resolved
Hide resolved
docs/src/modules/ROOT/pages/constraints-and-score/performance.adoc
Outdated
Show resolved
Hide resolved
Profiling constraints is notorishing difficult, since each component of a constraint are converted to nodes, some of which are shared. As such, a JVM method profile is basically unreadable and does not represent how much time is actually spent for each constraint. To aid in profiling, an optional constraintStreamProfilingEnabled configuration was added. If set to true, it wraps each tuple lifecycle node inside a ProfilingTupleLifecycle, which will measure how long each lifecycle executes. The ProfilingTupleLifecycle find out what constraint is responsible for creating that lifecycle by getting snapshot of the stack traces from its constraint stream's creator (when a constraint stream is shared, their stack traces are merged into the same set). At the end of solving, a profiling summary is then produced in the INFO log. timefold.solver.constraint-stream-profiling-mode was added as a property to Quarkus and Spring Boot to configure profiling (defaults to false).
f29c10b to
25d69ab
Compare
|




Profiling constraints is notorishing difficult, since each component of a constraint are converted to nodes, some of which are shared. As such, a JVM method profile is basically unreadable and does not represent how much time is actually spent for each constraint.
To aid in profiling, an optional constraintStreamProfilingMode configuration was added. If set to a value other than NONE, it wraps each tuple lifecycle node inside a ProfilingTupleLifecycle, which will measure how long each lifecycle executes. The ProfilingTupleLifecycle find out what constraint is responsible for creating that lifecycle by getting snapshot of the stack traces from its constraint stream's creator (when a constraint stream is shared, their stack traces are merged into the same set).
At the end of solving, a profiling summary is then produced in the INFO log. The details differ depending on the profiling mode:
In the BY_METHOD profiling mode, (className, methodName) is used as the key
In the BY_LINE profiling mode, (className, methodName, lineNumber) is used as the key.
The methods/lines are printed in descending order of time percentage spent. The sum of time percentage spent may be over 100%, since methods/lines can share time spent with other methods/lines.
timefold.solver.constraint-stream-profiling-mode was added as a property to Quarkus and Spring Boot to configure profiling (defaults to NONE).