title: Springboot App consumes too much memory on docker
body: <p>Trying to deploy a <strong>containerized springboot app</strong> using <strong>docker</strong>.
  here's my <strong>Dockerfile</strong>:</p>
  
  <pre><code>ROM openjdk:8
  ADD app-1.0.jar app.jar
  EXPOSE 8080
  ENTRYPOINT ["java", "-Xmx64m", "-Xss256k", "-jar", "ecalio-landing.jar"]
  </code></pre>
  
  <p>And <strong>runned</strong> a <strong>container</strong> like this:</p>
  
  <pre><code>sudo docker run -d -m256m --restart=always server.tomcat.max-threads=5 --name=ecalio-landing
  </code></pre>
  
  <p>Once <strong>deployed</strong>, i used <strong>apache benchmark</strong> to <strong>test</strong> the <strong>backend</strong> and how much <strong>requests</strong> it can <strong>reach</strong> using this command:</p>
  
  <pre><code>ab -n 20000 -c 10 http://www.ecalio.com/
  </code></pre>
  
  <p>Basically, trying to know if the backend can reach 20000 requests 10 at a time, because i've <strong>limited</strong> the <strong>container memory consumption</strong> to <strong>256mb</strong>. </p>
  
  <p>The <strong>container starts</strong> with <strong>220mb</strong> and <strong>reaches</strong> a <strong>level arround 245mb</strong> and <strong>doesn't go further</strong> <strong>even if i rerun the same</strong> <strong>ab command</strong></p>
  
  <p><strong>However</strong>, when i try to <strong>reach the backend using a browser</strong>, <strong>0.1mb is consumed each time i refresh the browser</strong> and obviously the <strong>container crushes once it reaches 256mb</strong> of <strong>memory consumption.</strong></p>
  
  <p><strong>How come does such a thing happends</strong> <strong>?</strong></p>
  
  <p><strong>I don't want my container to consume much memory</strong>, it's basically a simple app which makes use of <strong>jpa</strong> with <strong>1 entity</strong> <strong>model</strong> only, and <strong>perform only 1 retrieve</strong> request called each time <strong>/ url</strong> is called using a simple <strong>controller</strong> (<strong>@Controller</strong>) and <strong>returns</strong> a <strong>single html page</strong> rendered with <strong>thymeleaf</strong></p>
  
  <p>I've used Java VisualVM With my app (launched locally on my machine without a docker container) and i can see clearly that my app doesn't have any leak of memory, the heap memory doesn't go further more than 68mb and used heap is always being cleared by the GC ... </p>
  
  <p><a href="https://i.stack.imgur.com/mIvPu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mIvPu.png" alt="Profiling memory"></a></p>