Tomcat thread pool? Commented out in tomcat.conf, should I use it? - java

I really don't consider myself a java or tomcat expert. I have a vps with tomcat running on it. In the tomcat.conf file there is the following.
Notice that the Excecutor 'tomcatThreadPool' and corresponding Connector referencing that Executor is commented out.
At the risk of sounding very stupid...I'm going to ask this question...
With the Executor and Connector commented out, how are my servlets functioning? In other words, are they using a default thread pool? Or should I uncomment the Executor and Connector for servlet efficiency?
I guess I'm not very knowledgeable in this area at all....
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->

The Tomcat documentation of Executor says (emphasis is mine):
The Executor represents a thread pool that can be shared between
components in Tomcat. Historically there has been a thread pool per
connector created but this allows you to share a thread pool, between
(primarly) connector but also other components when those get
configured to support executors
So, you don't have to uncomment anything for Tomcat to work efficently, the Executor is for special needs as using more than one executor or using some thread pool yourself.
The referenced tomcat page is in the first results if you google "Tomcat Executor", by the way.

Related

Why does localhost work but external URL doesn't in tomcat?

My tomcat server is configured as this:
<Connector port="8080" protocol="HTTP/1.1"
address="192.168.122.15"
connectionTimeout="20000"
redirectPort="8443" />
When I try to access it via http://localhost:8080/{endpoint}, the operation works
When I use the external URL that's supposedly mapped to it: http://projecta.cave-gaming.com:8080/{endpoint}, it returns a 404 timeout error.
How do I map my tomcat server to the forwarded port so I can access it from an external URL?
Have you bind the server to locahost?
You can configure this using the address attribute like described here
You can do this in the server.xml
<Connector port="8080" protocol="HTTP/1.1" ...
If you omit the address attribute you are listening to all available addresses.

What are the threads with empty stack on tomcat 8.0 JVM?

I am diagnosing an unresponsive tomcat 8.0_29 instance (jdk1.8_93). Some threads are blocked but there are a lot of RUNNABLE threads (hundreds) with empty stacktrace.
Tomcat is running behind Apache http on different virtual machine.
Cennector config is as follows:
`
<Connector port="8443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
SSLEnabled="true" secure="true" enableLookups="false"
disableUploadTimeout="true"
keystoreFile="${catalina.home}/conf/server.jks"
keystorePass="xxxxxx"
acceptCount="100" maxThreads="25" scheme="https"
clientAuth="false" sslProtocol="TLSv1.2"/>
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"
acceptorThreadCount="2" maxThreads="300" acceptCount="200" minSpareThreads="20"
connectionTimeout="180000" keepAliveTimeout="180000" URIEncoding="ISO-8859-1" /> `
SSL termination is made by Apache son only calls through AJP reach Tomcat
Thread-41827 - priority:5 - threadId:0x00007f44e932f800 - nativeId:0xd7d - state:RUNNABLE
stackTrace:
java.lang.Thread.State: RUNNABLE
Many of them are named 'thread-$id', the rest are 'HandshakeCompletedNotify-Thread'
HandshakeCompletedNotify-Thread - priority:5 - threadId:0x00007f44fc841000 - nativeId:0x7565 - state:RUNNABLE
stackTrace:
java.lang.Thread.State: RUNNABLE
What are those threads?
Thanks a lot

secure AJP connector not rendering

We have a hybris server behind an apache web server that are linked with ajp connectors. This is working perfectly however for some reason after updating to hybris 5.3 (and tomcat 7) the secure ajp connector is not rendering.
In the hybris tomcat config folder we have this in the server.xml:
${tomcat.connectors.ajp.plain}
which renders on ant clean all to this in the platform server.xml
<Connector protocol="AJP/1.3" port="8009" proxyPort="80" redirectPort="443" />
this works for non secure connections however we need to also render the secure connector:
<Connector protocol="AJP/1.3" port="8010" proxyPort="443" scheme="https" secure="true" />
I could just hard code this into the server.xml but that doesn't seem like the best way to do it. and I can't find where ${tomcat.connectors.ajp.plain} is actually rendered. Is there a similar property somewhere that will render the secure connector using the ports defined in the local.properties?
I'm afraid you have to declare it manually in your server.xml template in the configuration directory.
In actual fact, I prefer to do this for both AJP connectors as the templated one injected by the variable you mention is not very well configured and I have seen significant performance issues as a result. For example the number of threads is not specified and it is not associated with an executor. This means that when under large load, the number of active threads can grow to a silly number and cause the whole thing to fall over.
In fact, below is a snippet of the config/tomcat/conf/server.xml I use, which I have developed over 7 years of working exclusively on Hybris. Not only does it have sensible configurations, it also uses the more performant non-blocking IO protocols.
Hope this helps.
<Executor name="hybrisExecutor"
namePrefix="hybrisHTTP"
maxThreads="${tomcat.maxthreads}"
minSpareThreads="${tomcat.minsparethreads}"
maxIdleTime="${tomcat.maxidletime}"/>
<Connector port="${tomcat.http.port}"
maxHttpHeaderSize="8192"
maxThreads="${tomcat.maxthreads}"
protocol="org.apache.coyote.http11.Http11NioProtocol"
executor="hybrisExecutor"
enableLookups="false"
acceptCount="${tomcat.acceptcount}"
connectionTimeout="20000"
URIEncoding="UTF-8"
disableUploadTimeout="true" />
<Connector port="${tomcat.ssl.port}"
maxHttpHeaderSize="8192"
maxThreads="${tomcat.maxthreads}"
protocol="org.apache.coyote.http11.Http11NioProtocol"
executor="hybrisExecutor"
enableLookups="false"
acceptCount="${tomcat.acceptcount}"
connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="UTF-8"
SSLEnabled="true"
scheme="https"
secure="true"
clientAuth="false"
sslProtocol="TLS"
keystoreFile="${catalina.home}/lib/keystore"
keystorePass="123456" />
<!--
We explicitly declare the AJP connectors as we want to separate HTTP and SSL traffic and the default connector setting Hybris provides is not good enough.
-->
<Connector protocol="org.apache.coyote.ajp.AjpNioProtocol"
executor="hybrisExecutor"
enableLookups="false"
acceptCount="${tomcat.acceptcount}"
connectionTimeout="120000"
maxThreads="${tomcat.maxthreads}"
port="${tomcat.ajp.port}"
proxyPort="${proxy.http.port}"
redirectPort="${proxy.ssl.port}"
URIEncoding="UTF-8"
useIPVHosts="${tomcat.ajp.useipv}" />
<Connector protocol="org.apache.coyote.ajp.AjpNioProtocol"
executor="hybrisExecutor"
enableLookups="false"
acceptCount="${tomcat.acceptcount}"
connectionTimeout="120000"
maxThreads="${tomcat.maxthreads}"
port="${tomcat.ajp.secureport}"
proxyPort="${proxy.ssl.port}"
redirectPort="${proxy.http.port}"
scheme="https"
secure="true"
URIEncoding="UTF-8"
useIPVHosts="${tomcat.ajp.useipv}" />
The variables are just properties you declare in local.properties. They are substituted at build time by the ant deploy task when it builds the actual server.xml in the platform tomcat directory.
I think you should try with:
<Connector
protocol="AJP/1.3"
port="8010"
connectionTimeout="20000"
scheme="https"
SSLEnabled="true"
secure="true"
maxThreads="200"
proxyPort="443"/>

How to run multiple servlets execution in parallel for Tomcat?

I have a Tomcat application, I need two different servlets or the same one to respond in parallel to my requests. The case is I have a first request asking to download medical imaging and I have another AJAX client request fetching images before the first request is completely done. But for some reason, the server does not respond to my second request until the first one is over.
What has to be changed in order to achieve concurrent servlets execution? We have a pretty good server with multiple drives, multiple cores. I'm using Tomcat 6. Any ideas to explore would be great.
If that happens it's not about Tomcat. Probably you're using synchronization (implicitly or explicitly) somewhere.
However you can manage thread-pooling expicitly:
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
or
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
I.e. you can either specify the number of max threads or use a thread-pool. More information here http://tomcat.apache.org/tomcat-5.5-doc/config/http.html

NIO Connector in Tomcat

I'm trying to enable NIO Connector in Tomcat 6.0 by configuring server.xml file, but I'm getting Firefox can't establish a connection to the server at localhost:8081. in the browser whenever I type localhost:8081.
This is how I've configured NIO connector in Tomcat 6.0. May I know what's the problem?
<Connector connectionTimeout="20000" port="8081" protocol="org.apache.
coyote.http11.Http11NioProtocol" redirectPort="8443"/>
I've tried your tag on my server.
Your Connector tag has one unnecessary space between apache. and coyote
Remove it or try with the one below.
<Connector connectionTimeout="20000" port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>
It should start up.

Categories