groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alain Stalder <astal...@span.ch>
Subject Re: Improve Groovy class loading performance and memory management
Date Tue, 17 May 2016 07:04:49 GMT

On 17.05.16 07:53, Alain Stalder wrote:
> I will definitely try out the InvokerHelper.removeClass(clazz) with 
> added ClassInfo removal plus Introspector.flushFromCaches(clazz) and 
> see if I can get garbage collection before reaching the limit on 
> Metaspace or Heap.
Fantastic, I really got it to work :)

I took groovy master plus changes for GROOVY-7646 and GROOVY-7683 and 
modified the test in ClassGCTester as follows:

--
                 long nanoT0 = System.nanoTime();
                 Class<?> clazz = classLoader.loadClass(testClassName);
                 long nanoT1 = System.nanoTime();
                 clazz.newInstance();
                 long nanoT2 = System.nanoTime();
                 loadTimeTotal += (nanoT1 - nanoT0);
                 createTimeTotal += (nanoT2 - nanoT1);
                 weakFillingClassesMap.put(clazz, "");

                 // added:
                 Class<?> invokerHelperClass = 
ClassGCTester.class.getClassLoader().loadClass("org.codehaus.groovy.runtime.InvokerHelper");
                 Method removeClassMethod = 
invokerHelperClass.getDeclaredMethod("removeClass", Class.class);
                 removeClassMethod.invoke(null, clazz);
                 //Introspector.flushFromCaches(clazz);
--

An then ran the test as follows (not using ClassValue, loading the test 
class not from the same ClassLoader as Groovy itself):

$ java -XX:MaxMetaspaceSize=64m -Xmx512m -cp .:groovy-2.5.0-SNAPSHOT.jar 
ClassGCTester -cp filling/ -parent tester -classes GroovyFilling

--
Secs Test classes              Metaspace/PermGen Heap   Load time Create 
time
        #loaded  #remaining        used committed       used 
committed     average     average
    0         1           1       6.3m       6.5m      12.8m 245.5m     
0.838ms    11.112ms
    1       486         486       9.2m      10.5m      27.6m 245.5m     
0.326ms     1.624ms
    2      1404        1404      12.7m      16.1m      30.3m 245.5m     
0.244ms     1.124ms
    3      2308          61       7.6m      16.8m      12.2m 228.5m     
0.241ms     1.014ms
    4      3461        1214      12.0m      16.8m      46.4m 244.0m     
0.212ms     0.908ms
    5      4577        2330      16.3m      21.4m      69.1m 240.0m     
0.200ms     0.860ms
    6      5581        3334      20.1m      27.4m      75.1m 237.5m     
0.197ms     0.847ms
    7      6703         974      11.1m      18.2m      11.3m 268.0m     
0.197ms     0.818ms
    8      7996        2267      16.0m      23.4m      65.7m 253.5m     
0.188ms     0.786ms
    9      9261        3532      20.9m      28.5m     115.1m 267.5m     
0.182ms     0.765ms
   10     10518         960      11.0m      20.0m      10.9m 285.0m     
0.181ms     0.747ms
   11     11841        2283      16.1m      24.0m      68.9m 285.0m     
0.177ms     0.730ms
   12     13097        3539      20.9m      29.0m     113.9m 285.0m     
0.173ms     0.722ms
   13     14288         331       8.7m      21.3m      49.6m 314.0m     
0.174ms     0.715ms
   14     15640        1683      13.8m      22.9m     105.5m 316.0m     
0.170ms     0.705ms
   15     16923        2966      18.7m      27.9m     150.4m 315.5m     
0.168ms     0.699ms
   16     18128        4171      23.3m      32.6m      54.6m 316.0m     
0.166ms     0.697ms
   17     19360         628       9.8m      21.5m      88.6m 347.0m     
0.167ms     0.692ms
   18     20707        1975      15.0m      24.6m     137.6m 346.5m     
0.165ms     0.685ms
   19     21958        3226      19.7m      29.6m      39.1m 347.5m     
0.164ms     0.683ms
   20     23172        4440      24.4m      34.4m      66.4m 349.5m     
0.163ms     0.682ms
   21     24430         861      10.7m      21.9m     120.7m 383.5m     
0.163ms     0.678ms
   22     25725        2156      15.7m      25.5m      19.0m 381.0m     
0.162ms     0.675ms
   23     26986        3417      20.5m      30.5m      49.3m 385.0m     
0.161ms     0.674ms
   24     28192        4623      25.1m      35.3m      70.8m 384.5m     
0.161ms     0.673ms
   25     29454         956      11.1m      21.0m     134.6m 416.0m     
0.161ms     0.671ms
   26     30737        2239      16.0m      26.3m      25.2m 416.5m     
0.160ms     0.669ms
[...]
--

Nicely garbage collects repeatedly, Metaspace stay well below the 
configured maximum of 64m...

PS: Note that Introspector.flushFromCaches(clazz) was experimentally 
really not necessary in this case, but maybe has to do with the simple 
nature of the test script ("42") and only calling a (no-args) 
constructor... In any case very promising...

Alain




Mime
View raw message