Thursday, April 30, 2009

Measure your application's size in memory

We should not generally prefer to construct the application and then workaround the performance issues.
Measuring performance throughout construction can help to identify major performance problems as quickly as possible, which is almost always beneficial.

If a major problem becomes apparent, then some immediate redesign will likely be necessary.
If no major problem is apparent, then, if needed, minor optimizations can be performed later, when construction is nearly complete.
(Many would argue that worrying about minor optimizations during construction is not advisable, since optimizations can sometimes make code more obscure.)

But fixing this minor optimizations can also be very useful to avoid the major issues later.

The excellent JConsole tool comes with JSE 6, and can be used to manage and monitor a local or remote Java Virtual Machine.

If JConsole is not available, there are some other means of measuring an application's size in memory. They depend on your platform. For example:

* NT : Task Manager, look for java.exe or javaw.exe
* Unix : get the process id "ps -e | grep java", pass it to pmap, as in "pmap -x 6598", and look for total KB entry in the Private column

As well, the JDK itself comes with basic profiling tools. For example :

* Runtime.freeMemory()
* Runtime.totalMemory()
* java -Xprof MyClass
* java -Xrunhprof:[options] MyClass

No comments:

SpringBoot: Features: SpringApplication

Below are a few SpringBoot features corresponding to SpringApplication StartUp Logging ·          To add additional logging during startup...