3.执行器(线程池)
在tomcat中每一个用户请求都是一个线程,所以可以使用线程池提高性能。
tomcat7默认就是线程池,默认最小10,最大是200 3.1.开启并且使用
配置: 3.2. 参数说明
AttributeDescriptionthreadPriority (优先级)(int)The thread priority for threads in the executor, the default is 5 (the value of theThread.NORM_PRIORITY constant)daemon(守护进程)(boolean)Whether the threads should be daemon threads or not, the default is truenamePrefix(名称前缀)(String)The name prefix for each thread created by the executor. The thread name for an individual thread will be namePrefix+threadNumbermaxThreads(最大线程数)(int)The max number of active threads in this pool, default is 200minSpareThreads(最小活跃线程数) (int)The minimum number of threads always kept alive, default is 25maxIdleTime(空闲线程等待时间) (int)The number of milliseconds before an>3.3. 最佳实践 4. 连接器(Connector)
Connector是Tomcat接收请求的入口,每个Connector有自己专属的监听端口
Connector有两种:HTTP Connector和AJP Connector 4.1. 通用属性(高亮的是重点)
AttributeDescriptionallowTraceA boolean value which can be used to enable or disable the TRACE HTTP method. If not specified, this attribute is set to false.如果需要服务器能够处理用户的HAED/TRACE请求,这个值应该设置为true,默认值是falseasyncTimeoutThe default timeout for asynchronous requests in milliseconds. If not specified, this attribute is set to 10000 (10 seconds).默认超不时候以毫秒为单位的异步恳求。若是没有指定,该属性被设置为10000(10秒)。enableLookupsSet to true if you want calls to request.getRemoteHost() to perform DNS lookups in order to return the actual host name of the remote client. Set to false to skip the DNS lookup and return the IP address in String form instead (thereby improving performance). By default, DNS lookups are disabled.若是你想request.getRemoteHost()的调用 履行,以便返回的长途客户端的实际主机名的DNS查询,则设置为true。设置为false时跳过DNS查找,并返回字符串情势的IP地址(从而提高性能)。默认景象下,禁用DNS查找。maxHeaderCountThe maximum number of headers in a request that are allowed by the container. A request that contains more headers than the specified limit will be rejected. A value of less than 0 means no limit. If not specified, a default of 100 is used.容器允许的请求头字段的最大数目。请求中包含比指定的限制更多的头字段将被拒绝。值小于0表示没有限制。如果没有指定,默认设置为100。maxParameterCountThe maximum number of parameter and value pairs (GET plus POST) which will be automatically parsed by the container. Parameter and value pairs beyond this limit will be ignored. A value of less than 0 means no limit. If not specified, a default of 10000 is used. Note that FailedRequestFilter filtercan be used to reject requests that hit the limit.将被容器自动解析的最大数量的参数和值对(GET加上POST)。参数值对超出此限制将被忽略。值小于0表示没有限制。如果没有指定,默认为10000。请注意, FailedRequestFilter 过滤器可以用来拒绝达到了极限值的请求。maxPostSizeThe maximum>4.2. 标准实现(高亮的是重点)
除了上面列出的常见的连接器属性,标准的HTTP连接器(BIO,NIO和APR/native)都支持以下属性。
AttributeDescriptionacceptCountThe 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.当所有可能的请求处理线程都在使用时,传入连接请求的最大队列长度。当队列满时收到的任何请求将被拒绝。默认值是100。acceptorThreadCountThe number of threads to be used to accept connections. Increase this value on a multi CPU machine,>4.3. NIO的具体配置
AttributeDescriptionpollerThreadCount(int)The number of threads to be used to run for the polling events. Default value is 1 per processor up to and including version 7.0.27. Default value as of version 7.0.28 is 1 per processor but not more than 2.When accepting a socket, the operating system holds a global lock. So the benefit of going above 2 threads diminishes rapidly. Having more than one thread is for system that need to accept connections very rapidly. However usually just increasing acceptCount will solve that problem. Increasing this value may also be beneficial when a large amount of send file operations are going on.(int)用来处理轮询事件的线程的数量。在版本7.0.27及以前版本,默认值是每个处理器1个。版本7.0.28的默认值是每个处理器1个,但不超过2个。当接受一个套接字,操作系统拥有全局的锁。所以超过2个线程的好处而迅速减小。有一个以上的线程是因为系统需要非常迅速地接受连接。但通常只要增加acceptCount值就可以解决这个问题。增加该值也可能是有用的,当大量发送文件操作发生的时候。pollerThreadPriority(int)The priority of the poller threads. The default value is 5 (the value of thejava.lang.Thread.NORM_PRIORITY constant). See the JavaDoc for the java.lang.Thread>4.4. 最佳实践