Skip to content
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

Restarts are slow when using spring-boot-devtools and spring-boot-docker-compose #35435

Closed
joshlong opened this issue May 15, 2023 · 4 comments
Closed
Labels
type: bug A general bug
Milestone

Comments

@joshlong
Copy link
Member

not sure if this is a bug but it's interesting. you can see it in (in)action here https://github.com/spring-tips/development-containers-with-docker-compose-and-testcontainers

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 15, 2023
@wilkinsona
Copy link
Member

We call docker compose ps twice during a restart – once for hasRunningServices() and once for getRunningServices() – and it isn't particularly quick. With a single service running, time docker compose ps shows a total time of roughly 0.5 seconds on the first call. Subsequent calls are quicker at around 0.15 seconds. Perhaps we can rework things so that we make a single call to docker compose ps.

@wilkinsona wilkinsona removed the status: waiting-for-triage An issue we've not yet triaged label May 16, 2023
@wilkinsona wilkinsona changed the title docker compose + devtools takes about a second to restart vs 0.2s with testcontainers Restarts are slow when using spring-boot-devtools and spring-boot-docker-compose May 16, 2023
@wilkinsona wilkinsona added the type: bug A general bug label May 16, 2023
@wilkinsona wilkinsona added this to the 3.1.x milestone May 16, 2023
@wilkinsona
Copy link
Member

wilkinsona commented May 16, 2023

Creating a new DockerCli instance is also quite slow, in particular the calls to getDockerCommand(this.processRunner) and getDockerComposeCommand(this.processRunner). Each takes ~0.3s. We may be able to cache these in static fields so that they're reused across restarts.

Waiting for the services to be ready is also rather slow even though, in this case, there's only a single service. When checking that Postgres is ready, the read timeout in TcpConnectServiceReadinessCheck pops and it this point we determine that the service is ready. This accounts for 0.2s of the restart time.

@wilkinsona
Copy link
Member

wilkinsona commented May 16, 2023

https://github.com/wilkinsona/spring-boot/tree/gh-35435 addresses the things described above other than the readiness check.

philwebb added a commit that referenced this issue May 17, 2023
Update `DockerCli` so that the docker commands are cached. This helps
improve startup time when using devtools with docker compose.

See gh-35435
philwebb pushed a commit that referenced this issue May 17, 2023
Update `DockerComposeLifecycleManager` so that `docker ps` is
not called multiple times.

See gh-35435
philwebb added a commit that referenced this issue May 17, 2023
Default 'spring.docker.compose.readiness.wait' to `ONLY_IF_STARTED`
when using devtools.

See gh-35435
@philwebb
Copy link
Member

Doing three devtools restarts...

Before:

2023-05-17T15:52:53.275-07:00  INFO 63496 --- [  restartedMain] com.example.demo.DemoApplication         : Started DemoApplication in 2.101 seconds (process running for 19.261)
2023-05-17T15:52:58.933-07:00  INFO 63496 --- [  restartedMain] com.example.demo.DemoApplication         : Started DemoApplication in 1.185 seconds (process running for 24.919)
2023-05-17T15:53:03.614-07:00  INFO 63496 --- [  restartedMain] com.example.demo.DemoApplication         : Started DemoApplication in 1.21 seconds (process running for 29.6)

After:

2023-05-17T15:54:36.074-07:00  INFO 63657 --- [  restartedMain] com.example.demo.DemoApplication         : Started DemoApplication in 0.704 seconds (process running for 10.27)
2023-05-17T15:54:46.307-07:00  INFO 63657 --- [  restartedMain] com.example.demo.DemoApplication         : Started DemoApplication in 0.717 seconds (process running for 20.503)
2023-05-17T15:54:55.442-07:00  INFO 63657 --- [  restartedMain] com.example.demo.DemoApplication         : Started DemoApplication in 0.632 seconds (process running for 29.638)

@philwebb philwebb modified the milestones: 3.1.x, 3.1.0 May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants