JVM - How much RAM should I allocate

自作多情 提交于 2021-01-28 18:35:58

问题


I didn't find a suggestion on how much RAM I actually should allocate to the JVM.

Assuming that my computer has 4GB RAM and runs Windows 10. I nearly only use Java Applications on it. With how much RAM should I start the JVM? The system needs RAM for itself too, so in my logic, I should not allocate 4 GB even if that is possible.

This isn't a black/white question, I just want to have an idea and how to come to an answer in this question.


回答1:


I didn't find a suggestion on how much RAM I actually should allocate to the JVM.

The JVM has a default setting of 1/4 of main memory. If you have 4 GB it will default to 1 GB.

Note: this is a pretty small system and you get get some embedded devices and phones which this much memory.

If you can afford to buy a little more memory it will make your life easier.

I nearly only use Java Applications on it. With how much RAM should I start the JVM?

Unless you have a reason to change a command line parameter I would leave it as it is.

Note: you OS will need some memory, perhaps 1 GB and you want to leave 1 GB free for caching etc, so you could increase the heap size to 2 GB, but only if you needed to.

What if I run 4 programs in parallel? Can I still allocate 2GB for every of that program?

Yes, but it's a very bad idea. You application will start swapping and your computer can become unusable. I would try to stay under 2 GB total for this machine.

We have a business application here that often reaches to the maximum allocated Ram, which makes it lag a lot if a user has too many "tabs" open.

In that case, you should make sure you have the right tool for the job which means making sure your system has enough memory. 4 GB of memory costs $18. If you had a hobby PC with 4 GB, I would say, get more memory. Three years ago, my 8 year old son when he turned 8 I gave him a PC with 8 GB of memory because it's didn't make sense to buy less. I would just get 16 GB or 32 GB minimum. Then its worth spending some time tuning it, maybe.




回答2:


you can type "jconsole" or "jmc" in command line to see how much memory java used.



来源:https://stackoverflow.com/questions/37783246/jvm-how-much-ram-should-i-allocate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!