Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6831639

G1: G1 collector performance with LinkedHashMap

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • 7
    • 6u10
    • hotspot
    • gc
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      I wrote a little benchmark for testing the G1 collector with the LinkedHashMap class. I never leave more than 2 entries in the map. When using the default collector, performance is quite good, but with G1 the GC pauses frequently and the VM consumes huge amounts of memory.

      JUSTIFICATION :
      Many users of the new G1 collector might run similar benchmarks and conclude that the G1 collector performs poorly overall. I suspect that in a real application G1 will behave much better.

      I almost filed this as a bug, because it seems that the collector shouldn't have to work so hard to collect (what I believe) is nothing but garbage. Since the collector is actually working (slowly), I consider this an RFE.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect the performance of G1 in this simple test to be as good as the default collector.
      ACTUAL -
      Performance is extremely poor, with frequent long GC pauses.

      ---------- BEGIN SOURCE ----------
      import java.util.LinkedHashMap;
      import java.util.Map;

      public class CacheTest {
          public static void main(String[] args) throws Exception {
              Map<Object, Object> cache = new LinkedHashMap<Object, Object>();
              long i = 0;
              while (true) {
                  cache.put(i, new String());
                  cache.remove(i - 1);
                  i++;
                  if (i % 100000 == 0) {
                      System.out.println(i);
                  }
              }
          }
      }

      C:\>"\Program Files\Java\jre6\bin\java.exe" -version
      java version "1.6.0_14-ea"
      Java(TM) SE Runtime Environment (build 1.6.0_14-ea-b04)
      Java HotSpot(TM) Client VM (build 14.0-b13, mixed mode, sharing)


      C:\>"\Program Files\Java\jre6\bin\java.exe" -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -verbose:gc CacheTest
      [GC pause (young) 1024K->124K(8192K), 0.0017905 secs]
      [GC pause (young) 2172K->1872K(8192K), 0.0206060 secs]
      [GC pause (young) 2896K->2744K(16M), 0.0214125 secs]
      [GC pause (young) 5816K->5352K(32M), 0.0337724 secs]
      100000
      200000
      300000
      400000
      500000
      600000
      [GC pause (young) 58M->50M(105M), 0.5629917 secs]
      700000
      800000
      900000
      1000000
      1100000
      1200000
      [GC pause (young)-- 116M->117M(122M), 1.1623899 secs]
      1300000
      [Full GC 121M->116K(8192K), 0.0933021 secs]
      1400000
      1500000
      1600000
      1700000
      [GC pause (young) 43M->36M(83M), 0.4415740 secs]
      ...




      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use default collector instead.

            tonyp Tony Printezis
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: