Predicting memory consumption of java components [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am currently working on an event driven System with multiple components running. Recently , I have received an urgent requirement to identify the memory consumption of java components running , so that we can give a brief idea of memory requirements before it is getting deployed on UAT/customer production environments.
Do we have any API using which Deep retained size can be calculated or a formula can be provided using which memory requirements can be computed.
Any ideas on this will surely help.
I have seen some API's ( java instrumentation Api) using which Shallow size can be calculated , but this will not suffice my need.
I also found java Assist using which java byte code can be modified at runtime.

To identify the memory consumption of a java aplication, you can use a profiler.
In jdk 6 or greater you can find jvisualvm (https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jvisualvm.html).
With jvisualvm, you can attach to a java process and, in sampler tab, you can see the memory consumed grouped by class type.
There are even other powerful profilers (JProfiler is one of them)

Enable garbage collection logging and analyze the log. As a bonus you will also be able to identify (and fix) aberrant behaviour.
To turn on gc logging, use the following flags:
-verbose:gc
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:+PrintTenuringDistribution
-XX:+PrintGCCause
-Xloggc:/gc-%t.log
This log file can then be handled in a number of tools like Censum from JClarity or uploaded to https://gceasy.io/ for easy analysis. Note that you will see the memory consumption as a whole for the app, not a breakdown. For that you will have to use something like VisualVM mentioned above.

Related

100% CPU Utlization by Java Application [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to analyze the java application using VisualVM tool and am getting the following statistics.
.
What I don't understand is why my app is utilizing approx 100% of CPU, and what are the ways I can detect and resolve memory-related issues in java application.
The project is developed on Spring Boot and is deployed on Apache Tomcat Server.
Thanks.
Edit:
My project used to utilize a max of 30% of CPU but now it's utilizing 100% and because of it most of the APIs are taking a lot of time to respond.
You could use a Profiling tool like JProfiler or VisualVM to analyze what your application is doing at that time. You could also connect a debugger and just "pause" the threads, that's a hack that may give you some hint on where to look for what is actually happening.
From your screenshot I'm not really seeing any memory specific issues, but using a profiling tool will also allow you to analyze which classes have instances with allocated memory.

Tomcat having extremely high cpu usage [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have tomcat 8 and running a web application on tomcat. Recently I noticed my Vsphere client showing alarms for high cpu usage and found that the process responsible for is tomcat. When I restart the tomcat server it is running good, but after some time, the same problem arise. How to solve this issue?
/data/IMS/java/bin/java -Djava.util.logging.config.file=/data/IMS/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048
This is a broad topic, so I can only really provide you with some pointers on how to debug remote applications.
If you want to get some visibility into what your App is doing you can use a tool like Visual VM. Visual VM can profile cpu and memory usage, see details here. In order to do profiling you need to:
Enable JMX on Tomcat. Docs on how to do this for Tomcat 8 are here.
Run Visual VM and point it at your Tomcat server's JMX connection. Tutorial here.
Do some cpu usage profiling and look at memory usage to get a better idea about what is happening. Formulate some hypotheses and test them out. Repeat the process until you stumble upon a solution.
If I had to guess what was going wrong, I would say memory usage is gradually increasing over time, and garbage collection starts taking a long time.

Troubleshooting performance issues in java / Scala play framework apps [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
We have apps that are deployed in production [Java / Scala]. We have alerts setup when ever there is a spike in CPU usage or memory usage.
Occasionally we see a huge spike in CPU or memory usage. Some times the application that is running on play stops responding to request.
I usually see the logs for last few API hits before the crash, that way I recently figured out one of API was downloading huge dump of data and memory got exhausted.
Can I get tips for troubleshooting the issues in general [commands / tools to capture stats] when things go wrong in prod?
This requires a lot of experience though. Below are some steps that you could follow:
Prerequisite:
You should understand java Memory Model i.e. what's New Generation(Eden, Survivor-01,Survivor-02), Old Generation, Meta Space, Heap, Stack etc.
Read this to understand it better.
You should understand how Garbage collection works. e.g. you should understand how Mark and Sweep algorithm works. Check the same link as above for same.
Now you could install visual VM. Also, in visual vm install a plugin visual gc it will show you memory used in different space. You will see another tab Visual GC
i) Observe Graphs(Heap one to top right in the snapshot below) in Monitor Tab.
**Trick: ** You could perform manual GC as well to observe how steep the graph line for Used Heap Space is and how quickly it fills up at running some block of code. I used it many times and it really helps (Especially if used with the debugger)!
ii) Also, try to observe the Thread Dump if multithreading is causing some issue.
iii) In any case, you could also do some profiling or sampling via profiler and sampler tab.
Below is a snapshot of sampler. See how clearly it tells how much memory is taken by what data type:
Important: Screenshot is of the heap. You could change to Per Thread Allocation tab to see per thread allocation.
Similarly, you could observe CPU consumption.
Alternatively, use JMeter if you think locally you are not able to reproduce the same. Jmeter can help you extensively load test your application basically.
Also, if you have integrated any server monitoring tool that could also be helpful. You could easily get notified for a problematic code.
At last, you could download the heap dump from the production system and analyze that on local using visual vm.
jmap -J-d64 -dump:format=b,file=<heap_dump_filename> <pid>
this link have more detailed answers from some really cool developers on same.
Use jstat. It comes with java and is very handy sometimes.
jstat -gc 2341 //2341 is the java process id.
These are from my experience. But In this direction, there would never be enough and I believe my knowledge keeps on evolving as I face more such issues. Hence, please practice it and explore further.
Having said that, there are other tools available so also feel free to find other ones that suit your needs well. To get started take a look at Jconsole.

Capture and Analyze Core Dump on Running App Server [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
How can I capture a Core Dump and analyze the Java heap on an application running in Apache Tomcat?
A javacore can be provoked manually (assuming the JVM is configured to dump at user signal - generally it is).
On Windows: Press ControlBreak on the command window to generate the dumps.
On Linux: Press Control\ on the shell window.
On *nix or using Cygwin: kill -quit <pid>
All in all, launch Tomcat from a console, then depending on your platform perform one of the options above. This will generate a javacore which can be analyze with various tools e.g. Visual VM, etc.
VisualVM provide wide range of memory test on any application running with Java. I don't have much idea about tomcat memory analyzer but I'd prefer VisualVM
Download: https://visualvm.java.net/
VisualVM is a visual tool integrating several commandline JDK tools and lightweight profiling capabilities. Designed for both production and development time use, it further enhances the capability of monitoring and performance analysis for the Java SE platform
Screenshot of heap dump.

Is there any ways in C,C++ to control the memory ram,registers according to our need? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Are there any ways in C and C++ to control the memory ram and registers according to our need? Eg. movement of data in ram from one location to other, changing values in registers, etc?
Is it possible in Java???
For memory management you should consider using a Memory Pool. Link.
Though you shouldn't be reinventing the wheel. Use a library instead that provides a clean templated interface to memory pools. Avoid malloc and memcpy as much as possible.
If you wan't to play with the registers you can include assembly code. Link.
I am not sure to understand your question, which is operating system, processor, and compiler specific.
With recent GCC you could do some of it (for instance, reserve registers to avoid them being used). And you could also customize the compiler (e.g. with MELT) to suite more needs. But such a customization means at least weeks of efforts.
You could also make a new backend in GCC (but this means months of work)
And recent standard C++11 library has notably std::allocator and a lot of memory management related stuff.

Categories

Resources