Class MemoryUsageServlet

  • All Implemented Interfaces:
    jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable

    @WebServlet(name="MemoryUsageServlet",
                urlPatterns="/memoryusage")
    public class MemoryUsageServlet
    extends jakarta.servlet.http.HttpServlet
    MemoryUsageStress
    Author:
    Michal Babacek

    This simple servlet is used for stressing memory.

    The objective is to force JVM to allocate a given amount of memory (in megabytes). After the memory is filled up, we wait for a specified number of milliseconds before dereferencing.

    E.g.:

    http://localhost:8080/clusterbench/memoryusage?milliseconds=20000&megabytes=500

    will allocate 500MB and keep them for 20000ms.

    Warning: Obviously, if you set megabytes=1000 while having -Xmx512m you will experience an unpleasant and utterly inevitable OOM.

    Note: Naturally, if -Xms < -Xmx, JVM will be allocating more system physical memory. You can observe system physical memory values in the message you shall get from this servlet.

    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class jakarta.servlet.http.HttpServlet

        LEGACY_DO_HEAD
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void doGet​(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)  
      String getServletInfo()  
      • Methods inherited from class jakarta.servlet.http.HttpServlet

        doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, init, service, service
      • Methods inherited from class jakarta.servlet.GenericServlet

        destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
    • Constructor Detail

      • MemoryUsageServlet

        public MemoryUsageServlet()
    • Method Detail

      • doGet

        protected void doGet​(jakarta.servlet.http.HttpServletRequest request,
                             jakarta.servlet.http.HttpServletResponse response)
                      throws jakarta.servlet.ServletException,
                             IOException
        Overrides:
        doGet in class jakarta.servlet.http.HttpServlet
        Throws:
        jakarta.servlet.ServletException
        IOException
      • getServletInfo

        public String getServletInfo()
        Specified by:
        getServletInfo in interface jakarta.servlet.Servlet
        Overrides:
        getServletInfo in class jakarta.servlet.GenericServlet