Performance Tuning in The Tomcat Server

by:APTEK     2020-07-16
Performance tuning of an Apache Tomcat Server is considered a bit of a black art and something that only an experienced Tomcat admin should undertake. While expertise with Tomcat and best practices for its implementation/management is important, there are some basic tuning approaches you can employ that will provide significant benefits for little effort. This article covers those approaches. Spend some time understanding the installation of Tomcat, the web site's traffic level, and the web applications that it runs. In general Tomcat performs better when you: - Start the JVM with its initial heap tomcat memory size (the -Xms switch) set to the maximum memory size. Using the maximum setting, the JVM never needs to resize and reallocate the heap memory while trying to serve requests. - Start the Tomcat JVM with a higher heap memory maximum using the -Xmx switch. The higher this setting, the more memory is available, allowing the server a higher percentage of its CPU time to serve web requests. If your webapp runs on dedicated server hardware, give the JVM as much of the machine's physical memory as reasonably possible. If it is running on shared or virtual hardware, hook up a console (such as Tcat Server console) to see how much memory your webapp uses under high load circumstances and adjust the maximum heap size accordingly. - Tweak the Connector (web server) thread pool settings for your web request load based on your peak traffic patterns. If the maxThreads attribute is set too low, you may not have enough threads to handle all of the requests causing requests to sit idle until another request thread is freed up to handle them, and Tomcat will be unable to take advantage of your server's hardware. If the maxThreads attribute is set too high, Tomcat startup time will increase, and can slow down your server during peak load periods trying to run a high number of request threads concurrently. - Additional Connector attribute settings: * compression: Toggle between 'on' and 'off' to determine which setting is best for your webapp. * compressableMimeTypes: If you enable compression, set this attribute to show Tomcat what you want it to compress. Try something like 'text/html,text/xml,text/javascript,text/css,text/plain'. Other important factors in performance tuning include: - HTTP caching headers: Enabling the user's web browser to cache the static content of your webapps can greatly increase the user's perceived performance. It is important to set the right set of response headers and their values when Tomcat serves the webapp's static files. Proxying all requests to Tomcat from Apache HTTPD is not advised for maximum Tomcat performance as that configuration may cause a loss of about half of the Tomcat's performance. - HTTPS is slower than HTTP. Bringing the Tomcat server geographically closer to the users may help reduce request times. - Many webapps use a relational database, making the database connection settings very important. Adjust the maxActive, maxIdle, and maxWait attributes where you define your database connection. If using the AJP Connector, set the attribute request.registerRequests='false' to stop logging tomcat JMX stats for the requests of the connector, to make performance steadier during traffic spikes.
Custom message
Chat Online 编辑模式下无法使用
Chat Online inputting...
Hello, please leave your name and email here before chat online so that we won't miss your message and contact you smoothly.