How to measure CPU and memory during load test - java

We are using JMeter in a heterogeneous environment and we would like to measure CPU and memory while we are producing heavy load on a server where our service or web application is running. What would you recommend to use? Is there any software solution (open source or commercial) available which records CPU and memory usage in a file or to a database?
Thank you!

You can use our JMeter perfmon plugin to measure CPU, memory and a lot of other metrics:

From the java perspective, you can use jconsole or write your own code to monitor the memory usage.
Measure CPU and memory consumption of a Java application
javasysmon on github
dstat for linux and perfmon for windows. Read more

You could take a look at Cacti.
It could collect resource usages like CPU, MEM easily with built-in templates and display them in nice graphics. Both Windows and Uni* are supported.

One you install the Perfmon plugin, I also had to install the server agent, and open the firewall port 4444.
Here's a link which I found super useful.
http://grosan.co.uk/web-application-performance-testing-using-apache-jmeter-part-2-monitor-server-resources/

Perhaps you can take a look to collectd if you run in some unix/linux flavour. It will bring you not only CPU but also memory, Disk IO, network and a good number of plugins available.

Related

Java information about process

Suppose I launched new process in JVM using ProcessBuilder.
How can get information about memory used by process and CPU time?
General, problem is this: I have a executable, I need to run it with CPUtime and memory restrictions, I need to set up some callbacks which works on event when CPU or memory restrictions failed. How can I do this in Java?
Thanks in advance
OSHI project could help:
OSHI is a free JNA-based (native) Operating System and Hardware
Information library for Java. It doesn't require the installation of
any additional native libraries and aims to provide a cross-platform
implementation to retrieve system information, such as OS version,
processes, memory & CPU usage, disks & partitions, devices, sensors,
etc.
The feature you're looking for is:
Process uptime, cpu, memory usage

Can JConsole be used to monitor time required to execute particular methods for a web application?

After I connect to weblogic process through JConsole, I see some overall statistics but not the method-wise breakup of performance (time required for each method/class). Besides, as of now, I don't see how particular methods may be profiled using JConsole. Am I looking at the right tool? Or should I go for JProfiler instead?
You are using the wrong tool.
JConsole is a montiring tool. It will help you look at metrics like classes loaded, Heap Space, Perm Space, Threads Live, Collections etc etc...
What you want to do is profiling, not monitoring, try jvisualvm you can find it under JAVA_HOME/bin right next to JConsole.
BE aware that these tools have limited capability, I believe jvisualvm will make it to profile an application up to 65k classes, if you want to go bigger you should try JProfiler, Netbeans Profiler, or Yourkit maybe even Solaris Studio. It all depends on your platform and taste.

Is there a console profiler for Java?

Is there a gprof-like profiler for Java that can be run from the terminal in Linux?
All tools I have found are GUI programs and I need run it from the terminal.
The JVM has a built-in profiler called HPROF. You can enable it on the command line like this:
java -agentlib:hprof=file=hprof.txt,cpu=samples MyClass
This will dump profile information out to a text file when the program finishes. In addition to profiling CPU usage, it can also track heap usage.
The open-source tool jvmtop contains a terminal profiler and might be worth a look:
JvmTop 0.7.0 alpha - 15:16:34, amd64, 8 cpus, Linux 2.6.32-27, load avg 0.41
http://code.google.com/p/jvmtop
Profiling PID 24015: org.apache.catalina.startup.Bootstrap
36.16% ( 57.57s) hudson.model.AbstractBuild.calcChangeSet()
30.36% ( 48.33s) hudson.scm.SubversionChangeLogParser.parse()
7.14% ( 11.37s) org.kohsuke.stapler.jelly.JellyClassTearOff.parseScript()
6.25% ( 9.95s) net.sf.json.JSONObject.write()
3.13% ( 4.98s) ....kohsuke.stapler.jelly.CustomTagLibrary.loadJellyScri()
JXInsight/OpenCore has term/shell reporting plugins (top, queues, stacks,...) that will output its metering and metrics data at regular intervals. It is also possible to access this information using the Open API which allows inspection of the model in real-time within the JVM or offline using a snapshot file handle. Both are supported via Plugin API which it how the top, queues,... ones work.
http://www.jinspired.com/products/opencore (commercial)
Is there a technical reason you can't use a GUI? Is it just a preference driven by a workflow habit? If not then you can always try out our FREE JXInsight/Opus Java Edition - a highly efficient and scalable code level latency performance measurement solution for rapidly identifying hotspots within Java and JRuby applications.
http://www.jinspired.com/products/opus
Note: I am the product architect of both products.
I use jconsole for that. http://docs.oracle.com/javase/6/docs/technotes/tools/share/jconsole.html
If you want it for profiling and monitoring. You can use Jvisualvm.
from App site:
DESCRIPTION
Java VisualVM is an intuitive graphical user interface that provides detailed information about Java technology-based applications (Java applications) while they are running on a given Java Virtual Machine (JVM*). The name Java VisualVM comes from the fact that Java VisualVM provides information about the JVM software visually.
Java VisualVM combines several monitoring, troubleshooting, and profiling utilities into a single tool. For example, most of the functionality offered by the standalone tools jmap, jinfo, jstat and jstack have been integrated into Java VisualVM. Other functionalities, such as some of those offered by the JConsole tool, can be added as optional plug-ins.
EDIT:
As you want a terminal approach.Refer this link Triggering a Javadump.
It describes creation of java dump.

Java Visual VM skewing CPU

i am trying to analyze the CPU usage for a Java UI application running on Windows. I connected it to VisualVM, but it looks like the highest percentage for CPU usage is being used by
sum.rmi.transport.tcp.TCPTransport$ConnectionHandler.run();
I believe this is being used to supply information to VisualVM and hence VisualVM is skewing the results that i'm trying to investigate. Does any one have a way to get a better indication of what is occurring or a better method to determine what in a running java application is taking up so much CPU.
Try to use sampler first.
For detailed information use the profiler and set root methods. See Profiling With VisualVM, Part 1 and Profiling With VisualVM, Part 2 for more information about CPU and Memory profiling.
That sounds awfully suspicious. Try cross referencing the data with results from hprof. You won't need any external applications running, and the data will simply be dumped to a text file from your own process. Are you connecting to your process remotely?

JVM calltree snapshot for VisualVM

I am trying to use VisualVM to profile a Java (Sun JDK 1.6) standalone application. I have a scripted performance test environment, where I can run my application and get it to report some metrics I care about.
Is there some way to get JVM to collect some CPU profiling snapshot which I can later analyze with VisualVM?
I am looking for something similar to -XX:+HeapDumpOnOutOfMemoryError flag which writes a heap dump to disk just before an OutOfMemoryError is thrown.
There is the hprof tool built into the JVM (http://java.sun.com/developer/technicalArticles/Programming/HPROF.html) which allows you to capture basic profiling information, its dog slow and produces massive files.
VisualVM AFAIK does not yet have these abilities, but yourkit has the ability to do what you want though its agent, and programmatically.
Yourkit via agent line (-agentlib:yjpagent=onexit=snapshot)
http://www.yourkit.com/docs/80/help/additional_agent_options.jsp
Programmatically
http://www.yourkit.com/docs/80/api/index.html
As an aside I would suggest that you are careful with measuring CPU along with performance testing as it will definatly skew your results, have you considered looking at something like https://japex.dev.java.net/ around your core code ?

Categories