Use the Correct NIO Protocol Connector in Confluence to Improve Performance

Still need help?

The Atlassian Community is here for you.

Ask the community

Confluence 5.8 or later versions shipped with NIO protocol connector by default. However, if you are upgrading from versions prior to Confluence 5.8 whilst maintaining the Tomcat configurations, you need to make sure you're using the NIO connector for better performance.

For Confluence 6 and up, we recommend using the NIO2 version, which is the latest iteration of this protocol.


Symptoms

Confluence becomes unresponsive during periods of high load. Given a little time, the instance may recover naturally and become usable again without having to restart. Profiling tools will show that the majority of tomcat HTTP threads are busy and CPU usage is high. Thread dumps will contain a lot of stacktraces with the following:

apache.coyote.http11.InternalInputBuffer.parseRequestLine

You will see a different stack trace if you use the AJP Connector in your instance. Please take note of the resolution for the AJP protocol depending on the version of Tomcat in use within your instance of Tomcat.

Cause

By default Confluence uses the Coyote Connector, along with a 20 second timeout.

This is the default connector in Confluence 5.5.4 and all following versions:

<Connector port="8090" connectionTimeout="20000" redirectPort="8443"
	maxThreads="48" minSpareThreads="10"
    enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8" />

This is the default connector from before Confluence 5.5.4:

<Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8090" minProcessors="5"
	maxProcessors="75"
	enableLookups="false" redirectPort="8443" acceptCount="10" debug="0" connectionTimeout="20000"
	useURIValidationHack="false" URIEncoding="UTF-8"/>

When a request is made to the server, Confluence will provide that request a thread, meaning there will be one thread consumed per concurrent connection. If the connection is used just enough to not trigger the timeout (20 seconds by default), the thread will be continually held by this connection and wasted.

Under high load this can result in connections that are consuming server resources and preventing them from being used by other HTTP threads for long periods, even if they are doing very little.

Workaround

  • The following workaround should be thoroughly tested in a test instance before being applied to a production instance.
  • Please be aware that this material is provided for your information only and that you use it at your own risk.
  • You should only use this workaround if you're running Java version 7 Update 25 or higher. Confluence 4.2 was the first version of Confluence that supported Java version 7.
  • Shut down Confluence
  • Locate server.xml, in your <installation_directory>/conf/ folder; and open it in a text editor
  • Locate your connector - it will be similar to the connector shown above

    In Confluence 5.5.4 and beyond, Tomcat will be configured to use the default http11protocol connector. However, you can add protocol="org.apache.coyote.http11.Http11NioProtocol" to the connector. If you do not use the HTTP Connector but use the AJP Connector instead, use the AJP NIO protocol instead.

    WARNING

    It is not recommended to use the AJP connector in your environment as the HTTP Connector is preferred. Using the HTTP Connector will provide better performance, stability and the ability to easily enable HTTP/2 when this is commonly available in Tomcat 9. Clients are advised not to use the AJP Connector as this will suffer performance penalties and will not allow you to easily migrate to HTTP/2 in future.

    Here's the default connector, using the HTTP/HTTPS NIO2 Connector - notice the protocol attribute:

    <Connector port="8090" connectionTimeout="20000" redirectPort="8443"
    	maxThreads="48" minSpareThreads="10"
        enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8"
        protocol="org.apache.coyote.http11.Http11Nio2Protocol" />
    <Connector port="8443" maxHttpHeaderSize="8192"
                       maxThreads="150" minSpareThreads="25"
                       protocol="org.apache.coyote.http11.Http11Nio2Protocol"
                       enableLookups="false" disableUploadTimeout="true"
                       acceptCount="100" scheme="https" secure="true"
                       clientAuth="false" sslProtocol="TLSv1.2" sslEnabledProtocols="TLSv1.2" SSLEnabled="true"
                       URIEncoding="UTF-8" keystorePass="<MY_CERTIFICATE_PASSWORD>"/>


    Here is the default connector, using the standard AJP NIO2 Connector - notice the protocol attribute:

    <Connector port="8090" connectionTimeout="20000" redirectPort="8443"
    	maxThreads="48" minSpareThreads="10"
        enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8"
        protocol="org.apache.coyote.ajp.AjpNio2Protocol" />
  • Save the file and restart Confluence

The NIO Connector is a non-blocking type of connector. It will poll connections to see which ones are actually being used (as opposed to waiting for them to timeout); and should result in the available threads being used more efficiently.

For more advanced tomcat configuration options please refer to Tomcat Official Documentation.


Description Confluence becomes unresponsive during periods of high load. Given a little time, the instance may recover naturally and become usable again without having to restart. Profiling tools will show that the majority of tomcat HTTP threads are busy and CPU usage is high.
ProductConfluence
PlatformServer
Last modified on Aug 10, 2020

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.