Configured in tomcat's server.xml

  1. <Connectorport="8080"protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443"maxSpareThreads="750"maxThreads="1000"minSpareTHreads="50"acceptCount="1000"maxProcessors="1000"URIEncoding="gbk"useBodyEncodingForURI="true"/>                的配置, 其中:

    acceptCount="1000" the maximum number of connections accepted

     maxProcessors="1000" Maximum number of active threads

    port="8080" service port

    protocol="HTTP/1.1" service protocol

    connectionTimeout="20000" The timeout unit is ms

    redirectPort="8443" When the redirect port  requires secure communication, the client request will be forwarded to the redirectPort port of SSL

    maxThreads: The maximum number of threads that Tomcat can create, each thread handles one request;  maxThreads determines the maximum thread threshold of tomcat, which needs to be set larger

    minSpareThreads: The minimum number of spare threads, the number of initialized threads when tomcat starts;

    maxSpareThreads: The maximum number of spare threads. Once the created threads exceed this value, Tomcat will close the socket threads that are no longer needed;


     URIEncoding="gbk" sets the default transcoding format of tomcat

    Check out the documentation in $TOMCAT_HOME/webapps/tomcat-docs/config/http.html for the following instructions: 
    URIEncoding: This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO- 8859-1 will be used. That is to say, if URIEncoding is not set, Tomcat will perform URL decoding according to ISO-8859-1 by default. ISO-8859-1 does not include Chinese characters, so Chinese characters must not be parsed correctly. .


    Reprint someone else's blog:

     

    1. Tomcat connection pool configuration 
         If Tomcat wants to withstand a large amount of concurrency, the number of connections must be increased. The general Tomcat Connector can be modified as follows: 
         

    <Connector port="80" protocol="HTTP/1.1" 
        connectionTimeout="60000" 
        redirectPort="8443"
        maxThreads="5000" 
        acceptCount="500"
        minSpareThreads="100"
        maxSpareThreads="5000"
        enableLookups="false"
        compression="on"
        compressionMinSize="2048"
        compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
        disableUploadTimeout="true"
        URIEncoding="UTF-8"/>

    其中几个关键的参数: 
    connectionTimeout:连接超时,毫秒为单位.对于高并发对实时要求不高的可以使适当增加该值 
    maxThreads:最大并发连接数 
    acceptCount:在超过最大连接数后,可以接受的排队数量 
    minSpareThreads:Tomcat初始化时默认创建的线程数,也是以后线程增加时一次增加的最小数量 
    maxSpareThreads:这个参数标识,一旦创建的线程数量超过这个值,Tomcat就会关闭不活动的线程 
    enableLookups:关闭DNS查询 
    在实现中,我们发现使用该配置,连接数上去之后很难下降,导致CPU一直维持在一个比较高的水平. 

    后来我们换了一种连接方式,采用线程池的方式,首先定义一个Executor: 

    <Executor name="tomcatThreadPool" 
            namePrefix="tomcatThreadPool-" 
            maxThreads="1000" 
            maxIdleTime="300000"
            minSpareThreads="200"/>

    参数的意义和上述相同 
    在Connector中使用定义的这个连接池: 

     

    <Connector executor="tomcatThreadPool"
               port="20003" protocol="HTTP/1.1"
               acceptCount="800"
               minProcessors="300"
               maxProcessors = "1000"
               redirectPort="8443"/>

     

    minProcessors,maxProcessors与上面的minSpareThreads,maxThreads意义差不多. 
    使用连接池以后,发现连接数上升后如果一段时间没有请求了,连接数会很快下降,CPU的消耗得到了有效的降低, 
    处理能力得到了增强.






    如何查看当前tomcat的连接数呢?

    假设服务器上开启了 2个tomcat实例,分别监听8040和8050端口

    netstat -na | grep ESTAB | grep 8040 | wc -l

    netstat -na | grep ESTAB | grep 8050 | wc -l


    二者之和,就是所有tomcat的连接数

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326680664&siteId=291194637