You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Campbell, Lance" <la...@illinois.edu> on 2019/03/04 15:49:43 UTC

How to display the current In-Use Stack Size

Tomcat 9.x
What is the easiest way to identify how much memory Tomcat/Java is currently using from the Java stack -Xss ?  Not max but currently being used.

Is there a particular statement I can put into a servlet to see what the current memory usage is of the stack?

Thanks,

Lance

Re: How to display the current In-Use Stack Size

Posted by John Dale <jc...@gmail.com>.
Something like this maybe?

String[] cmd = {
"/bin/sh",
"-c",
"ps -eo rss,comm --sort rss"
};

            Process p = Runtime.getRuntime().exec(cmd);

  p.waitFor();
  BufferedReader buf = new BufferedReader(new InputStreamReader(
          p.getInputStream()));
  String line = "";
  String output = "";

  while ((line = buf.readLine()) != null)
  {
    if(line.indexOf("java") > 0)
    {
        output += line + "\n";
    }
  }

  out.println(output);
System.out.println(output);

On 3/4/19, Campbell, Lance <la...@illinois.edu> wrote:
> I have seen those as well.  I was hoping someone knew if there was a way to
> view the Java Stack in particular.
>
> On 3/4/19, 11:16 AM, "John Dale" <jc...@gmail.com> wrote:
>
>     I found this in some old code .. not sure if it works.  Let me know.
>
>     //Getting the runtime reference from system
>                 Runtime runtime = Runtime.getRuntime();
>
>                 //Print used memory
>                 out.println("Used Memory: "
>                     + ((runtime.totalMemory() - runtime.freeMemory()) / mb)
> + "MB");
>                 out.println("<br/>");
>
>                 //Print free memory
>                 out.println("Free Memory: "
>                     + (runtime.freeMemory() / mb) + "MB");
>                 out.println("<br/>");
>
>                 //Print total available memory
>                 out.println("Total Memory: " + (runtime.totalMemory() / mb)
> + "MB");
>                 out.println("<br/>");
>
>                 //Print Maximum available memory
>                 out.println("Max Memory: " + (runtime.maxMemory() / mb) +
> "MB");
>                 out.println("<br/>");
>
>     On 3/4/19, Campbell, Lance <la...@illinois.edu> wrote:
>     > Tomcat 9.x
>     > What is the easiest way to identify how much memory Tomcat/Java is
> currently
>     > using from the Java stack -Xss ?  Not max but currently being used.
>     >
>     > Is there a particular statement I can put into a servlet to see what
> the
>     > current memory usage is of the stack?
>     >
>     > Thanks,
>     >
>     > Lance
>     >
>
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>     For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to display the current In-Use Stack Size

Posted by "Campbell, Lance" <la...@illinois.edu>.
I have seen those as well.  I was hoping someone knew if there was a way to view the Java Stack in particular.    

On 3/4/19, 11:16 AM, "John Dale" <jc...@gmail.com> wrote:

    I found this in some old code .. not sure if it works.  Let me know.
    
    //Getting the runtime reference from system
                Runtime runtime = Runtime.getRuntime();
    
                //Print used memory
                out.println("Used Memory: "
                    + ((runtime.totalMemory() - runtime.freeMemory()) / mb) + "MB");
                out.println("<br/>");
    
                //Print free memory
                out.println("Free Memory: "
                    + (runtime.freeMemory() / mb) + "MB");
                out.println("<br/>");
    
                //Print total available memory
                out.println("Total Memory: " + (runtime.totalMemory() / mb) + "MB");
                out.println("<br/>");
    
                //Print Maximum available memory
                out.println("Max Memory: " + (runtime.maxMemory() / mb) + "MB");
                out.println("<br/>");
    
    On 3/4/19, Campbell, Lance <la...@illinois.edu> wrote:
    > Tomcat 9.x
    > What is the easiest way to identify how much memory Tomcat/Java is currently
    > using from the Java stack -Xss ?  Not max but currently being used.
    >
    > Is there a particular statement I can put into a servlet to see what the
    > current memory usage is of the stack?
    >
    > Thanks,
    >
    > Lance
    >
    
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
    For additional commands, e-mail: users-help@tomcat.apache.org
    
    


Re: How to display the current In-Use Stack Size

Posted by John Dale <jc...@gmail.com>.
I found this in some old code .. not sure if it works.  Let me know.

//Getting the runtime reference from system
            Runtime runtime = Runtime.getRuntime();

            //Print used memory
            out.println("Used Memory: "
                + ((runtime.totalMemory() - runtime.freeMemory()) / mb) + "MB");
            out.println("<br/>");

            //Print free memory
            out.println("Free Memory: "
                + (runtime.freeMemory() / mb) + "MB");
            out.println("<br/>");

            //Print total available memory
            out.println("Total Memory: " + (runtime.totalMemory() / mb) + "MB");
            out.println("<br/>");

            //Print Maximum available memory
            out.println("Max Memory: " + (runtime.maxMemory() / mb) + "MB");
            out.println("<br/>");

On 3/4/19, Campbell, Lance <la...@illinois.edu> wrote:
> Tomcat 9.x
> What is the easiest way to identify how much memory Tomcat/Java is currently
> using from the Java stack -Xss ?  Not max but currently being used.
>
> Is there a particular statement I can put into a servlet to see what the
> current memory usage is of the stack?
>
> Thanks,
>
> Lance
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to display the current In-Use Stack Size

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Lance,

On 3/4/19 10:49, Campbell, Lance wrote:
> Tomcat 9.x

Note that the answer to this is not Tomcat-specific.

> What is the easiest way to identify how much memory Tomcat/Java is 
> currently using from the Java stack -Xss ?  Not max but currently 
> being used.

Uh... there is no "maximum stack size". There is only "stack size".
Each thread gets a stack of exactly that size.

> Is there a particular statement I can put into a servlet to see
> what the current memory usage is of the stack?

RuntimeMXBean rbean = ManagementFactory.getRuntimeMXBean();

List args = rbean.getInputArguments();

Then look through them for "-Xss" and the accompanying size.

The "used stack size" is the number of live threads times that number.

I don't know if there is a way to check that it was effective, though.

For example, there may be multiple -Xss arguments and the JVM picks one
of them to use (probably the last one, but I don't know for sure).

Also, there may be some minimum / maximum size that will be chosen if
the number is not sane. Or there may be magic numbers like 0 or -1 that
mean "the default for the platform" or whatever.

YMMV.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlx+0DwACgkQHPApP6U8
pFhaRQ//e3GW8AlMVxve9LTljwvtHcZcaCsjA4UWyDyi14rLEu4aHClf5mRluxwE
F0cvsEThxFIv2mpvY0aijs9Vcu+Uf8qMEncks3LTEPxq5GUoRdTHvO4dIqQh2tLd
LVRKBMj7TqeSeQqGjmkgxFHf+F2iuOj34q3LGWzhVbHTn94JOka65nZx75auTySS
jv/+pQGTPjJ8WgGCI3NQIlkg4t7+46i2lWI/D3FhFi0h7uqmV31wly4p7Pz1KxZa
6veaGcutwU7V5brl2vF00AXZsQPSlTQYNLEAfvL87S1WrXWeRTel4Xu/PIPKGq3H
bDbGeC7fh0KR1Gu7sBNlc9ZPxZs57B250ouvkEJ6wj3VG9RA6/MpdCsES9Mv8Z3m
jiwizYnpE2aVKTlH5ID3NPlxH4mCKVl4xxV2JKPeSqBRhnQJkRWE06Mg9XaW6LMv
f1GO9TJ5DSL+Qyb+9i29qy47c9oPrOL4I/9ABOkPfDQzc7iUHdfvpZbKg0BCzgSN
s9vQbzhl32tsJCskjg8OqY7NfzmO8rbcDj90/q60ekCYIz1QzFtJpp6WDMYtbcmW
I9W8dErov/iZSrRpw8selIvjYjJ//2cJ4vm6m9NBg3euT4NasiywidByaF5kOEZE
l5vBcSbDM6/am6b/ukSvRBX33LT5brPv4JQa33haGsKHgNoqc34=
=ZIok
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org