Skip to content

Commit 2535884

Browse files
committed
speedup tomcat startup
1 parent a36d80b commit 2535884

File tree

4 files changed

+151
-2
lines changed

4 files changed

+151
-2
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ COPY --from=overlay /tmp/cas-overlay/build/cas-resources/templates/ /data/templa
9191
#templates
9292
COPY --from=overlay /tmp/cas-overlay/build/cas-resources/templates/ /usr/local/tomcat/webapps/cas/WEB-INF/classes/templates/custom
9393
COPY rootfs /
94+
#catalina.properties skiplist
95+
RUN /usr/bin/scan.sh /usr/local/tomcat >>/usr/local/tomcat/conf/catalina.properties
9496

9597
EXPOSE 80
9698
EXPOSE 443

rootfs/usr/bin/scan.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#! /usr/bin/env bash
2+
# Script to create catalina tld scanning exclusion string
3+
# see http://skybert.net/java/improve-tomcat-startup-time/
4+
# by torstein.k.johansen@gmail.com
5+
set -o errexit
6+
set -o nounset
7+
set -o pipefail
8+
read_user_input() {
9+
tomcat_home=$1
10+
}
11+
12+
main() {
13+
read_user_input "$@"
14+
local jar_without_tld_list=
15+
16+
for f in $(find ${tomcat_home} -name "*.jar"); do
17+
if [[ $(unzip -v ${f} | grep '.tld$' | wc -l) -eq 0 ]]; then
18+
jar_without_tld_list="${jar_without_tld_list}$(basename $f)\n"
19+
fi
20+
done
21+
local result=
22+
for el in $(echo -e "$jar_without_tld_list" | sort | uniq); do
23+
if [ -n "${result}" ]; then
24+
result="${result},\\ \n${el}"
25+
else
26+
result="org.apache.catalina.startup.TldConfig.jarsToSkip=\\ \n${el}"
27+
fi
28+
done
29+
30+
echo -e "${result}"
31+
}
32+
33+
main "$@"
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
#
17+
# List of comma-separated packages that start with or equal this string
18+
# will cause a security exception to be thrown when
19+
# passed to checkPackageAccess unless the
20+
# corresponding RuntimePermission ("accessClassInPackage."+package) has
21+
# been granted.
22+
package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat.
23+
#
24+
# List of comma-separated packages that start with or equal this string
25+
# will cause a security exception to be thrown when
26+
# passed to checkPackageDefinition unless the
27+
# corresponding RuntimePermission ("defineClassInPackage."+package) has
28+
# been granted.
29+
#
30+
# by default, no packages are restricted for definition, and none of
31+
# the class loaders supplied with the JDK call checkPackageDefinition.
32+
#
33+
package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,\
34+
org.apache.jasper.,org.apache.naming.,org.apache.tomcat.
35+
36+
#
37+
#
38+
# List of comma-separated paths defining the contents of the "common"
39+
# classloader. Prefixes should be used to define what is the repository type.
40+
# Path may be relative to the CATALINA_HOME or CATALINA_BASE path or absolute.
41+
# If left as blank,the JVM system loader will be used as Catalina's "common"
42+
# loader.
43+
# Examples:
44+
# "foo": Add this folder as a class repository
45+
# "foo/*.jar": Add all the JARs of the specified folder as class
46+
# repositories
47+
# "foo/bar.jar": Add bar.jar as a class repository
48+
#
49+
# Note: Values are enclosed in double quotes ("...") in case either the
50+
# ${catalina.base} path or the ${catalina.home} path contains a comma.
51+
# Because double quotes are used for quoting, the double quote character
52+
# may not appear in a path.
53+
common.loader="${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar"
54+
55+
#
56+
# List of comma-separated paths defining the contents of the "server"
57+
# classloader. Prefixes should be used to define what is the repository type.
58+
# Path may be relative to the CATALINA_HOME or CATALINA_BASE path or absolute.
59+
# If left as blank, the "common" loader will be used as Catalina's "server"
60+
# loader.
61+
# Examples:
62+
# "foo": Add this folder as a class repository
63+
# "foo/*.jar": Add all the JARs of the specified folder as class
64+
# repositories
65+
# "foo/bar.jar": Add bar.jar as a class repository
66+
#
67+
# Note: Values may be enclosed in double quotes ("...") in case either the
68+
# ${catalina.base} path or the ${catalina.home} path contains a comma.
69+
# Because double quotes are used for quoting, the double quote character
70+
# may not appear in a path.
71+
server.loader=
72+
73+
#
74+
# List of comma-separated paths defining the contents of the "shared"
75+
# classloader. Prefixes should be used to define what is the repository type.
76+
# Path may be relative to the CATALINA_BASE path or absolute. If left as blank,
77+
# the "common" loader will be used as Catalina's "shared" loader.
78+
# Examples:
79+
# "foo": Add this folder as a class repository
80+
# "foo/*.jar": Add all the JARs of the specified folder as class
81+
# repositories
82+
# "foo/bar.jar": Add bar.jar as a class repository
83+
# Please note that for single jars, e.g. bar.jar, you need the URL form
84+
# starting with file:.
85+
#
86+
# Note: Values may be enclosed in double quotes ("...") in case either the
87+
# ${catalina.base} path or the ${catalina.home} path contains a comma.
88+
# Because double quotes are used for quoting, the double quote character
89+
# may not appear in a path.
90+
shared.loader=
91+
92+
# Default list of JAR files that should be scanned that overrides the default
93+
# jarsToSkip list above. This is typically used to include a specific JAR that
94+
# has been excluded by a broad file name pattern in the jarsToSkip list.
95+
# The list of JARs to scan may be over-ridden at a Context level for individual
96+
# scan types by configuring a JarScanner with a nested JarScanFilter.
97+
tomcat.util.scan.StandardJarScanFilter.jarsToScan=\
98+
log4j-taglib*.jar,\
99+
log4j-web*.jar,\
100+
log4javascript*.jar,\
101+
slf4j-taglib*.jar
102+
103+
# String cache configuration.
104+
tomcat.util.buf.StringCache.byte.enabled=true
105+
#tomcat.util.buf.StringCache.char.enabled=true
106+
#tomcat.util.buf.StringCache.trainThreshold=500000
107+
#tomcat.util.buf.StringCache.cacheSize=5000
108+
109+
# Disable use of some privilege blocks Tomcat doesn't need since calls to the
110+
# code in question are always already inside a privilege block
111+
org.apache.el.GET_CLASSLOADER_USE_PRIVILEGED=false
112+
113+
114+
# skip list generated

rootfs/usr/local/tomcat/conf/server.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
certificateChainFile="/etc/cert/chain.pem" />
2929
</SSLHostConfig>
3030
</Connector>
31-
<Engine name="Catalina" defaultHost="localhost">
31+
<Engine name="Catalina" defaultHost="localhost" startStopThreads="0">
3232
<Realm className="org.apache.catalina.realm.LockOutRealm">
3333
<!-- This Realm uses the UserDatabase configured in the global JNDI
3434
resources under the key "UserDatabase". Any edits
@@ -39,7 +39,7 @@
3939
</Realm>
4040

4141
<Host name="localhost" appBase="webapps"
42-
unpackWARs="true" autoDeploy="true">
42+
unpackWARs="false" autoDeploy="true" startStopThreads="0">
4343
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
4444
prefix="localhost_access_log" suffix=".txt"
4545
pattern="%h %l %u %t &quot;%r&quot; %s %b" />

0 commit comments

Comments
 (0)