I have a java app. Its use is to automate login to websites and create wifi hotspots. It is a GUI app with many features such as a notification manager and system tray. My JAR file has a size of 3 MB but, it consumes about 100 MB of RAM. Should I be worried?
I checked if any of my methods were recursive and I could not find any.
My java app's code can be found here : https://github.com/mavrk/bitm-cyberoam-client/tree/master/JavaApplication13
A one line program can use 8 GB of memory.
If you are concerned about the size of the heap you can either
reduce it further, though this might slow the application or prevent it from working.
use a memory profiler to see where the memory is being utilised.
not worry about about 50 cents worth of memory. If you are minimum wage you shouldn't spend more then 6 minutes on it or your time will be worth more than the memory you save.
Related
I can see in jconsole, that my simple java hello world app takes 1 MB or 2 Mb, however in task manager it shows 12 MB. I need to understand it in order to analyze a problem in our java-native layer application which shows only 40 MB memory in jconsole, which we find normal and even on native layer there are not any memory intensive operations. In production environment, task manager shows 373 MB, which is much beyond our expectations.
Note: we don't have out of memory error yet, we rather have a watchdog service, which complains when memory goes beyond 250 MB and start logging it in a log file.
This article might help you. The reason is that windows does not show only heap memory instead its overall memory of windows process. The jvm tools like jvisualvm or jconsole show the exact heap space used by a java process
I have a program and a strong suspicion that memory swapping is occuring. The reason I belive that is the case is the fact that program just hangs from time to time. When I started logging, things became even more confusing as the program started hanging on different places, with different methods being executed.
At this time I'm using 32-bit IBM Java with 2gb dedicated to the program, so I'm right on the edge with the memory. Change to x64 is possible but before that:
Question 1: Can I programatically detect memory swapping at runtime? Or how could I at least give myslef some hints (via logging) that swapping is occuring.
And as of now, I dont have memory usage logs availible to me, however, if xmx is 2Gigs, that's just RAM and if memory swap occurs, would it even appear that i dont have enough memory?
Question 2: As I think about it now, can I log the start of garbage collenction? Can I detect it at runtime?
EDIT: said program exports very large amounts of data from database.
EDIT2: can I programatically forbid memory swapping for givem JVM?
Can I programatically detect memory swapping at runtime?
You can monitor in the OS how much swap is being used or how much is being written to the swap partitions. How you do this depends on yoru OS>
if memory swap occurs, would it even appear that i dont have enough memory?
If you had enough memory no swapping would occur. Note: even if no swapping occurs it that more memory wouldn't help. Most likely you need more than just your application memory e.g. disk caching also is important.
can I log the start of garbage collenction?
You can in another process, however you can't run anything while a stop-the-world action is occurring.
Change to x64 is possible but before that:
Java 5.0 was the last version where I would have said may be 32-bit is best. That was ten years ago.
program exports very large amounts of data from database.
1 GB is less than the cost of a cup of coffee these days. Even tens of GB is not much to worry about. Hundreds of GBs is getting big, and if you have a few TB you have an interesting problem. Some of my clients have 3 TB machines and they have very large amounts of data e.g. 100s TB.
I gave an old computer which hadn't been used for years to my oldest daughter and she gave it to my 8 year old daughter. It has 24 GB of memory and she uses it to mainly watch youtube videos.
can I programatically forbid memory swapping for givem JVM?
You can lock it into memory using JNI but when a machine swaps your heap space your machine is on the edge of dying anyway.
I face a problem with java application I built in javaFx. It consumes only 2-3% of cpu usage and around 50 to 80 MB of memory in windows. But in mac same application initially starts with 50 mb of memory and continuously increases to 1 GB and uses over 90% of CPU Usage. I found this information when I checked Mac task manager. When I use a java profiler to find memory leaks, the profiler shows memory usage same like window (not more than 100 MB).
I am confused with this behaviour in Mac.
Has anyone encountered this problem before, or am I doing something wrong with my application?
Lots of things possible, but i suspect this: Depending on the memory size and cpu count, the jvm may run in server mode, which causes memory management to be different. Use -server option to force it to be server mode always and compare again.
Can also take heap dumps (jmap -dump) to see what is taking up so much memory, and stack traces (kill -3) to see what is taking up so much cpu.
I am trying to understand why android GC behaves the way it does,
VM Heap is set to 512 MB
Runtime.getRuntime maxMemory is 512 MB
Runtime.getRuntime totalMemory is 13 MB
Runtime.getRuntime freeMemory is 3 MB
I am always within +/- 2-3 MB of these values.
My code is functional so I am using a lot objects but I am no where near 512 MB yet I am constantly seeing GC calls in my logcat especially in tight loops. Why doesn't it just let the heap grow? and GC in small increments instead of pausing my app every time for 300 ms.
Is there any way for me to have a little more control over the garbage collection process (this won't be a market app I have no problem with installing a custom rom.) other than stock answer being change your coding style do not create a lot of objects, since I see a similar behavour on a real device (a quad 1,2 ghz machine with 2 gb of ram when no other app is running it is kind of annoying to have a machine this powerfull and not be able to code the way I like.)
The main problem is that an app runs in a VM and each VM has its limit. As long as you are not going native (NDK) you will have to live with the little RAM your VM gets.
I have no problem with installing a custom rom.
If you want to build your own ROM (or search for one with configurable settings), increase the size per VM and be happy with it.
My code is functional so I am using a lot objects
Well there is a difference between "using a lot of objects" and "using a lot of objects with damn short life time". But as you don't wanna hear about it...
I'm trying to develop a small testing application that runs a few commands on and every X seconds measures cpu usage,memory usage and network utilization as seen in Windows Task Manager.
the Application will be written in java and is supposed to run on both windows and linux.
I have found that many people uses the Sigar API in order to extract system information easily.
I found out how to use it to extract memory usage using
Mem mem = sigar.getMem();
mem.getUsed();
I'm still not sure what the difference is between memory used and actual memory used, can someone elaborate me on this?
Also I'm still not sure how to extract Cpu usage and network utilization.
for Cpu I have tried:
cpu = sigar.getCpuPerc();
cpu.getCombined();
but the numbers seems very different from what I'm seeing in the Task Manager.
which API should I use to get the desired results?
for network utilization I have no clue.
Memory used refer to the allocated memory size, actual memory used is the one which is actually used out of the allocated, it reduces some kernel and other areas memory from it.
For CPU, I also figured out values to be different and seen some blog where it suggest to multiply by 100. So I did, now the values are quite similar...
http://code.google.com/p/starfire/source/browse/trunk/starfire/src/main/java/es/upm/dit/gsi/starfire/capability/systemMonitor/CpuMonitor.java?spec=svn279&r=279
Network I am still searching.