TomcatExpert

Performance Tuning the JVM for Running Apache Tomcat

posted by dmikusa on November 22, 2011 09:13 AM

This article is the second in a series discussing how to performance tune the JVM to better run Apache Tomcat. In the first article, we discussed the basic basic goals and how to monitor the performance of your JVM.

If you have not read the first article, I would strongly suggest reading that before continuing with this article. It is important to understand and follow the processes outlined in that article when performance tuning. They will both save you time and prevent you getting into trouble. With that, let's continue.

Tuning the JVM

At this point we've covered the basics and are ready to begin examining the JVM options that are available to us. Please note that while these options can be used for any application running on the JVM, this article will focus sole only how they can be applied to Tomcat. The usage of these options for other applications may or may not be appropriate.

Note: For simplicity, it is assumed that you are running an Oracle Hotspot JVM.

General Options

-Xms and -Xmx

These settings are used to define the size of the heap used by the JVM. -Xms defines the initial size of the heap and -Xmx defines the maximum size of the heap. Specific values for these options will depend on the number of applications and the requirements of each application deployed to a Tomcat instance.

With regard to Tomcat, it is recommended that the initial and maximum values for heap size be set to the same value. This is often referred to as a fully committed heap and this will instruct the JVM to create a heap that is initially at its maximum size and prevent several full garbage collections from occurring as the heap expands to its maximum size.

-XX:PermSize and -XX:MaxPermSize

These settings are used to define the size of the permanent generation space. -XX:PermSizedefines the initial value and -XX:MaxPermSize defines the maximum value.

With regard to Tomcat, it is recommended that the initial and maximum values for the size of the permanent generation be set to the same value. This will instruct the JVM to create the permanent generation so that it is initially at its maximum size and prevent possible full garbage collections from occurring as the permanent generation expands to its maximum size.

At this point, you might be thinking that this seems awful similar to the -Xms and -Xmx options, and while the concept is the same, “PermGen” or permanent generation, refers to the location in memory where the JVM stores the class files that have been loaded into memory. This is different and distinct from the heap (specified by -Xms and -Xmx) which is where the JVM stores the object instances used by an application.

One final note, if the PermGen space becomes full (regardless of the availability of memory in the heap) then the JVM will attempt a full garbage collection to reclaim space. This can often be a source of problems for applications which dynamically create or load a large number of classes. Proper sizing of -XX:PermSize and -XX:MaxPermSize for your applications will allow you to work around this issue.

-Xss

This setting determines the size of the stack for each thread in the JVM. The specific value that you should use will vary depending on the requirements of the applications deployed to Tomcat, however in most cases the default value used by the JVM is too large.

For a typical installation, this value can be lowered, saving memory and increasing the number of threads that can be run on a system. The easiest way to determine a value for your system is to start out with a very low value, for example 128k. Then run Tomcat and look for a StackOverFlow exception in the logs. If you see the exception, then gradually increase the value and restart Tomcat. When the exceptions disappear, you have found the minimal value which works for your deployment.

-server

This setting will select the Java HotSpot Server VM. This will instruct the VM that it is running in a server environment and the default configurations will be changed accordingly.

Note, this option is really only needed when running 32-bit Windows, as 32-bit Solaris and 32-bit Linux installations with two or more CPU's and 2GB or more of RAM will enable this option by default. In addition, all 64-bit OS's have this option enabled by default as there is no 64-bit client VM.

For a comprehensive list of JVM options, please see the article Java HotSpot VM Options.

Selecting a Collector

For many users, tuning the basic options I mentioned in the previous section will be sufficient for their applications. However, for larger applications or applications which just require larger heap sizes these options may not be sufficient. If your Tomcat installation fits this profile then you'll want to take one further step and tune the collector.

To begin tuning the collector, you need to pick the right collector for your application. The JVM ships with three commonly used collectors: the serial collector, the parallel collector and the concurrent collector. In most cases when running Tomcat, you'll be using either the parallel collector or the concurrent collector. The difference between the two being that the parallel collector typically offers the better throughput, while the concurrent collector often offers lower pause times.

The parallel collector can be enabled by adding -XX:+UseParallelGC to CATALINA_OPTS or the concurrent collector can be enabled by adding -XX:+UseConcMarkSweepGC to CATALINA_OPTS (you would never want to have both options enabled). As to which of the collectors you should be using, it is difficult to give a blanket recommendation. I would suggest that you give both a try, measure the results and use that to make your decision.

Once you have selected a collector, it is possible to take one further step and apply some configuration settings which are specific to the collector. That being said, most of the time the JVM will detect and set excellent values for these options. You should not attempt to manually configure these unless you have a good understanding of how the specific garbage collector is working, you are applying rule number one from above and you really know what you are doing. That said, I'm going to talk about two options, one for the parallel collector and one for the concurrent collector.

When you specify the option to run the parallel collector, it will only run on the young generation. This means that multiple threads will be used to process the young generation, but the old generation will continue to be processed by a single thread. To enable parallel compaction of the old generation space you can enable the option -XX:+UseParallelOldGC. Note that this option will help the most when enabled on a system with many processors.

When you specify the option to run the concurrent collector, it is important to realize that garbage collection will happen concurrently with the application. This means that garbage collection will consume some of the processor resources that would have otherwise been available to the application. On systems with a large number of processors, this is typically not a problem. However, if your system has only one or two processors then you will likely want to enable the -XX:+CMSIncrementalMode option. This option enables incremental mode for the collector, which instructs the collector to periodically yield the processor back to the application and essentially prevents the collector from running for too long.

Conclusion

Congratulations! If you're reading this then you made it all the way through the article. If you're still a little confused at this point, that is OK and I would say normal. Tuning the JVM and the inner workings of the garbage collectors is not an easy subject.

If you'd like to get some additional information on the subject, I would strongly suggest continuing on with this article from Oracle, Java SE 6 HotSpot[tm] Virtual Machine Garbage Collection Tuning. It is very technical and should be able to fill in any of the gaps left from this article.

Daniel Mikusa is a Software Support Engineer at Pivotal.  Daniel has been a user of Apache Tomcat for the past six years and is currently focused on providing enterprise-class support for Pivotal's Tomcat and tc Server customers. Daniel attended college at Kent State University and holds a bachelor's degree in Computer Science.

Comments

Click this

I wonderment why other professionals don't respond your website overmuch m happy I plant this.Click this

dj

I am interested in such topics.
Watch Petes Dragon Online
Watch Moana Online
Watch The Light Between Oceans Online
Watch Assassins Creed Online
Watch Mechanic 2 Resurrection Online
Watch Sing Online
Watch Storks Online
Watch Jack Reacher 2 Never Go Back Online
Watch Kubo and the Two Strings Online
Watch Fantastic Beasts and Where to Find Them Online
Watch Moana Online
Watch Manchester by the Sea Online
Watch Collateral Beauty Online
Watch Sing Online
Watch Arrival Online
Watch Mechanic 2 Resurrection Online
Watch War Dogs Online
Watch Ben Hur Online
Watch Sausage Party Online
Watch The Edge of Seventeen Online
Watch Florence Foster Jenkins Online
Watch Assassins Creed Online
Watch La La Land Online
Watch Snowden Online
Watch Manchester by the Sea Online
Watch Passengers Online
Watch Doctor Strange Online
Watch Miss Peregrines Home for Peculiar Children Online
Watch Petes Dragon Online
Watch The Girl on the Train Online
Watch Collateral Beauty Online
Watch Deepwater Horizon Online
Watch Jack Reacher 2 Never Go Back Online
Watch A Monster Calls Online
Watch Gold Online
Watch Doctor Strange Online
Watch The Founder Online
Watch La La Land Online
Watch Storks Online
Watch Fantastic Beasts and Where to Find Them Online
Watch The Magnificent Seven Online
Watch Kubo and the Two Strings Online
Watch Deepwater Horizon Online
Watch Spectral Online
Watch The Magnificent Seven Online
Watch The Founder Online
Watch Passengers Online
Watch The Space Between Us Online
Watch A Monster Calls Online
Watch The Space Between Us Online
Watch Gold Online
Watch Snowden Online
Watch Rogue One Online
Watch Spectral Online
Watch Florence Foster Jenkins Online
Watch Billy Lynns Long Halftime Walk Online
Watch Miss Peregrines Home for Peculiar Children Online
Watch Trolls Online
Watch The Accountant Online
Watch Arrival Online
Watch Ben Hur Online
Watch Inferno Online
Watch Inferno Online
Watch War Dogs Online
Watch The Edge of Seventeen Online
Watch The Accountant Online
Watch The Light Between Oceans Online
Watch Rogue One Online
Watch Billy Lynns Long Halftime Walk Online
Watch The Girl on the Train Online
Watch Trolls Online
Watch Sausage Party Online
Keep posting such needed information.

I’m glad to find so many

I’m glad to find so many useful and informative data on your website.useful source

This makes you stand way out

This makes you stand way out from many other writers that push poorly written content.s5 car covers

As a breed Foxhounds are one

As a breed Foxhounds are one of the most healthy breeds around in today's list of dogs, health problems are few and far between.Max Clayton

blog actualités

Your contents are too simple to read and easy to understand.blog actualités

The professional which does

The professional which does the laptop computer repair work services Bolton acknowledges precisely how important your computer is to you.laptop repair orlando

I use only high quality

I use only high quality materials - you can see them at: chula vista party rentals

I invite you to the page

I invite you to the page where you can read with interesting information on similar topics. autoprotectionoptions.com

I infer I haven't interpreted

I infer I haven't interpreted specified incomparable physical anywhere added online.read more

Cool website buddy I am gona

Cool website buddy I am gona suggest this to all my list of contacts.سناب انستقرام احلام الشامسي

This is very appealing,

This is very appealing, however , it is very important that will mouse click on the connection: fjell elsker

Acknowledges for penmanship

Acknowledges for penmanship such a worthy column, I stumbled beside your blog besides predict a handful advise. I want your tone of manuscript... burger i norge

Beaver says I also have such

Beaver says I also have such interest, you can read my profile here: frilanser i norge

Nice information, valuable

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here. norkse ulver

I thought this was a pretty

I thought this was a pretty interesting read when it comes to this topic. Liked the material. Carpet Cleaners in Port Elizabeth

I can also transmit most

I can also transmit most people the link allowing you to analyze it again in my circumstances you should spirit.alcohol detox Florida

Academic ethics are one of

Academic ethics are one of the most serious things which are faced by all students. elite tyres brighton

I would be appreciating all

I would be appreciating all of your articles and blogs because they are fitting up mark.ipad

df

Could much the same as to say thank for a huge post and an inside and out exciting site.www.onesureinsurance.co.uk/motor-trade-insurance

I jump at the chance to

I jump at the chance to peruse this post since I met such a large number of new realities about it actually.Thanks a great deal for.how to choose a suitcase

The key topics are really

The key topics are really very important and it is very suitable for the subject of the conference.cosmetic regulatory

Frank

Your articles are really fit authorized and incomparable.Frank

There are so many options out

There are so many options out there that I’m completely overwhelmed .. Any suggestions? Many thanks! http://www.cosless.com/products/premium-magnetic-screen-door

I'll hide your message,

I'll hide your message, though will still try to answer you if I can without spoilers.do my essay

We really enjoyed working

We really enjoyed working with you two! Congratulations.Whakki Media

Allows users to race against

Allows users to race against the computer or other players in multiple race modes.ToolsHQ

It's never too lately to

It's never too lately to meliorate your information and your listing has me.mykonos vacation villas

Unbelievable job mates, I

Unbelievable job mates, I enjoy going through your articles.injured shoulder

The spot else might just I

The spot else might just I understand that sort of data written in such a flawless strategy?pay per install network

As with Goth culture itself,

As with Goth culture itself, having a sense of humour about the whole thing prevents a Gothling from becoming a living.vampire outfits

I'm gladsome to mature so

I'm gladsome to mature so more serviceable and informative assemblage on your website.ok money in browken arrow

I would be appreciating all

I would be appreciating all of your articles and blogs because they are fitting up mark.traders policy

shunleemedia.com

I’m wondering how I could be notified when a new post has been made.shunleemedia.com

I don't cerebrate some of

I don't cerebrate some of websites offer this typewrite of assemblage.GetYourCouponCodes

The author of your blogs and

The author of your blogs and articles and contents is appreciating.patio umbrella

It's nice to see that some

It's nice to see that some people still understand how to write a quality post.http://www.cosless.com/products/premium-magnetic-screen-door

thanks for j sharing with

thanks for j sharing with that awesome articles thanks u a lot
rasoio elettrico | regolabarba | ferro da stiro con caldaia | Friggitrice ad Aria | scopa a vapore | ripetitore wifi | ripetitore wifi amplificatore wifi piastra a vapore | miglior aspirapolvere | skateboard elettrico | passeggino leggero | miglior smartphone | tablet per bambini tyj20

jack

A beats might be fantastic. You possess numerous especially capable actors. I just aspire most people the right from victory.
Wax-U

Your style is very unique in

Your style is very unique in comparison to other folks I have read stuff from. Thanks for posting when you have the opportunity, Guess I will just bookmark this blog.
Mortgage Broker Calgary

If you had a learning

If you had a learning disability in school that may have built up your ability to persevere when things get difficult.www.strengthstransform.com

truly an incredible

Your site is truly an incredible, it is amazing and I will appreciate your job. Things are very open and clearly explain. one solar panels

very cooool juegos friv

very cooool

juegos friv 10
friv 2.0
juegod friv 2.0
juegos friv 2017
juegos friv 20
juegos de friv
juego friv
friv juegos
friv
friv 2
juegos friv 20

good post

i am surprisingly here. I discovered this board and I in discovering It really accommodating and it helped me out a great deal. I would like to present something back and help other people, for example, you helped me.
treat back pain

Awesome and interesting

Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post. one solar

JVM

Hi,

I have two java processes running, one for Tomcat and one for another java application running against the same JVM on same machine on redhat.

1. How would I specify -Xms and –Xmx differently for my second process?
2. And ideally what those values should be?
3. How heap would be allocated and managed for two java processes running on same machine?

For tomcat there are my options

CATALINA_OPTS="-Xmx3072m -Xms2024m -XX:MaxPermSize=512m
4. Should I change my -XX:MaxPermSize=512m To a different value.

For second java process, this is what I have specified

Not sure how these values would affect the performance as I have ‘CATALINA_OPTS="-Xmx3072m -Xms2024m -XX:MaxPermSize=512m’ defined as well.
5. ’

Here is memory available on my machine

cat /proc/meminfo
MemTotal: 3913460 kB

Need help.

Regards,
mobika

first article

where is the first article ?
bad target you set for it.

I’m encouraged while using

I’m encouraged while using surpassing along with preachy list that you just adorn such minor timing.
Easy Moves 4 U

Spartagen XT Reviews

It's superior, however , check out material at the street address.
getfreestuffonlinenow.com Spartagen XT reviews

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.