Java Performance Tuning

Source: Internet
Author: User
Tags tomcat server

One, Tomcat server 1, JVM parameter tuning

The startup parameters of Tomcat are located in the Tomcat directory \ Bin, if you are the Linux operating system is the catalina.sh file, if you are a Windows operating system then you need to change the Catalina.bat file

JAVA_OPTS="$JAVA_OPTS -server -Xms4096m -Xmx4096m -Xmn1024m -Xss256K -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=15 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/home/gclogs/gc.log -Djava.awt.headless=true"

Explain:
-server: Higher performance
-xms4096m: initial heap Memory 4g
-xmx4096m: Max heap Memory 4g
-xmn1024m: Young generation 1g
-xss256k: space occupied by each thread
-XX:+DISABLEEXPLICITGC: Suppress call to GC
-xx:maxtenuringthreshold=15: Survival times in younger generations
-XX:+USEPARNEWGC: Multi-threaded parallel recycling for younger generations
-XX:+USECONCMARKSWEEPGC: Old generation uses CMS recycling
-xx:+cmsparallelremarkenabled: Minimize Mark's time when using USEPARNEWGC
-xx:+usecmscompactatfullcollection: Prevents Memoryfragmention, organizes live object, and reduces memory fragmentation when using concurrent GC
-xx:largepagesizeinbytes=128m: Specify paging page size for Java heap
-xx:+usefastaccessormethods:get,set method into local code
-xx:+usecmsinitiatingoccupancyonly: Indicates that only after oldgeneration has used the initialized scale concurrent collector start the collection
-XX:CMSINITIATINGOCCUPANCYFRACTION=70: Old generation arrives at 70% for GC
-djava.awt.headless=true:headless mode is a configuration mode of the system. In this mode, the system is missing a display device, keyboard, or mouse.
-xx:+printgc-xx:+printgcdetails-xx:+printgcdatestamps-xloggc:/home/gclogs/gc.log: Print log information

Remark: The above collector is young substitute parnewgc, old substitute CMS; You can also use the G1 collector

-XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:MaxGCPauseMillis=50 -XX:GCPauseIntervalMillis=200

Explain:
-XX:+UNLOCKEXPERIMENTALVMOPTIONS-XX:+USEG1GC #开启G1, these two are used simultaneously
-xx:maxgcpausemillis=50 #暂停时间目标;
-xx:gcpauseintervalmillis=200 #暂停间隔目标;

2, connector optimization

The installation directory for Tomcat \conf the following server.xml

<Connector port="8080"protocol="HTTP/1.1"connectionTimeout="20000"URIEncoding="UTF-8"maxThreads="300"minSpareThreads="25"maxSpareThreads="75"enableLookups="false"acceptCount="300"maxProcessors="1000"minProcessors="5"useURIValidationHack="false"compression="on"compressionMinSize="2048"compressableMimeType="text/html,text/xml,text/JavaScript,text/css,text/plain"redirectPort="8443" />

Explain:
Protocol: Protocol
ConnectionTimeout: Number of milliseconds to connect time-out
Uriencoding: Encoding
Maxthreads:tomcat the maximum number of threads that can be created, that is, the maximum number of concurrent
Minsparethreads: The minimum number of standby threads, the number of threads initialized at tomcat startup.
Maxsparethreads: If the number of threads in the idle state is greater than the number of settings, the threads are aborted, reducing the total number of threads in the pool
Enablelookups: Whether to allow domain names to be reversed
Acceptcount: When the number of threads reaches MaxThreads, subsequent requests are placed in a wait queue, the Acceptcount is the size of the queue, and if the queue is full, refuse connection
Maxprocessors: Maximum number of connections
Minprocessors: Initialize the number of connections
Useurivalidationhack: Checking URLs
Compression: Boot compression
compressionminsize:2048 when the return content is greater than or equal to 2kb boot compression, to the client in the decompression
Compressablemimetype: Compression type

Ii. springboot Item 1, JVM parameters

Springboot starts directly with the jar package and adds parameters to the start command, here is an example:

nohup java -server -Xms4096m -Xmx4096m -Xmn1024m -Xss256K -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=15 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/home/gclogs/gc.log -Djava.awt.headless=true -jar mq.jar &
2. Springboot optimized for built-in Tomcat

Configuring in Application.yml

server:  tomcat:    uri-encoding: UTF-8    max-threads: 300    min-spare-threads: 25    max-connections: 1000    accept-count: 300  port: 8080  connection-timeout: 20000  compression:    enabled: true    mime-types: text/html,text/xml,text/JavaScript,text/css,text/plain    min-response-size: 2048
Third, Performance view common commands

Note: 128914 is the thread ID
View load: W, uptime
View Cpu:top
Memory: Free
Disk: DF
Io:iostat, Vmstat
View GC Status: JSTAT-GC 128914 2000 2
View stack condition: Jstack 128914
Analyzing GC logs: more Gc.log
View all threads inside a process: top-hp 128914

Java Performance Tuning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.