Tomcat Server Docker
Tomcat startup time is reduced by ~30% by enabling the Shared Class Cache (SCC) in the Docker images.
- Tomcat Server Dockery
- Server.tomcat.max-threads Docker
- Run Tomcat Server Docker
- Tomcat Server Docker Free
In my earlier blog , I measured the Performance of Tomcat with Tradelite7 Application without using any docker images and we saw the boost of Startup time with default Shared Cache in OpenJ9. In this article, let’s do some experiments using docker images of Tomcat and how the Shared Class Cache affects the Startup Performance.
This Video shows how to start running tomcat inside Docker Container and also shows how to run multiple tomcat instance's on docker.1.) How to commit the con.
As default SCC with OpenJ9 is disabled when running in Docker, we need to explicitly enable SCC. If we enable SCC in runtime, the caching classes and AoT doesn’t persist in docker when it stops. So, one way to get the SCC improvements is by populating SCC during build time.
Congratulations, you have successfully installed the docker-compose and ran the tomcat application with mysql database using docker-compose. The Startup Medium's largest active publication. Docker 安装 Tomcat 方法一、docker pull tomcat 查找 Docker Hub 上的 Tomcat 镜像: 可以通过 Sort by 查看其他版本的 tomcat，默认是最新版本 tomcat:latest。 此外，我们还可以用 docker search tomcat 命令来查看可用版本： [email protected]:/tomcat$ docker search tomcat NAME. Minimal Docker file where the Connect2id server is the sole application in Apache Tomcat. Login page, other UIs and web hook based components are deployed separately. Estricatemente speaking Tomcat is not a server but transforms the caught JPS into servlets that can serve the application in question. On the other hand, Apache Tomcat is open source and can be installed on any system running Java. Deploy Apache Tomcat with Docker Compose 1.- Install Docker on Linux.
In this article, I will show how to create an SCC during build and compare the Performance with “No SCC” and “explicit SCC” for Tomcat with OpenJ9.
To start with, I picked the Dockerfile of Tomcat 9 for OpenJ9 from Tomcat Docker library and used it to build the default Tomcat docker images which has “No SCC”.
Now, we have to create a docker image which uses SCC with OpenJ9.
For that, following modifications are done in Docker file
- Add JAVA_OPTS which has SharedClassCache related options. -Xshareclasses:name=tomcat_scc,cacheDir=/tmp,enableBCI -Xscmx20M
- Do a cold Tomcat Startup run as part of build itself. This helps in creating the SCC required.
- Now, change the JAVA_OPTS to make -Xshareclasses flag readonly. , to avoid any AOT that happens at the start of container as it doesn’t give any benefit to the container.
Below are the lines I added in Dockerfile for above instructions. (just before the EXPOSE 8080 command)
With the above changes in Dockerfile, we can build an image which uses SCC with OpenJ9. I also created an another image which runs the tomcat Server for 10 times (instead of one time as mentioned in above snippet) to populate the SCC – only to check if that can improve more Startup time.
To calculate the Startup time and Footprint, below methods are used:
- For Startup time: Need to mount the logs directory of the container into your server and Use the log (catalina.out) generated by the server and look for
INFO [main] org.apache.catalina.startup.Catalina.start Server startup in **** milliseconds.
- For Footprint: I initially used docker stats to collect the Memory_Usage of a container. Because docker stats doesn’t add up Cache memory, the docker with SCC showed lesser memory_usage (which is not we are looking for!)
So, I had to measure it by summing up RSS of a process and Huge pages used (if enabled). RSS of a process is calculated using “ps -p <pid> -o rss”. Huge Pages used is the difference of the value from “/proc/meminfo” before and after the tomcat Startup.
The command below is used to start the docker container:
Below are the results of Startup and Footprint from my experiments:
Tomcat Server Dockery
Above graphs Y-axis uses normalized data since it’s the relative picture that matters.
From the graph data above, OpenJ9-ExplicitSCC(with 10 warm-ups during build) didn’t help much in reducing the Startup time as OpenJ9-ExplicitSCC (which does a single run during build) also gave similar results.
Size of docker images (on disk) with tomcat using ExplicitSCC and the original one are:
All Above experiments are done on a machine with following config
- CPU Type: Intel(R) Xeon(R) Gold 6126 CPU @ 2.60GHz
- 24 physical, 48 logical processors.
- Pinned 4 processors to the server during the run. (used numactl — physcpubind=0–3 — membind=0)
- From the data we got, we can confirm that OpenJ9 with SCC has an out-of-box ~30% reduced Startup time with only 2% increase in Footprint against no SCC.
- Because of this reduced Startup time, the Tomcat community should perhaps consider adding a step to create an SCC by doing a single start of Tomcat Server during build into their OpenJ9 based docker images.
Docker has become so widely accepted that I wanted to give it a serious try. Many times I am faced with the situation to define a typical web infrastructure to host multiple web applications. A typical minimal configuration consists of an Apache http Server and multiple Tomcat instances hosting different applications.
After I had played around with Docker images and containers I digged into docker-compose to define and link multiple docker containers.
Build your docker images
Initially you would have a look at some public docker repository to see whether appropriate container definitions are available for your purpose.
I haven’t been successful finding the right ones yet so I just created my own docker files based on already existing definitions.
Linking the good old Apache with Tomcat is quite straightforward via the use of the mod_jk module and the AJP connector in Tomcat.
So it would be helpful to have an Apache Web Server container with mod_jk already installed.
Dockerfile for httpd
Dockerfile for Tomcat
For a Tomcat container I extend an already existing definition and additionally expose its AJP port 8009.
After building the images they would become available in my local repository.
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
mg tomcat ff21e2bb0767 2 weeks ago 350 MB
mg httpd eb2ff0c48096 2 weeks ago 220.1 MB
tomcat latest 52ae4ebca944 2 weeks ago 350 MB
ubuntu latest e9aeff8e9dd1 2 weeks ago 187.9 MB
All containers have to be defined in a YAML file docker-compose.yml which looks as follows.
3 different Tomcat based containers – portalapp, searchapp, businessapp – and an Apache Webserver – http – hosting individual applications. All Tomcat containers expose their 8009 port so AJP connectivity is possible. Via data volumes directive we provide mount points so externally provided web applications may be deployed to the Tomcat instances.
The Apache Webserver container makes its http-port 80 available to the public via its ports directive. Quite a few mount points are defined to configure mod_jk and the webserver itself.
The above configuration is based on the following directory structure
We need to tell Apache via mod_jk how to connect to the individual tomcat instances.
For this purpose we provide necessary configuration via worker.properties and jk.conf.
In this configuration file we define the necessary workers, one for each tomcat instance we need to connect to. If you have a look at the
host definitions you will recognize that we use the container names defined in the docker-compose.yml file appended with the network name ‘webfrastructure’.
In this configuration file we mount the URIs of our applications to the corresponding workers so each URI is served by its corresponding tomcat instance.
Finally we are able to run our docker containers in its isolated network.
> docker-compose --x-networking up -d
and end up as depicted as follows.
Run Tomcat Server Docker
Now we are able to access our applications from the given URLs
Tomcat Server Docker Free
If you want to learn more about Docker Compose, just head over to the official documentation at https://docs.docker.com/compose/.