[native] Optimize Dockerfile#25487
Conversation
|
|
czentgr
left a comment
There was a problem hiding this comment.
Thanks for working on optimizing the image. I had some questions.
|
|
||
| EXPOSE 8080 | ||
|
|
||
| VOLUME ["/var/lib/presto/data"] |
There was a problem hiding this comment.
What would be mounted here? What is in this directory provided by the host?
How would a user use now that this is mounted?
There was a problem hiding this comment.
Based on the original Dockerfile which runs mkdir -p /var/lib/presto/data, I assume this is the default path for "persistent data of the application".
Refering to it as a VOLUME, it provides information to the image about the path that will be persisted by default, and when running a container, will create the volume in host by default.
Note that this will not mount the host directory, it will create a Docker volume matching that path inside the container.
https://docs.docker.com/build/building/best-practices/#volume
There was a problem hiding this comment.
If this cause any problems, we can get rid of it, no problem.
| VOLUME ["/var/lib/presto/data"] |
There was a problem hiding this comment.
Thanks, it should be ok persisting this. We should document this so a user can also mount this with the run command to a different place on the host.
| trap 'kill -TERM $app 2>/dev/null' TERM | ||
|
|
||
| $PRESTO_HOME/bin/launcher run | ||
| $PRESTO_HOME/bin/launcher run & |
There was a problem hiding this comment.
Can you explain a bit more on the benefit of this change? This installs the forward for TERM which previously should also be seen if the container is stopped?
wait also is terminated with TERM so why wasn't this happening for presto_server previously. Looks like you said it was waiting for a KILL?
There was a problem hiding this comment.
When you do docker stop, the container runtime by default will send a SIGTERM to the application.
In this case, the application is /bin/sh as we are running this entrypoint script, hence this script will receive the signal.
However, we want to send the signal to the application itself, otherwise it will keep running.
As the container runtime sees the container still running, after a timeout of 10 seconds, it will send a SIGKILL to force stop the application - this is why docker stop takes 10 seconds to stop the application.
Now, with this change, the script receives the signal (trap), and runs a function (send the signal to the running application), which in turn makes it shutdown.
Note, if there is another preferred signal to stop the application gracefully (eg. SIGINT, SIGUSR), we can change it.
There was a problem hiding this comment.
Also note, since we are not doing that much operation in this entrypoint script, we could also remove it and call directly the program as ENTRYPOINT in Dockerfile, so that remains as main PID.
The program receives any ENV previously defined, unless you had any experience with this failing...?
There was a problem hiding this comment.
@duhow Thanks for the explanation. So I was wondering if the 10s don't come from the config kShutdownOnsetSec. This is by default 10s. So even receiving the SIGTERM it will take 10s to actually shut down. basically, I think you are seeing expected behavior on docker stop with the main PID being presto_server.
The signal handler reacts on SIGINT and SIGTERM and stops it. The idea is to try and make sure that tasks complete.
So if the motivation was to reduce the docker stop time then the config is perhaps something to look at rather than changing the code here. Although the code change looks ok I'm not sure it does why you made the change originally.
There was a problem hiding this comment.
The change in here is because the presto_server does not receive any SIGINT or SIGTERM signal, so it won't know it has to shutdown when doing docker stop.
This change however makes that the signal is passed to the application, which then should do whatever it needs before closing - any change in the application to shutdown properly (if needed) should be in another PR.
There was a problem hiding this comment.
Understood. Actually, I was thinking of PrestoC++ but this is the python launcher for Presto Java which spawns the JVM.
|
There is an issue when publishing the docker image, seems related to the mount, since we will build the images simultaneously => |
czentgr
left a comment
There was a problem hiding this comment.
Please also squash the commits and change the commit message to have [native] as prefix because this PR only applies to Prestissimo.
|
|
||
| EXPOSE 8080 | ||
|
|
||
| VOLUME ["/var/lib/presto/data"] |
There was a problem hiding this comment.
Thanks, it should be ok persisting this. We should document this so a user can also mount this with the run command to a different place on the host.
|
@czentgr done 👍🏻 |
| trap 'kill -TERM $app 2>/dev/null' TERM | ||
|
|
||
| $PRESTO_HOME/bin/launcher run | ||
| $PRESTO_HOME/bin/launcher run & |
There was a problem hiding this comment.
Understood. Actually, I was thinking of PrestoC++ but this is the python launcher for Presto Java which spawns the JVM.
Description
Changes in
Dockerfilecommands to optimize the container image.Additionally, uses
trapto forward the TERM signal (stop) to the application, instead of waiting until KILL.Motivation and Context
💾 Saves ~500MB in Docker image, and makes updates even faster if reusing cached layers (eg. keep
javaversion)Impact
Pulling the image will be faster.
Test Plan
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.