You use Heroku to run web applications for free and easily, right? However, if you use it for free, if you leave the application for more than 30 minutes (no request), the server will go to sleep.
If you access the application after sleep, it will take some time for the response to come back. So, in order to shorten the startup time, I tried using GraalVM, which has been attracting attention recently, and Quarkus, which can run Java web applications on GraalVM.
This time I would like to compare how to run Quarkus on Heroku and the startup time with Spring Boot.
--Has a Heroku account
Please refer to the following article to create the application.
I tried the Java framework "Quarkus"
This time we'll use Heroku's container registry for the Docker registry.
Create the following file.
src/main/docker/Dockerfile.web
FROM registry.fedoraproject.org/fedora-minimal
WORKDIR /work/
COPY *-runner /work/application
RUN chmod 775 /work
EXPOSE 8080
CMD ["./application", "-Dquarkus.http.host=0.0.0.0", "-Dquarkus.http.port=${PORT}"]
-Dquarkus.http.port=${PORT}Is required to boot on the port specified on Heroku. It cannot be started without this.
By the way, you can change the launch port of the Quarkus app by changing the $ {PORT} part.
## Log in to the Heroku container
```console
heroku container:login
heroku create <Application name>
After that, please go with the project root.
heroku container:push -R -a <Application name>
heroku container:release web -a <Application name>
curl https://<Application name>.herokuapp.com/hello
Confirm that hello is output.
RestController
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@RequestMapping("hello")
public String home() {
return "hello";
}
}
Dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY target/app.jar app.jar
CMD ["java","-jar","app.jar","--server.port=${PORT}"]
** The following steps are the same as Quarkus, so they are omitted. ** **
Wait for the heroku server to look like this:
Execute the following command to measure.
curl https://<Quarkus application name>.herokuapp.com/hello -o /dev/null -w "%{time_starttransfer}\n" -s
7.038011
curl https://<Spring Boot application name>.herokuapp.com/hello -o /dev/null -w "%{time_starttransfer}\n" -s
15.208555
** Quarkus now boots in half the time of Spring Boot **
Recommended Posts