Home > Enterprise >  Spring drastically slows down score evaluation speed of Optaplanner solver
Spring drastically slows down score evaluation speed of Optaplanner solver

Time:05-09

I have a following piece of code

@SpringBootApplication
public class ServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ServerApplication.class, args);

        OptimalTerminationTimeFinder.findOptimalTerminationTime(
            8,
            10,
            50,
            Duration.ofSeconds(1),
            Duration.ofMillis(250));
}

where OptimalTerminationFinder solves hundreds of problems and tries to find the best termination time for a given problem size.

The problem is that when I comment the annotation @SpringBootApplication, the score evaluation speed increases from 40k to 80k and vice versa.

Why is Spring slowing down the solver so much? I read the user guide for Spring and the only difference is that they use a SolverManager but that's not the problem, is it? I just use the Solver class.

I cannot afford such a drastic speed decrease with Spring - the time difference is crucial at the production.

CodePudding user response:

I reproduced the performance difference with java-spring-boot quickstart.

I believe the slower calculation speed is somehow caused by running the application using the spring-boot-maven-plugin (I assume the plugin is also used by your IDE if you try to run a @SpringBootApplication annotated class).

If you first build an executable JAR of your project and then run the JAR either in your IDE or from the terminal using java -jar ..., you'll see the full speed score calculation.

I don't have an explanation of why the Spring Boot Maven Plugin prevents full performance but the production build of your application won't suffer from that.

CodePudding user response:

I bet it's the logging. They probably differ by default between spring and plain java (so Yurloc's answer is correct). Check the logging levels and appenders for both runs.

I've seen the score calculation speed drop by a factor of 2x or more:

  • Category org.optaplanner from DEBUG to TRACE logging can be a 4x drop. It depends.
  • Category org.optaplanner from INFO to DEBUG logging can be a 2x drop. It depends.
  • Category org.drools from WARN to DEBUG can be a 10x drop. It depends.
  • Appender from console to file logging can be a 2x drop. It depends.
  • Related