{"id":6884,"date":"2017-07-21T17:41:12","date_gmt":"2017-07-21T09:41:12","guid":{"rendered":"http:\/\/rmohan.com\/?p=6884"},"modified":"2017-07-21T17:41:12","modified_gmt":"2017-07-21T09:41:12","slug":"garbage-priority-garbage-collector","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6884","title":{"rendered":"Garbage Priority Garbage Collector"},"content":{"rendered":"<header class=\"post-header\">\n<h1 class=\"post-title\">Garbage Priority Garbage Collector (G1 GC) Use notes<\/h1>\n<div class=\"post-meta\"><\/div>\n<\/header>\n<div class=\"post-body\">\n<p>G1 GC is a new garbage collection strategy, starting with JDK7, mainly for server-side JVM, and large memory applications, the goal is to achieve similar high-throughput CMS.\u00a0G1 is still the idea of ??sub-management, the main use of the idea of ??block management, through the memory is divided into no more than 2048 blocks, each size between 1M-32M, Eden, Survivor space and old generation are one Series of discontinuous logical regions.<a id=\"more\"><\/a><\/p>\n<p>Here do not talk about the concrete realization of G1 ideas, only record how to configure and use.<\/p>\n<h2 id=\"??-G1-GC\">Start the G1 GC<\/h2>\n<figure class=\"highlight plain\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"line\">-XX: + UseG1GC<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h2 id=\"????????\">Several parameters and default values<\/h2>\n<ul>\n<li><code>-XX:MaxGCPauseMillis=200<\/code>\u00a0Maximum pause time, which is a target value, JVM will try to close to this target, the default value of 200.<\/li>\n<li><code>-XX:G1HeapRegionSize=n<\/code>\u00a0G1 area block size, 1M-32M, must be a power of 2, G1 will be based on the size of the block plan is not more than 2048 blocks.<\/li>\n<li><code>-XX:G1NewSizePercent=5<\/code>\u00a0Young generation in the heap in the smallest percentage, the default value is 5%<\/li>\n<li><code>-XX:G1MaxNewSizePercent=60<\/code>\u00a0The maximum percentage of young generations in the heap, the default is 60%<\/li>\n<li><code>-XX:ParallelGCThreads=n<\/code>Sets the value of the STW worker thread.\u00a0Set the value of n to the number of logical processors.\u00a0The value of n is the same as the number of logical processors, up to 8.\u00a0If there are more than eight logical processors, set the value of n to about 5\/8 of the number of logical processors.\u00a0This applies to most cases unless it is a larger SPARC system, where the value of n can be about 5\/16 of the number of logical processors.<\/li>\n<li><code>-XX:ConcGCThreads=n<\/code>Sets the number of threads that are marked in parallel.\u00a0Set n to 1\/4 of the amount of parallel garbage collection threads (ParallelGCThreads).<\/li>\n<li><code>-XX:InitiatingHeapOccupancyPercent=45<\/code>\u00a0Mark the garbage threshold, the default 45%<\/li>\n<li><code>-XX:G1ReservePercent=10<\/code>Set the percentage of reserved memory as free space to reduce the risk of target space spillovers.\u00a0The default value is 10%.<\/li>\n<\/ul>\n<h2 id=\"??\">Suggest<\/h2>\n<ul>\n<li>Avoid using the -Xmn option or other related options such as -XX: NewRatio to explicitly set the young generation size.\u00a0Fixed young generation size will cover the pause time target.<\/li>\n<li>Pause time goals are not too small, because pause time and throughput are a contradictory indicator.<\/li>\n<\/ul>\n<h2 id=\"??\">example<\/h2>\n<p>This is a simple configuration of tomcat startup<\/p>\n<figure class=\"highlight plain\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"line\">Export CATALINA_OPTS = &#8220;$ CATALINA_OPTS -Xms10g&#8221;<\/div>\n<div class=\"line\">Export CATALINA_OPTS = &#8220;$ CATALINA_OPTS -Xmx10g&#8221;<\/div>\n<div class=\"line\">Export CATALINA_OPTS = &#8220;$ CATALINA_OPTS -Xss512k&#8221;<\/div>\n<div class=\"line\"><\/div>\n<div class=\"line\">Export CATALINA_OPTS = &#8220;$ CATALINA_OPTS -XX: + DisableExplicitGC&#8221;<\/div>\n<div class=\"line\">Export CATALINA_OPTS = &#8220;$ CATALINA_OPTS -XX: + HeapDumpOnOutOfMemoryError&#8221;<\/div>\n<div class=\"line\">Export CATALINA_OPTS = &#8220;$ CATALINA_OPTS -XX: + UnlockExperimentalVMOptions&#8221;<\/div>\n<div class=\"line\"><\/div>\n<div class=\"line\">Export CATALINA_OPTS = &#8220;$ CATALINA_OPTS -XX: + UseG1GC&#8221;<\/div>\n<div class=\"line\">Export CATALINA_OPTS = &#8220;$ CATALINA_OPTS -XX: MaxGCPauseMillis = 200&#8221;<\/div>\n<div class=\"line\">Export CATALINA_OPTS = &#8220;$ CATALINA_OPTS -XX: G1NewSizePercent = 40&#8221;<\/div>\n<div class=\"line\">Export CATALINA_OPTS = &#8220;$ CATALINA_OPTS -XX: G1MaxNewSizePercent = 80&#8221;<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<blockquote><p><code>G1NewSizePercent<\/code>And\u00a0<code>G1MaxNewSizePercent<\/code>experimental properties, so please through the\u00a0<code>-XX:+UnlockExperimentalVMOptions<\/code>open test option.<\/p><\/blockquote>\n<p>Done.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p> Garbage Priority Garbage Collector (G1 GC) Use notes <\/p>\n<p>G1 GC is a new garbage collection strategy, starting with JDK7, mainly for server-side JVM, and large memory applications, the goal is to achieve similar high-throughput CMS. G1 is still the idea of ??sub-management, the main use of the idea of ??block management, through the memory [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6884"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6884"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6884\/revisions"}],"predecessor-version":[{"id":6885,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6884\/revisions\/6885"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}