title: Increasing heap memory utilization on Java Tomcat application
body: <p>I have a Java application running on a Tomcat7 instance. I am using Java 8.</p>
  
  <p>Now within my application there is a webservice of the format :  <a href="http://zzz.xxx.zzz.xxx/someWebservice?somepar1=rrr&amp;somePar2=yyy" rel="nofollow noreferrer">http://zzz.xxx.zzz.xxx/someWebservice?somepar1=rrr&amp;somePar2=yyy</a>. This returns a <code>String</code> value of max 10 characters. </p>
  
  <p>I have now started load testing this service using Jmeter. I am putting a load of 100 concurrent connections and getting a throughput of roughly <code>150 requests/second</code>. The server is a 4 core-6GB machine and is only running Tomcat (application instance). The database instance is running on a separate machine. JVM is running with min 2GB and Max 4 GB memory allocation. Max Perm Size is 512 MB. Tomcat has enough threads to cater to my load (Max connections/threads/executor values have been setup correctly)</p>
  
  <p>I am now trying to optimize this service and in order to do so I am trying to analyze memory consumption. I am using <code>JConsole</code> for the same. My CPU usage is not a concern , but when I look at the memory (HEAP) usage, I feel something is not right. What I observe is a sawtooth shaped graph, which I know is correct as regular GC clears heap memory. </p>
  
  <p>My concern is that this sawtooth shaped graph has an <strong>upward trend</strong>. I mean that the troughs in the sawtooth seem to be increasing over time. With this trend eventually my server reaches max heap memory in an hour or so and then stabilizes at 4GB. I believed that if I am putting a CONSTANT load, then the heap memory utilization should have a constant trend, i.e. a saw tooth graph with its peaks and troughs aligned. If there is an upward trend I am suspecting that there is a memory leak of variables which are collecting over time and since GC isn't able to clear them there is an increase over a period of time.  I am attaching a screenshot.  </p>
  
  <p><a href="http://i63.tinypic.com/30bmpl2.png" rel="nofollow noreferrer">Heap Usage</a></p>
  
  <p>Questions:</p>
  
  <p>1). Is this normal behavior? If yes, then why does the heap continuously increase despite no change in load? I don't believe that a load of 100 threads should saturate 4GB heap in roughly 30 minutes.</p>
  
  <p>2). What could be the potential reasons here? Do I need to look at memory leaks? Any JVM analyzer apart from JConsole which can help me pinpoint the variables which the GC is unable to clear?</p>