Skip to content

Instantly share code, notes, and snippets.

@mondain
Last active March 20, 2020 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mondain/012ad9ede1981037f387f7d042c29bcb to your computer and use it in GitHub Desktop.
Save mondain/012ad9ede1981037f387f7d042c29bcb to your computer and use it in GitHub Desktop.
Red5 configuration for higher HTTP/WS loads

The following modifications to the conf/jee-container.xml should provide a higher availability level than the default configuration set.

For http and ws connections:

<bean name="httpConnector" class="org.red5.server.tomcat.TomcatConnector">
    <property name="protocol" value="org.apache.coyote.http11.Http11Nio2Protocol" />
    <property name="address" value="${http.host}:${http.port}" />
    <property name="redirectPort" value="${https.port}" />
    <property name="connectionProperties">
        <map>
            <entry key="port" value="${http.port}" />
            <entry key="redirectPort" value="${https.port}" />
            <entry key="maxHttpHeaderSize" value="${http.max_headers_size}"/>
            <entry key="maxKeepAliveRequests" value="${http.max_keep_alive_requests}"/>
            <entry key="keepAliveTimout" value="-1"/>
            <entry key="useExecutor" value="true"/>
            <!-- Maximum number of request processing threads to be created by this Connector -->
            <entry key="maxThreads" value="${http.max_threads}"/>
            <!-- Backlog of connections waiting to be accepted -->
            <entry key="acceptCount" value="1000"/>
            <!-- Number of threads to be used to accept connections -->
            <entry key="acceptorThreadCount" value="${http.acceptor_thread_count}"/>
            <!-- Protocol handler caches Processor objects to speed up performance -->
            <entry key="processorCache" value="${http.processor_cache}"/>
            <!-- Connection timeout alloting 20s for an accepted connection to present its request -->
            <entry key="connectionTimeout" value="20000"/>
            <!-- Negative one prevents connections from being counted -->
            <entry key="maxConnections" value="-1"/>
        </map>
    </property>
</bean>

For https and wss connections:

<bean name="httpsConnector" class="org.red5.server.tomcat.TomcatConnector">
    <property name="secure" value="true" />
    <property name="protocol" value="org.apache.coyote.http11.Http11Nio2Protocol" />
    <property name="address" value="${http.host}:${https.port}" />
    <property name="redirectPort" value="${http.port}" />
    <property name="connectionProperties">
        <map>
            <entry key="port" value="${https.port}" />
            <entry key="redirectPort" value="${http.port}" />
            <entry key="SSLEnabled" value="true" />
            <entry key="sslProtocol" value="TLSv1.2" />
            <entry key="ciphers" value="TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_GCM_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA" />
            <entry key="useServerCipherSuitesOrder" value="true" />
            <entry key="keystoreFile" value="${rtmps.keystorefile}" />
            <entry key="keystorePass" value="${rtmps.keystorepass}" />
            <entry key="truststoreFile" value="${rtmps.truststorefile}" />
            <entry key="truststorePass" value="${rtmps.truststorepass}" />
            <entry key="clientAuth" value="false" />
            <entry key="allowUnsafeLegacyRenegotiation" value="false" />
            <entry key="maxHttpHeaderSize" value="${http.max_headers_size}"/>
            <entry key="maxKeepAliveRequests" value="${http.max_keep_alive_requests}"/>
            <entry key="keepAliveTimout" value="-1"/>
            <entry key="useExecutor" value="true"/>
            <!-- Maximum number of request processing threads to be created by this Connector -->
            <entry key="maxThreads" value="${http.max_threads}"/>
            <!-- Backlog of connections waiting to be accepted -->
            <entry key="acceptCount" value="1000"/>
            <!-- Number of threads to be used to accept connections -->
            <entry key="acceptorThreadCount" value="${http.acceptor_thread_count}"/>
            <!-- Protocol handler caches Processor objects to speed up performance -->
            <entry key="processorCache" value="${http.processor_cache}"/>
            <!-- Connection timeout alloting 20s for an accepted connection to present its request -->
            <entry key="connectionTimeout" value="20000"/>
            <!-- Negative one prevents connections from being counted -->
            <entry key="maxConnections" value="-1"/>
        </map>
    </property>
</bean>

Entries added: acceptCount, connectionTimeout, and maxConnections.

The following modifications should be made to the conf/red5.properties file:

# HTTP
http.host=0.0.0.0
http.port=80
https.port=443
http.URIEncoding=UTF-8
http.max_headers_size=8192
http.max_keep_alive_requests=-1
http.max_threads=200
http.acceptor_thread_count=100
http.processor_cache=200

The http.acceptor_thread_count has been increased from 10 (Tomcat default is 1), to be 10% of the accept backlog ie. acceptCount. Lastly, since we use an executor useExecutor=true the maxThreads and processorCache are essentially irrelavant.

Definitions for the modified parameters:

  • acceptCount - The maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 100.
  • acceptorThreadCount - The number of threads to be used to accept connections. Increase this value on a multi CPU machine, although you would never really need more than 2. Also, with a lot of non keep alive connections, you might want to increase this value as well. Default value is 1.
  • connectionTimeout - The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented. Use a value of -1 to indicate no (i.e. infinite) timeout. The default value is 60000 (i.e. 60 seconds) but note that the standard server.xml that ships with Tomcat sets this to 20000 (i.e. 20 seconds). Unless disableUploadTimeout is set to false, this timeout will also be used when reading the request body (if any).
  • maxConnections - The maximum number of connections that the server will accept and process at any given time. When this number has been reached, the server will accept, but not process, one further connection. This additional connection be blocked until the number of connections being processed falls below maxConnections at which point the server will start accepting and processing new connections again. Note that once the limit has been reached, the operating system may still accept connections based on the acceptCount setting. The default value varies by connector type. For NIO and NIO2 the default is 10000. For NIO/NIO2 only, setting the value to -1, will disable the maxConnections feature and connections will not be counted.
  • maxThreads - The maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200. If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool. Note that if an executor is configured any value set for this attribute will be recorded correctly but it will be reported (e.g. via JMX) as -1 to make clear that it is not used.
  • processorCache - The protocol handler caches Processor objects to speed up performance. This setting dictates how many of these objects get cached. -1 means unlimited, default is 200. If not using Servlet 3.0 asynchronous processing, a good default is to use the same as the maxThreads setting. If using Servlet 3.0 asynchronous processing, a good default is to use the larger of maxThreads and the maximum number of expected concurrent requests (synchronous and asynchronous).

Tomcat 8.5 Connector Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment