Project

General

Profile

« Previous | Next » 

Revision cc251391

Added by Andreas Kohlbecker about 8 years ago

support for both memory models java 7 and java 8

View differences:

src/main/java/eu/etaxonomy/cdm/server/AssumedMemoryRequirements.java
15 15
 */
16 16
public class AssumedMemoryRequirements {
17 17

  
18
    // memory requirements
19
	public static final int KB = 1024;
20
	public static final long MB = 1024 * KB;
21
    public static final long PERM_GEN_SPACE_PER_INSTANCE = 55 * MB;
22
    public static final long HEAP_PER_INSTANCE = 130 * MB;
23
    public static final long PERM_GEN_SPACE_CDMSERVER = 19 * MB;
24
    public static final long HEAP_CDMSERVER = 15 * MB;
18
    // these values are best obtaines by using the following command sequence:
19
    // export JPID=$(jps | grep Jetty | awk '{ print $1}'); jcmd $JPID GC.run; sleep 1;  jstat -gc $JPID | sed -e 's/ \+/\t/g'
20

  
21
    /*
22
     * From Java 8 on PermGen is replaced by the Metaspace
23
     *
24
     * Metaspace capacity:
25
     *
26
     * By default class metadata allocation is
27
     * limited by the amount of available native memory (capacity will
28
     * of course depend if you use a 32-bit JVM vs. 64-bit along with OS
29
     * virtual memory availability). A new flag is available
30
     * (MaxMetaspaceSize), allowing you to limit the amount of native
31
     * memory used for class metadata. If you don’t specify this flag,
32
     * the Metaspace will dynamically re-size depending of the
33
     * application demand at runtime.
34
     */
35

  
36
    public static final int KB = 1024;
37
    public static final long MB = 1024 * KB;
38

  
39
    /**
40
     * 25% on to on the idle footprint
41
     */
42
    private static final double FREE_HEAP = 1.25;
43

  
44

  
45
	/*
46
	 * JAVA 7
47
     * based on the PC value of the  jstat -gc output
48
     */
49
	public static final long PERM_GEN_SPACE_PER_INSTANCE = 55 * MB;
50
    public static final long PERM_GEN_SPACE_CDMSERVER = 20 * MB;
51

  
52
    /*
53
     * based on the HU value of the  jstat -gc output
54
     */
55
    public static final long HEAP_PER_INSTANCE = (long)(235 * MB * FREE_HEAP);
56
    public static final long HEAP_CDMSERVER = (long) (15 * MB * FREE_HEAP);
25 57

  
26 58
}
src/main/java/eu/etaxonomy/cdm/server/JvmManager.java
24 24
 */
25 25
public class JvmManager {
26 26

  
27
    /**
28
     *
29
     */
27
    // Java 7
30 28
    private static final String SUFFIX_PERM_GEN = "Perm Gen";
29
    // Java > 8
30
    private static final String SUFFIX_META = "Metaspace";
31 31

  
32 32
    public static final Logger logger = Logger.getLogger(JvmManager.class);
33 33

  
......
35 35
        return getMemoryPoolUsage(SUFFIX_PERM_GEN);
36 36
    }
37 37

  
38
    public static MemoryUsage getMetaSpaceUsage(){
39
        return getMemoryPoolUsage(SUFFIX_META);
40
    }
41

  
38 42
    protected static MemoryUsage getMemoryPoolUsage(String nameSuffix) {
39 43
        List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
40 44

  
......
42 46
            if(memoryPoolMXBean.getName().endsWith(nameSuffix)){
43 47
                logger.debug(memoryPoolMXBean.getName()
44 48
                        + ": init= " + memoryPoolMXBean.getUsage().getInit()
45
                        + ", used= "+memoryPoolMXBean.getUsage().getUsed()
46
                        + ", max= "+memoryPoolMXBean.getUsage().getMax()
49
                        + ", used= "+ memoryPoolMXBean.getUsage().getUsed()
50
                        + ", max= "+ memoryPoolMXBean.getUsage().getMax()
47 51
                        + ", committed= "+memoryPoolMXBean.getUsage().getCommitted());
48 52
                return memoryPoolMXBean.getUsage();
49 53
            }
......
75 79
        return Runtime.getRuntime().availableProcessors();
76 80
    }
77 81

  
82
    public static Integer getJvmVersion() {
83
        return Integer.parseInt(System.getProperty("java.version").split("\\.")[1]);
84
        // alternatively System.getProperty("java.specification.version");
85
    }
86

  
78 87
}
src/main/java/eu/etaxonomy/cdm/server/instance/StartupQueue.java
136 136
            notifyInstanceStartedUp(instance);
137 137
            // release reference to the instance so
138 138
            // that the thread can be garbage collected
139
            instance.getWebAppContext().removeLifeCycleListener(this);
139 140
            instance = null;
140 141
        }
141 142

  
......
147 148
            notifyInstanceFailed(instance);
148 149
            // release reference to the instance so
149 150
            // that the thread can be garbage collected
151
            instance.getWebAppContext().removeLifeCycleListener(this);
150 152
            instance = null;
151 153
        }
152 154

  
src/main/webapp/js/memory-status.js
8 8
          $("#status").html(''); // make empty
9 9
          $("#status").html('<div>CPU Cores: ' + data.availableProcessors + '</div>'); // make empty
10 10
          $("#status").append(memoryUsageEntry(data.heapMemoryUsage, data.recommendedMinimumHeap, "HeapUsage", "100%", "#F48B65", "#65B1F4"));
11
          $("#status").append(memoryUsageEntry(data.permGenSpaceUsage, data.recommendedMinimumPermGenSpace, "PermGenSpaceUsage", "100%","#F48B65", "#65B1F4"));
11
          if(data.permGenSpaceUsage){
12
              $("#status").append(memoryUsageEntry(data.permGenSpaceUsage, data.recommendedMinimumPermGenSpace, "PermGenSpaceUsage", "100%","#F48B65", "#65B1F4"));              
13
          }
12 14
     }); // end JSON
13 15

  
14 16

  
......
21 23
  function memoryUsageEntry(memoryUsage, recommended, label, barWidth, cssColorUsed, cssColorMax){
22 24
    var mb = 1024 * 1024;
23 25
    var gb = mb * 1024;
24
    var max = memoryUsage.max / mb;
26
    
27
    var max = memoryUsage.max ? memoryUsage.max / mb : -1;
25 28
    var used = memoryUsage.used / mb;
26 29
    var percent = used * 100 / max;
27 30
    var recommendedMB = recommended / mb;
28 31
    var html = '';
29 32

  
30 33
    html += '<span class="memory-usage">';
31
    html += label + '(' + used + ' of '  + max+ ' MB, recommended: '  + recommendedMB + ' MB)&nbsp;';
34
    html += label + '(' + used 
35
    if(recommendedMB > 0){
36
        html += ' of '  + max+ ' MB, recommended: '  + recommendedMB 
37
    }
38
    html += ' MB)&nbsp;';
32 39
    html += '<div style="height: 100%; width:' + barWidth + ';background-color:' + cssColorMax + '">';
33 40
    html += '<div style="background-color:' + cssColorUsed + '; width:' + percent + '%">&nbsp;</div></div></span>';
34 41

  
src/main/webapp/manage/MemoryService.jsp
17 17
    //the servelt context must use the class loader of the Bootloader class otherwise
18 18
    //getting the status will not work in mulithreading environments !!!
19 19
    Bootloader bootloader = Bootloader.getBootloader();
20
    long recommendedMinimumHeap = bootloader.getInstanceManager().recommendedMinimumSpace(AssumedMemoryRequirements.HEAP_CDMSERVER, AssumedMemoryRequirements.HEAP_PER_INSTANCE, null);
21
    long recommendedMinimumPermGenSpace = bootloader.getInstanceManager().recommendedMinimumSpace(AssumedMemoryRequirements.PERM_GEN_SPACE_CDMSERVER, AssumedMemoryRequirements.PERM_GEN_SPACE_PER_INSTANCE, null);
22

  
20
    Long recommendedMinimumHeap = bootloader.getInstanceManager().recommendedMinimumSpace(AssumedMemoryRequirements.HEAP_CDMSERVER, AssumedMemoryRequirements.HEAP_PER_INSTANCE, null);
21
    Long recommendedMinimumPermGenSpace = null;
22
    if(JvmManager.getJvmVersion() == 7){
23
        recommendedMinimumPermGenSpace = bootloader.getInstanceManager().recommendedMinimumSpace(AssumedMemoryRequirements.PERM_GEN_SPACE_CDMSERVER, AssumedMemoryRequirements.PERM_GEN_SPACE_PER_INSTANCE, null);
24
    } 
25
    
23 26
    ObjectMapper jsonMapper = new ObjectMapper();
24 27

  
25 28
    response.setHeader("Content-Type", "application/json;charset=UTF-8");
26 29

  
27 30
    MemoryUsage  heapMemoryUsage = JvmManager.getHeapMemoryUsage();
28
    MemoryUsage  permGenSpaceUsage = JvmManager.getPermGenSpaceUsage();
31
    MemoryUsage  permGenSpaceUsage = null;
32
    MemoryUsage  metaSpaceUsage = null;
33
    if(JvmManager.getJvmVersion() == 7){
34
        permGenSpaceUsage = JvmManager.getPermGenSpaceUsage();
35
    } else {
36
        metaSpaceUsage  = JvmManager.getMetaSpaceUsage();
37
    }
29 38

  
30 39
    ObjectNode node = jsonMapper.createObjectNode();
31
    node.put("recommendedMinimumHeap", recommendedMinimumHeap);
32
    node.put("recommendedMinimumPermGenSpace", recommendedMinimumPermGenSpace);
33 40
    node.put("availableProcessors", JvmManager.availableProcessors());
41
    node.put("recommendedMinimumHeap", recommendedMinimumHeap);
34 42
    node.putPOJO("heapMemoryUsage", heapMemoryUsage);
35
    node.putPOJO("permGenSpaceUsage", permGenSpaceUsage);
43
    if(JvmManager.getJvmVersion() == 7){
44
        node.put("recommendedMinimumPermGenSpace", recommendedMinimumPermGenSpace);
45
        node.putPOJO("permGenSpaceUsage", permGenSpaceUsage);
46
    } else {
47
        node.putPOJO("mataSpaceUsage", metaSpaceUsage);
48
    }
36 49

  
37 50
    JsonFactory jsonFactory = new JsonFactory();
38 51
    JsonGenerator jg = jsonFactory.createJsonGenerator(out);

Also available in: Unified diff