Tomcat configuration access log and number of threads

content

1. Configuration of tomcat access log

2. Tomcat configuration thread number

3. View the number of tomcat threads in real time


1. Configuration of tomcat access log

1. Access log configuration

server:
  tomcat:
    accesslog:
      enabled: true        #是否开启日志
      directory: /home/admin/arpro-backend-prod/logs/arpro-monitor   #日志存储目录
      pattern: '%t %a %A %m %U%q %s %D %I %B'  #日志格式
      prefix: TomcatAccess        #日志文件前缀
      rename-on-rotate: true     #是否启用日志轮转

2. View log files on disk

3.Accesslog parameter explanation:

  • enabled, the value is true, false, set to true when accesslog is required

  • directory, specifies the path to the access file

  • rotate, specifies whether to enable log rotation. Defaults to true. This parameter determines whether the log file needs to be switched. If it is set to false, the log file will not be switched, that is, all files will be entered into the same log file, and the file-date-format parameter will also be ignored.

  • pattern, which defines the format of the log,

    Configuration of pattern:

    %a - the remote IP address

    %A - local IP address

    %b - Bytes sent, not including HTTP headers, or '-' if 0

    %B - Bytes sent, excluding HTTP headers

    %h - remote host name (shows IP if resolveHosts is false)

    %H - request protocol

    %l - the remote username, always '-' (Remote logical username from identd)

    %m - the method of the request (GET, POST, etc.) %p - the local port on which the request was accepted

    %q - the query string, if present, with a preceding '?'

    %r - the first line of the request (including the request method and the requested URI)

    %s - HTTP status code of the response (200, 404, etc.) %S - User's session ID

    %t - date and time in Common Log Format

    %u - the authenticated remote user, or '-' if it does not exist

    %U - request URL path %v - local service name

    %D - time to process the request in milliseconds

    %T - the time to process the request in seconds %I - the thread name of the current request (can compare later with stacktraces)

2. Tomcat configuration thread number

server:
  tomcat:
    uri-encoding: UTF-8
    min-spare-threads: 300  #最小线程数
    max-threads: 1000  #最大线程数
    accept-count: 500     #最大等待队列长度
    max-connections: 1800     #最大链接数

First of all, the number of threads is an important point. Every time an HTTP request arrives at the web server, the web server will create a thread to process the request. This parameter determines how many HTTP requests the application service can handle at the same time.

There are two more important: the initial number of threads and the maximum number of threads .

Initial number of threads: When starting, if a large number of users visit, it can accept requests stably. Maximum number of threads: used to ensure the stability of the system.

Timeout: used to ensure that the number of connections is not easily overwhelmed. If a large number of requests come, the delay is relatively high, and it is easy to use up the number of threads. At this time, it is necessary to increase the timeout period. This situation is relatively common in production. Once the network is unstable, it is better to lose packets than to overwhelm the server .        

min-spare-threads:最小备用线程数,tomcat启动时的初始化的线程数。

max-threads:Tomcat可创建的最大的线程数,每一个线程处理一个请求,超过这个请求数后,客户端请求只能排队,等有线程释放才能处理。(建议这个配置数可以在服务器CUP核心数的200~250倍之间)

accept-count:当调用Web服务的HTTP请求数达到tomcat的最大线程数时,还有新的HTTP请求到来,这时tomcat会将该请求放在等待队列中,这个acceptCount就是指能够接受的最大等待数,默认100。如果等待队列也被放满了,这个时候再来新的请求就会被tomcat拒绝(connection refused)。

max-connections:这个参数是指在同一时间,tomcat能够接受的最大连接数。一般这个值要大于(max-threads)+(accept-count)。

connection-timeout:最长等待时间,如果没有数据进来,等待一段时间后断开连接,释放线程。

3. View the number of tomcat threads in real time

Get tomcat process pid

ps -ef|grep java

Count the number of threads in the tomcat process

ps -Lf 进程号 |wc -l

Tomcat's official manual, quite detailed

Apache Tomcat 9 Configuration Reference (9.0.60) - The HTTP Connectorhttps://tomcat.apache.org/tomcat-9.0-doc/config/http.html#Java_TCP_socket_attributes

If this blog is helpful to you, please remember to leave a message + like + favorite

おすすめ

転載: blog.csdn.net/promsing/article/details/123674175