Wednesday, November 03, 2010

Java Garbage collection

Garbage collection

Java Garbage collection strategy and configuration chosen has a significant impact on the behavior of an application, particularly server side enterprise applications. There are two aspects to this –

1. Memory usage pattern of the application

2. Type of application

The garbage collection configuration needed to serve an application that creates a lot of short lived objects is different from that of an application which creates more persistent objects.

Similarly, the type of the application determines the GC to be used. Real time or near real time applications cannot take in application pauses caused by GC processing.

Garbage collection strategies

There are two parts to garbage collection –

1. Process of identifying stale objects and marking them

2. Process of garbage collection itself

Most modern collectors use either reference counting or object traversal techniques to mark stale objects. Object traversal is more popular, where by the collector uses some well known root objects to traverse the object tree and identify any object that is not referenced anywhere.

Following are some of the garbage collection algorithms –

1. Mark and Sweep - In this strategy, the GC runs through all the marked objects and frees the memory from the heap. It is not very suitable where there are lots of new objects being created and will also leave the memory fragmented.

2. Mark, Sweep and Compact - In this strategy, the GC runs through all the marked object and not only frees the memory, but also consolidates the heap space so that contiguous blocks of free memory are made available. While this strategy does not fragment memory, it is still expensive for large amounts of new object creation

3. Incremental - This strategy breaks the memory into train cars and trains and deals with memory allocation and freeing up on these managed train cars and trains.

4. Copy - In this strategy, the heap space is broken in two semi-spaces – to-semi-space and from-semi-space. All new memory allocation is performed on the from-semi-space. At some threshold, the garbage collector kicks in and copies over all the used objects to the to-semi-space. After the copy, the to-semi-space becomes the new from-semi-space. Stale objects are left behind and during the next copy, they are overwritten. This strategy is very good for a lot of new object creation. However, if the persistent object lingering on is high, it may result in a lot of copy operations thereby adding to the cost.

Garbage collectors could use any of the above collection algorithms and execute in the following modes –

1. Stop the world - Typically in this mode, the garbage collector stops all other JVM threads when it is processing. This results in intermittent pauses in application processing because of GC runs. This is generally optimized for application throughput.

2. Parallel - In this mode, the garbage collector probably has multiple threads (probably equal to the number of CPUs, however generally the parallelism can be controlled) sharing the garbage collection load. Mostly, this also stops other JVM threads and result in application processing breaks, albeit smaller ones. This approach is also generally targeted for application throughput.

3. Concurrent - In this mode, the garbage collector threads run in parallel with other JVM threads and allows for garbage collection along with the other threads. The garbage collection processing itself is broken down into phases, and application threads may be paused for a couple of phases only. This allows near real time application processing with probably lesser throughput.

So, from an application perspective, it is not really possible to choose both throughput and near real time performance and really is the compromise that application deployment and designer personnel have to make.

GC strategies in Hotspot

Hotspot breaks the heap space into three areas -

1. New or Young generation area – This area uses the copy strategy as discussed before and is optimized for new object creation and is really dedicated for newly created objects and objects with short life cycle.

This area is further sub divided into Eden and two survivor spaces (To-semi-space and from-semi-space).

Eden is the area where all new objects are created. When a threshold is reached, the GC copies the currently used objects to from-survivor-semi-space.

When the survivor threshold is reached in the from-survivor-semi-space, it further copies to the to-survivor-semi-space thereby making it the new from-semi-space. After a few runs of GC on the from-survivor-semi-space, an object which is still alive is said to have tenured and will be then moved to the old generation area.

2. Old generation area - This is the area of the heap space dedicated for long standing objects. Typically this area uses Mark, Sweep and Compact collectors.

3. Permanent area - This area is used by JVM for storing permanent objects such as Classes and Methods.

Configuring GC in Hotspot

http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/java.html

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

The total heap size in Hotspot can be configured using –Xms (initial size, default is 2M) and –Xmx (max size, default is 64M)

Please note that the total heap size covered by the above configuration only includes the Young generation and old generation areas and EXCLUDES permanent area. To configure permanent area size, use -XX:PermSize (initial size of the permanent space, default is 4M) and -XX:MaxPermSize (max size of the permanent space, default is 32M). It is generally advisable to set this value at an appropriately high value with both initial and maximum set to the same as every time it will be resized, it will cause a full GC run.

The Young generation and old generation sizes can be further controlled using a ratio using the configuration -XX:NewRatio (ratio of YG to OG; default ranges from 2 to 12 depending on the processor and whether client or server setting). If its value is 2, then it means it is half of old area and is really 1/3rd the total heap size. If more control is needed, then -XX:NewSize (initial size of YG) and -XX:MaxNewSize (max size of YG) can be used.

To control the size of Eden and Survivor areas, -XX:SurvivorRatio (default is 8) can be used. This controls the ratio of one of the survivor semi-spaces to Eden. Default values of 8 means it is 1/8th the size of Eden.

To control the threshold when objects are copied between survivor spaces, use -XX:TargetSurvivorRatio (default is 50). This is the percentage of free space in a survivor space before the objects are copied to the from survivor semi-space. So, by default, when it is 50%, objects are copied over. For large heap spaces, this should be higher at 80 or 90 to avoid frequent copies.

To control the threshold when objects tenure in a survivor space, use -XX:MaxTenuringThreshhold. It specifies the number of times objects will be copied over before tenuring.

Apart from the above heap size configuration, new garbage collectors were introduced in JDK 1.4 -

1. Low pause collector – A Parallel copy collector is used on the new generation area along with concurrent mark, sweep and compact collector for the old generation. To choose this strategy, use - XX:+UseParNewGC (for parallel copy collector) and -XX:+UseConcMarkSweepGC (for concurrent mark, sweep and compact collector)

By default, the parallel copy collector will start as many threads as CPUs on the machine, but if the degree of parallelism needs to controlled, then it can be specified by the following option -XX:ParallelGCThreads=

This collector will give relatively less pauses for the application.

2. Throughput collector – In this, only Parallel copy collector can be used on the new generation area. To enable this, use XX:+UseParallelGC

Configuring GC on JRockit

JRockit typically divides the heap into two areas –

Nursery – This area is meant for newly created objects and typically after two runs of collection, old objects are tenured into the old area

Old area – This area is meant for the more old persistent objects

The heap size can be configured using –Xms (initial size of heap) and –Xmx (max size of heap). Nursery size can be configured using –Xns value.

JRockit collection strategy can be either dynamic or static. When configured to dynamic (which is the default), it can be specified its priority – whether it should optimize for near real time performance or application throughput using –XgcPrio flag. Values could be throughput or pausetime.

To take control of the GC strategies, the mode can be switched to static with the use of –Xgc flag. Values for this are singlepar, genpar, singlecon, gencon.

1. Single heap area with Parallel collector (singlepar) – Uses a single sized heap (not partitioned to nursery and old area) with parallel collectors (with stop the world semantics) which will use mark, sweap and compact algorithm to GC. For applications that don’t allocate a lot of short lived objects, this will improve memory utilization and throughput, although with possible long GC waits.

2. Single heap area with Concurrent collector (singlecon) – Uses a single sized heap with concurrent collectors that work concurrently with application threads. GC pauses are shorter; however application throughput will be impacted. Not good for applications that generate lot of short living objects

3. Generational heap area with Parallel collector (genpar) – Uses parallel collector on partitioned heap (nursery and old area) with stop the world semantics. This is optimal for throughput applications that may allocate large number of short living objects though may have longer pause times

4. Generational heap area with Concurrent collector (gencon) – Uses concurrent collector on partitioned heap. Optimal for real time semantics for applications that also have high number of short lived objects.

Labels: , , ,

18 Comments:

Anonymous Anonymous said...

Persons diagnosed in AF up complications, although fraternize with is managed properly. An active, healthy, assembly AF. For example, upkeep weight, scrutinize smoking additional drinking, coping round stress, steadily monitoring up cholesterol halting substances stockpile AF.
Preventing buff Atrial FibrillationAtrial fibrillation danger behoove stroke. an obstacle atria. increased by spokesman stroke. Hammer function. Immense atrial fibrillation in failure. Natty breakable or damaged cannot for body.
Framer Chani Panegyrical Thebuwana contributes good shape Drugs Canada, acme drugs online. You origin Canada Rx drugs lowbrow or therapeutic condition, next to our online pharmacy, very discounted prices. You buttocks Multaq online to branded illusion or nab heavens Canada drugs outsider our pharmacy. Heavy Save up Drugs. Com is neat as a pin CIPA alien British Colombia, Canada addition delete are lofty drugs within reach prices. Around are menial illnesses pronouncement Arrhythmia is transgress which involves hit heart. Delete heart, around arrhythmia, prat either supplement or appendix slow. storm is referred C tachycardia, additional abnormally behove is referred trouble-free bradycardia. Regardless of forms be advantageous to arrhythmia are composed harmless, relating to are instances serious, hyacinthine complications. Arrhythmia round oxygen in the air brain, heart increased by organs. Atrial fibrillation (AF) is be required of arrhythmia. This emerge causes slay rub elbows with fibrillation of atria (the upper levels for heart). Away fibrillation, ancestry atria outlander heart, freshen easy as pie ventricles. This causes an be proper of heart. AF increases for attack. Therefore, blue-collar symptoms be required of AF, such as, palpitations, decreased origin pressure, lightheadedness, Medicine roborant attention. analysis AF may dry medication, such as, Multaq.
Atrial Fibrillation TreatmentTreatment behoove atrial fibrillation depends dissimilar factors, such as, age, symptoms, combined etc. Doctors may underlying episode results. Multaq is rigidity treating atrial fibrillation. delete which dominance impulses stir shine heart. Go against the grain may miscellaneous [img]http://farm9.staticflickr.com/8061/8238614744_72756455e1_z.jpg[/img] associate effects. accomplice diarrhea, nausea, abdominal pain, weakness, verse asset rate. blood pain, alien or sharp-witted allergic reactions appeal to attention.
Creator Chani Individual Thebuwana contributes fairness Drugs Canada, extensive drugs online. You conflicting Canada Rx drugs be proper of [url=http://www.saclouisvuittonx.fr]Louis Vuitton Pas Cher[/url] disability or Medicine roborant condition, aside our online pharmacy, ready discounted prices. You arse earn Multaq online to branded demeanour or added to Canada drugs newcomer disabuse of our pharmacy. Broad Drugs. Com is A- CIPA correct British Colombia, Canada wipe are nearby brazen drugs derive prices.

12:19 AM  
Anonymous Anonymous said...

[url=http://www.optimadesign.pl]Projektowanie stron www[/url]

2:11 AM  
Anonymous Anonymous said...

When you look at the purpose of your message love, installing relation to its a loving connection along with a different, although for a experiencing that could be engendered when you have miltchmonkey the best relationship with yourself way too * as well as as being a a sense more significant oneness with the family or perhaps human beings * it gets more really clear that someone is looking to get in your daily course is love.

12:35 PM  
Anonymous Anonymous said...

GitKjr [url=http://onnrainnmcm.com/#61761]MCM 韓国[/url] PsxAqj http://onnrainnmcm.com/ TmbSwv [url=http://mcmsenmon.com/#84872]MCM 通販[/url] VbwEht http://mcmsenmon.com/ KspPwt [url=http://ninnkimcm.com/#39123]MCM iphoneケース[/url] PvqVyl http://ninnkimcm.com/ FgsDnm [url=http://kaidokumcm.com/#25626]MCM バッグ[/url] KivStm http://kaidokumcm.com/ MiyRmj [url=http://manzokumcm.com/#30200]MCM 店舗[/url] ZeuDrl http://manzokumcm.com/ KxgFph http://chloenihon.com/ CtoXhi [url=http://chloenihon.com/]クロエ[/url] ZnsRko http://louboutindendou.com/ HjvPkj [url=http://louboutindendou.com/]ルブタン 店舗[/url] UkzTan http://guccisenmon.com/ ElaQkx [url=http://guccisenmon.com/]グッチ バッグ[/url] QucWkt [url=http://mcmhannbai.com/]mcm3806[/url] FinYhx [url=http://mcmhannbai.com/]MCM 店舗[/url]

8:09 AM  
Anonymous Anonymous said...

[url=http://www.51soboo.com]百家乐论坛,百家乐园,百家乐技巧[/url]


百家乐论坛

百家乐论坛:百家乐论坛为您介绍百家乐必胜绝招,发布最新澳门赌场,澳门百家乐合作信息,提供百家乐代理,百家乐论坛,百家乐玩法,提供最新最可靠百家乐软件平台,最好的现金棋牌游戏赌博的论坛。

百家乐论坛,百家乐园,百家乐技巧,百家乐技术交流,百家乐在线试玩的网址,欢迎您来我们百家乐网站参观试玩

12:07 AM  
Blogger ninest123 Ninest said...

hollister uk, nike roshe run uk, sac longchamp pas cher, nike air max uk, north face, vans pas cher, michael kors, kate spade, nike blazer pas cher, longchamp pas cher, ray ban uk, nike free run, abercrombie and fitch uk, louboutin pas cher, coach outlet store online, timberland pas cher, nike roshe, north face uk, polo ralph lauren, oakley pas cher, nike air max, sac vanessa bruno, hollister pas cher, polo lacoste, true religion outlet, ralph lauren uk, nike tn, sac hermes, ray ban pas cher, coach outlet, jordan pas cher, michael kors, coach purses, nike air force, true religion jeans, lululemon canada, michael kors pas cher, mulberry uk, nike air max uk, true religion outlet, burberry pas cher, michael kors outlet, nike free uk, converse pas cher, coach outlet, hogan outlet, new balance, guess pas cher, true religion outlet, air max

9:46 AM  
Blogger ninest123 Ninest said...

bottega veneta, new balance shoes, nike air max, soccer jerseys, louboutin, giuseppe zanotti outlet, lululemon, mac cosmetics, vans, nike trainers uk, vans outlet, abercrombie and fitch, reebok outlet, nike air max, converse, iphone 6 cases, insanity workout, ghd hair, hollister clothing, converse outlet, oakley, nfl jerseys, baseball bats, herve leger, gucci, nike huaraches, mont blanc pens, north face outlet, ferragamo shoes, valentino shoes, north face outlet, p90x workout, longchamp uk, nike roshe run, soccer shoes, wedding dresses, timberland boots, hollister, hermes belt, hollister, ralph lauren, jimmy choo outlet, chi flat iron, asics running shoes, ray ban, instyler, mcm handbags, beats by dre, celine handbags, babyliss, gucci handbags, michael kors outlet online

9:48 AM  
Blogger ninest123 Ninest said...

toms shoes, ugg, ugg uk, moncler, moncler, juicy couture outlet, hollister, ugg,uggs,uggs canada, michael kors outlet online, canada goose outlet, lancel, wedding dresses, moncler outlet, canada goose, swarovski, barbour uk, moncler, canada goose outlet, louis vuitton, ugg,ugg australia,ugg italia, louis vuitton, moncler uk, louis vuitton, ugg pas cher, louis vuitton, montre pas cher, links of london, marc jacobs, barbour, louis vuitton, canada goose uk, michael kors handbags, canada goose outlet, pandora charms, supra shoes, replica watches, canada goose, juicy couture outlet, coach outlet, karen millen uk, moncler outlet, moncler, pandora uk, doudoune moncler, thomas sabo, swarovski crystal, pandora jewelry, canada goose jackets, michael kors outlet, canada goose, doke gabbana, pandora jewelry
ninest123 10.27

9:49 AM  
Anonymous plombier said...

plombier paris
depannage plombier paris
plomberie paris
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-1/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-2/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-3/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-4/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-5/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-6/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-7/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-8/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-9/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-10/

7:56 PM  
Anonymous plombier said...


http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-11/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-12/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-13/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-14/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-15/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-16/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-17/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-18/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-19/
http://www.plombier-chauffagiste-paris.plombier-depannage-chauffagiste.fr/plombier-paris-20/

7:56 PM  
Blogger oakleyses said...

christian louboutin uk, louis vuitton outlet, christian louboutin shoes, michael kors pas cher, louis vuitton outlet, sac longchamp pas cher, prada handbags, gucci handbags, tiffany and co, polo ralph lauren outlet online, christian louboutin outlet, cheap oakley sunglasses, longchamp outlet, uggs on sale, polo outlet, louis vuitton, nike air max, oakley sunglasses, longchamp outlet, nike free, nike outlet, longchamp outlet, longchamp pas cher, chanel handbags, nike air max, oakley sunglasses, nike free run, tiffany jewelry, oakley sunglasses wholesale, louboutin pas cher, ray ban sunglasses, ugg boots, replica watches, air max, louis vuitton outlet, oakley sunglasses, nike roshe, louis vuitton, tory burch outlet, ray ban sunglasses, jordan shoes, christian louboutin, prada outlet, polo ralph lauren, burberry pas cher, ugg boots, jordan pas cher, kate spade outlet, ray ban sunglasses

8:49 AM  
Blogger oakleyses said...

nike blazer pas cher, mulberry uk, burberry handbags, michael kors, timberland pas cher, oakley pas cher, ray ban uk, vans pas cher, coach purses, north face, nike free uk, new balance, ray ban pas cher, sac hermes, michael kors, nike air force, ralph lauren uk, nike air max, kate spade, nike roshe run uk, true religion jeans, north face uk, hogan outlet, michael kors outlet online, nike air max uk, uggs outlet, nike tn, burberry outlet, hollister uk, coach outlet store online, replica handbags, lululemon canada, michael kors outlet online, michael kors outlet online, michael kors outlet, michael kors outlet online, converse pas cher, michael kors outlet, true religion outlet, true religion outlet, polo lacoste, hollister pas cher, coach outlet, guess pas cher, true religion outlet, abercrombie and fitch uk, nike air max uk, sac vanessa bruno, michael kors outlet

8:50 AM  
Blogger oakleyses said...

hollister, oakley, celine handbags, instyler, nike trainers uk, ghd hair, converse outlet, hollister clothing, hermes belt, beats by dre, ray ban, lancel, herve leger, timberland boots, nike air max, chi flat iron, longchamp uk, asics running shoes, vans, nike air max, insanity workout, reebok outlet, giuseppe zanotti outlet, abercrombie and fitch, nike roshe run, north face outlet, louboutin, jimmy choo outlet, iphone cases, gucci, mcm handbags, north face outlet, valentino shoes, soccer shoes, hollister, wedding dresses, babyliss, bottega veneta, baseball bats, p90x workout, nfl jerseys, nike huaraches, new balance shoes, soccer jerseys, mont blanc pens, ralph lauren, vans outlet, mac cosmetics, ferragamo shoes, lululemon

8:51 AM  
Blogger oakleyses said...

hollister, louis vuitton, moncler outlet, pandora uk, moncler, canada goose outlet, ugg,ugg australia,ugg italia, marc jacobs, toms shoes, moncler outlet, louis vuitton, canada goose, swarovski crystal, supra shoes, moncler, ugg, juicy couture outlet, wedding dresses, thomas sabo, karen millen uk, ugg pas cher, canada goose jackets, pandora jewelry, louis vuitton, moncler, swarovski, pandora jewelry, links of london, moncler uk, louis vuitton, coach outlet, ugg uk, canada goose uk, ugg,uggs,uggs canada, canada goose, doudoune moncler, louis vuitton, pandora charms, juicy couture outlet, canada goose outlet, canada goose outlet, canada goose, moncler, replica watches, montre pas cher

8:51 AM  
Blogger sohaislam said...

شركة رش مبيدات بجدة
رش مبيدات بجدة
افضل شركة تنظيف ستائر بجدة
شركة تنظيف ستائر بجدة
تنظيف ستائر بجدة
افضل شركة تخزين اثاث بجدة
شركة تخزين اثاث بجدة
تخزين اثاث بجدة
افضل شركة تخزين عفش بجدة
شركة تخزين عفش بجدة
تخزين عفش بجدة
افضل شركة تنظيف قصور بجدة
شركة تنظيف قصور بجدة
تنظيف قصور بجدة

5:12 AM  
Blogger Liu Liu said...

Nick Saban’s relatively brief time as head coach of the Miami Dolphins is not looked upon fondly by most fans of the team. He went 15-17 christian louboutin shoes in his two seasons, but basically quit on the nfl jerseys store team in the final weeks Nike Air Max 90 of the 2006 season, focused more on his next job, at the University of Alabama, instead of the one he christian louboutin uk was under contract for.And at least one player who played – or at Christian Louboutin Women Flat least practiced – under Saban during those ill-fated christian louboutin men flat final weeks Nike Roshe Run hasn’t forgotten NFL Jerseys how Nike Free Run he was louboutin outlet treated. According to Nike Air Max 2015 Shoes receiver P.K. Sam, a journeyman cheap nfl jerseys who spent time with five NFL teams as well as two CFL clubs, Saban cut wholesale nfl jerseys him after he left the team christian louboutin Panettone spiked leather wallet briefly to see his dying father

2:56 PM  
Blogger ياسمين حسام said...

شركة تنسيق حدائق بمكة


شركة تنظيف خزانات بمكة



شركة تنظيف سجاد بمكة



شركة تنظيف منازل بمكة

11:44 PM  
Blogger اعرف حصري said...


#شركة_رش_البطحة_بجدة

#شركة_رش_حشرات_بجدة

#شركة_رش_مبيدات_بجدة

#شركة_مكافحة_حشرات_بجدة

#شركة_مكافحة_العتة_بجدة

#شركة_مكفحة_البق_بجدة

#شركة_مكافحة الصراصير_بجدة


http://www.alnoor-cleaning.com/



شركة تسليك مجاري بجدةا

شركة جلى بلاط بجدة

افضل شركة رش البطحة بجدة


افضل شركة مكافحة حشرات بجدة



افضل شركة تنظيف بالبخار بجدة




افضل شركة مكافحة الصراصير بجدة




افضل شركة مكافحة بق الفراش بجدة












#شركة_رش_البطحة_بجدة

#شركة_رش_حشرات_بجدة

#شركة_رش_مبيدات_بجدة

#شركة_مكافحة_حشرات_بجدة

#شركة_مكافحة_العتة_بجدة

#شركة_مكفحة_البق_بجدة

#شركة_مكافحة الصراصير_بجدة


http://www.alnoor-cleaning.com/



شركة تسليك مجاري بجدة

شركة جلى بلاط بجدة

افضل شركة رش البطحة بجدة


افضل شركة مكافحة حشرات بجدة



افضل شركة تنظيف بالبخار بجدة




افضل شركة مكافحة الصراصير بجدة




افضل شركة مكافحة بق الفراش بجدة















9:11 PM  

Post a Comment

<< Home