Author: pferraro
Date: 2009-05-19 11:37:11 -0400 (Tue, 19 May 2009)
New Revision: 2441
Modified:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java
Log:
Change default reserve ratio to 90%, allow ability to configure
Modified:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java 2009-05-18
22:02:04 UTC (rev 2440)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java 2009-05-19
15:37:11 UTC (rev 2441)
@@ -42,6 +42,9 @@
private static final long serialVersionUID = -8183119455180366670L;
private static Logger log = Logger.getLogger(HeapMemoryLoadServlet.class);
+ private static final String RATIO = "ratio";
+ private static final String DEFAULT_RATIO = "0.9";
+
private static final int MB = 1024 * 1024;
/**
@@ -52,7 +55,8 @@
protected void service(HttpServletRequest request, HttpServletResponse response)
throws IOException
{
int duration = Integer.parseInt(this.getParameter(request, DURATION,
DEFAULT_DURATION)) * 1000;
-
+ float ratio = Float.parseFloat(this.getParameter(request, RATIO, DEFAULT_RATIO));
+
System.gc();
MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
@@ -61,12 +65,11 @@
long total = (max >= 0) ? max : usage.getCommitted();
long free = total - usage.getUsed();
- // Reserve half the available free memory
- long reserve = free / 2;
+ long reserve = (long) (free * ratio);
log.info((total / MB) + "MB total memory");
log.info((free / MB) + "MB free memory");
- log.info("Reserving " + (reserve / MB) + "MB of memory");
+ log.info("Reserving " + (reserve / MB) + "MB (" + ((int) (ratio
* 100)) + "%) of memory");
List<Object> list = new ArrayList<Object>(2);
Show replies by date