Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Tomcat performance tuning

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Performance tuning: The application code is mainly started from the following aspects: If the code is not well developed, it will lead to performance problems, such as database connections that are not properly closed at the time of closure, which will cause the application to run slowly. Database tuning: If the database is slow to respond, then the application will definitely be slow to respond. JVM tuning: If your application requires more memory to run and you allocate less memory, it will cause memory overflow and therefore performance problems. Middleware services: For example, when we choose message queuing, caching, or design, it can also cause performance problems. Infrastructure and OS: for example, network packet loss, unreasonable system configuration, etc.

Proper logging and monitoring: Logging and monitoring help with analysis and troubleshooting.

Tomcat connector type: Java HTTP connector:

Is based on the HTTP protocol and supports HTTP 1.1, which enables tomcat server to act as a stand-alone server and JSP/servlet capable server.

Java AJP connector:

JAVA AJP is based on the Apache JServ protocol, which is often used when you don't want to expose your Java servlet container to the Internet.

APR(AJP/HTTP) connector:

Apache Portable Runtime (APR) is the best in scalability, performance and compatibility between different web servers. It provides services such as OPENSSL, shared memory, Unix large sockets, etc.

Thread tuning:

Thread stokes define the number of web server connection requests, and two thread stokes can be defined: shared stokes and dedicated stokes. This configuration is defined in the TOMCAT_HOME/conf/server.xml file.

Shared thread:

If you configure four connectors, you can share the thread.

The configuration is as follows:

(1) Define thread stokes (2) Reference defined thread stokes Dedicated thread stokes: Also defined in server.xml The following table is Dedicated thread stokes and Shared thread stokes Frequently used scenarios Comparison Features Shared thread pool Dedicated thread poolNumber of users less HighEnvironment Development ProductionPerformance low GoodmaxThreads:

The default maximum thread count is defined as 150, which can be adjusted in a production environment based on server performance.

maxKeepAlive:

The default value is 1, which is equivalent to closing.

JVM tuning: JMAP(memory mapping)

JMAP displays shared JAVA virtual machine memory information, useful for viewing the status of shared memory. Here are some common options:

Options Description

-dump Dumps the Java heap in hprof binary format-finalizer info Prints information on objects awaiting finalization-heap Prints a heap summary-histo Prints a histogram of the heap-permstat Prints class loader-wise statistics of permanent generation of the Java heapjmap

./ jmap --heap

For example, if our JAVA ID is 4306, then execute./ jmap -heap 4306

Attaching to process ID 4306, please wait... Debugger attached successfully.Client compiler detected.JVM version is 19.1-b02using thread-local object allocation.Mark Sweep Compact GCHeap Configuration:MinHeapFreeRatio = 40MaxHeapFreeRatio = 70MaxHeapSize = 268435456 (256.0MB)NewSize = 1048576 (1.0MB)MaxNewSize = 4294901760 (4095.9375MB)OldSize = 4194304 (4.0MB)NewRatio = 2SurvivorRatio = 8PermSize = 12582912 (12.0MB)MaxPermSize = 67108864 (64.0MB)Heap Usage:New Generation (Eden + 1 Survivor Space):capacity = 5111808 (4.875MB)used = 3883008 (3.703125MB)free = 1228800 (1.171875MB)75.96153846153847% usedEden Space:capacity = 4587520 (4.375MB)used = 3708360 (3.5365676879882812MB)free = 879160 (0.8384323120117188MB)80.83583286830357% usedFrom Space:capacity = 524288 (0.5MB)used = 174648 (0.16655731201171875MB)free = 349640 (0.33344268798828125MB)33.31146240234375% usedTo Space:capacity = 524288 (0.5MB)used = 0 (0.0MB)free = 524288 (0.5MB)0.0% usedtenured generation: capacity = 11206656 (10.6875MB)used = 3280712 (3.1287307739257812MB)free = 7925944 (7.558769226074219MB)29.274673908077485% usedPerm Generation: capacity = 12582912 (12.0MB)used = 6639016 (6.331459045410156MB)free = 5943896 (5.668540954589844MB)52.762158711751304% used From above you can see the following main information: heap configuration of the application heap memory utilization of each JVM component algorithm used by the garbage collector heap memory configuration:

JAVA_OPTS option in catalina.sh.

JAVA_OPTS="-Xms128m -Xmx512m -XX:MaxPermSize=256m"

Serial collectorProcess Single thread is used for GCGC pause High Threading Single threadedApplication Small application (data less than 100 MB)Advantage There is single thread communication Features Parallel collectorProcess Parallel thread does minor GCGC pause Less than SerialThreading MultithreadedApplication Mid-largeAdvantage Used in applications when peak performance is needed Features Concurrent collectorProcess GC is done concurrentlyGC pause Short pauseThreading MultithreadedApplication Mid-largeAdvantage Used in applications when a response is needJVM options are standard and non-standard:

The main options are as follows:

Options Parameter DescriptionBehavioral Options -XX:+ScavengeBeforeFullGC Do young generation GC prior to a full GCBehavioral Options --XX:-UseParallelGC Use parallel garbage collection for scavengesPerformance Options -XX:MaxNewSize=size Maximum size of new generation (in bytes)Performance Options -XX:MaxPermSize=64m Size of the Permanent Generation (after exceeding Xmxvalue)Performance Options -Xms Minimum heap memory for the startup of TomcatPerformance Options Xmx Maximum memory allocated to the instancePerformance Options -Xss Stack size for the heapDebugging Options -XX:-CITime Prints time spent in the JIT CompilerDebugging Options -XX:ErrorFile=./ hs_err_pid.log If an error occurs, save the error data to this fileDebugging Options -XX:HeapDumpPath=./ java_pid.hprof Path to the directory or filename for the heap dumpDebugging Options -XX:-HeapDumpOnOutOfMemoryError Dump the heap to the file whenjava.lang.OutOfMemoryError is thrownOptions Parameter DescriptionDebugging Options -XX:OnError=";" Run user-defined commands on fatal errorDebugging Options -XX:OnOutOfMemoryError="; Run user-defined commands when an OutOfMemoryError is first thrownDebugging Options -XX:-PrintClassHistogram Print a histogram of class instances on Ctrl-BreakParameters displayed in the logs for GCGC prints the output of the garbage collection to the stdout stream. At every garbage collection, the following five fields are printed:

[%T %B->%A(%C), %D]

%T: This is "GC" when the garbage collection is a scavenge, and "Full GC:" is performed, then scavenge collects live objects from the new generation only, whereas a full garbage collection collects objects from all spaces in the Java heap.%B: It is the size of the Java heap used before the garbage collection, in KB.% A: It is the size of the Java heap after the garbage collection, in KB.% C: It is the current capacity of the entire Java heap, in KB.

%D: It is the duration of the collection in seconds.

SurvivorRatioIt is defined as a ratio of eden to the survivor space size. The default value is 8, meaning that eden is 8 times bigger than from and to, each. The syntax for the SurvivorRatio is -XX:SurvivorRatio=.The following are some examples: System tuning: Suggest selecting a 64-bit system file size limit Open connection limit Large page size

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report