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

Thread Stack Size

Is there any other way to determine the minimal thread stack size other than the method you described? Perhaps by using VisualVM or another tool to identify stack sizes?

I'm not aware of another way

I'm not aware of another way to do this, but I'd welcome suggestions if there is a better way.

I am interested in such

I am interested in such topics so I will address page where it is cool described. Binäre Optionen

Such sites are important

Such sites are important because they provide a large dose of useful information ... Pet Relocation

Writing with style and

Writing with style and getting good compliments on the article is quite hard, to be honest.But you've done it so calmly and with so cool feeling and you've nailed the job. This article is possessed with style and I am giving good compliment. Best! Seo Firmaları

I understand this column. I

I understand this column. I realize You put a many of struggle to found this story. I admire your process. travel umroh 2016

Thanks

It is good, a well structured article, seems like it is your original though. Keep writing and share your idea
Cara memutihkan kulit wajah secara alami dan cepat, Hijab tutorial paris 2013 simple, Aneka resep dan cara membuat kue bolu,
harga dan spesifikasi apple ipod touch 5 terbaru, cara membuat slime mudah dan praktis

I can recommend primarily

I can recommend primarily decent and even responsible tips, as a result view it: locksmith coral springs

Glad to chat your blog, I

Glad to chat your blog, I seem to be forward to more reliable articles and I think we all wish to thank so many good articles, blog to share with us. xbox 360 controller

Actually I read it yesterday

Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written. arthritis causes

This is my first time i visit

This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work. I have been meaning to write something like this on my website and you have given me an idea. circuito cerrado

I might suggest solely

I might suggest solely beneficial in addition to trusted facts, and so find it: Donations for education

Listed here you'll learn it

Listed here you'll learn it is important, them offers the link in an helpful webpage: stock price alerts

It's superior, however ,

It's superior, however , check out material at the street address. https://www.uklingerie.com

Very good topic, similar

Very good topic, similar texts are I do not know if they are as good as your work out. matcha green tea

I like to recommend

I like to recommend exclusively fine plus efficient information and facts, hence notice it: massage

I simply believed it might be

I simply believed it might be a concept to publish in case other people had been having issues studying however I'm just a little uncertain basically 'm permitted to place titles as well as handles upon right here.
iSEO Company

I encourage you to read this

I encourage you to read this text it is fun described ... cafe sedir

This is very useful, although

This is very useful, although it will be important to help simply click that web page link: cafe berjer

Interestingly you write, I

Interestingly you write, I will address you'll find exciting and interesting things on similar topics. รายได้เสริม

Great info! I recently came

Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have. จีคลับ168

This is very interesting, but

This is very interesting, but it is necessary to click on this link: vhproperty.com

I can recommend primarily

I can recommend primarily decent and even responsible tips, as a result view it: Lithium ion battery manufacturers

I should say only that its

I should say only that its awesome! The blog is informational and always produce amazing things. ทำตาสองชั้น

I invite you to the page

I invite you to the page where you can read with interesting information on similar topics. libro factor quema grasa

This is very interesting

This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. hareketli kablo taşıma kanalı

You ought to basically

You ought to basically fantastic not to mention solid advice, which means notice: เกมส์สล็อต

acompanhantes rio de janeiro

Thanks guys, for sharing this conductive accumulation.acompanhantes rio de janeiro

I just thought it may be an

I just thought it may be an idea to post incase anyone else was having problems researching but I am a little unsure if I am allowed to put names and addresses on here. แพ็คเกจ ทัวร์เกาหลี

A unique campaign, and a ton

A unique campaign, and a ton of replayability through randomly generated maps and missions.free online games

carrageenan is safe

I am very thankful to all your team for sharing such inspirational information.carrageenan is safe

Obat Herbal Paling Ampuh

Obat Herbal HIV AIDS Terbaru Telah Ditemukan amazon Plus adalah salah satu Obat Tradisional HIV/AIDS terpercaya&terbaik. Menurut Dr. F.Franklin L.L., sebagai konseling yang telah menunjukkan manfaat Obat Tradisional HIV amazon mampu menyembuhkan kepada pasien penyakit AIDS. Dengan hadirnya Obat HIV/AIDS amazon pastinya amat membantu kepada kebanyakan pasien AIDS agar mampu bertahan hidup lebih lama.

Obat Miom Paling Ampuh Tanpa Operasi Jawaban paling tepat untuk mengatasi penyakit miom, menggunakan Obat Tradisional amazon Penyakit Miom, yang secara alami bisa mengatasi penyakit miom bebas efek samping karena Obat Tradisional amazon Penyakit Miom dibuat dari bahan yang seratus % tradisional tidak ada kandungan bahan-bahan kimia di dalamnya.

Obat Kanker Paru Paru Stadium 4 amazon Jus Kulit Manggis sangat efektif & aman jika diminum. Mampu membantu mencegah dan menyembuhkan penyakit kanker paru-paru tanpa operasi maupun kemoterapi. Agar lebih efektif konsumsilah secara rutin Jus Herbal setiap hari.

Toko Online Diherbal.com menawarkan jenis herbal berkualitas tinggi dengan tujuan untuk memperbaiki mutu kesehatan Anda. Diherbal.com merupakan toko online yang menjual obat obatan herbal bermutu.

Keep sharing many techniques.

Keep sharing many techniques. eagerly waiting for your new blog and useful information. keep doing more.uk essay

Diherbal Online Shop

Obat Tumor Hati Ganas Saya menderita kanker hati, tapi masih belum begitu berbahaya. Sesegera mungkin saya mencari obat-obatan alami yang dapat membantu mematikan sel kanker ini. Akhirnya saya memperoleh Jus Kulit Manggis Obat Tradisional Penyakit Kanker via website. Saya mengonsumsi Amazon sebanyak 6 botol selama satu bulan. Khasiatnya sudah terasa terjadi perkembangan pada arah penyembuhan untuk sakit kanker yang saya derita.

Obat Kanker Usus Stadium 4 Amazon Plus mengandung anti oksidan super yang bersifat untuk menumpas semua macam sel kanker yang tumbuh pada dalam sistem pencernaan terutama pada bagian usus besar, sehingga Amazon Plus ditetapkan sebagai Obat Herbal Kanker Usus Stadium 4 Paling Ampuh di Indonesia.

Obat Kanker Otak Tanpa Operasi K-Muricata dan Amazon Plus harapan baru dalam mengobati kanker otak tanpa operasi. Miom dan kanker otak hilang, masa kehamilan pun datang berkat obat herbal kanker otak paling ampuh K-Muricata dan Amazon Plus.

Toko Obat Herbal GrosirAmazonPlus.com kami menjual segala jenis herbal berkualitas tinggi bermaksud untuk membantu meningkatkan mutu kesehatan Anda. Kami adalah pusat grosir obat herbal terbesar di Indonesia.

Really i wish to thank you.It

Really i wish to thank you.It is about blogging and you cover everything that related information.car covers

I invite you to the page

I invite you to the page where you can read with interesting information on similar topics. ดูบอลสด

This is very interesting

This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. cykelhjelm med lys

These you will then see the

These you will then see the most important thing, the application provides you a website a powerful important internet page: webdesign fuer steuerberater

I read this article. I think

I read this article. I think You put a lot of effort to create this article. I appreciate your work. rezept brigadeiro

I also wrote an article on a

I also wrote an article on a similar subject will find it at write what you think. word vorlagen agentur

Fantastic blog post given

Fantastic blog post given here. This is one of the best blog posts that I've read on your blog in a long time. You have done an outstanding job here. I hope you keep it going on. http://geniotop.com/

It's really nice and meanful.

It's really nice and meanful. it's really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information. Jasa Desain Rumah

Alternatively, you can bypass

Alternatively, you can bypass those steps and quickly get out of the starting blocks by enlisting our help.informative post

unsecured debt consolidation loans

I'm gladsome to mature so more serviceable and informative assemblage on your website.unsecured debt consolidation loans

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

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

Post new comment

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