简体   繁体   English

我真的需要定义java最小堆大小

[英]Do I really need to define java minimum heap size

I'm about to deploy an application to a live server and right now I am at the part where I have to set heap and permgen sizes for the jvm. 我即将将应用程序部署到实时服务器,现在我正处于为jvm设置堆和permgen大小的部分。 I have seen a lot of articles and all of them say to "set the minimum heap size to (some number)", and to "set the maximum heap size to (some number)", but none of these articles really says why the minimum heap size needs to be set. 我看过很多文章,所有人都说“将最小堆大小设置为(某个数字)”,并“将最大堆大小设置为(某个数字)”,但这些文章都没有说明为什么需要设置最小堆大小。 I understand the reason to set the maximum heap size, but not about the minimum. 我理解设置最大堆大小的原因,但不是最小堆大小。 I would be thankful if you shed some light on this. 如果你对此有所了解,我将感激不尽。

The heap in Java is the general memory allocation area. Java中的堆是一般的内存分配区域。 Let us suppose that we set the minimum heap size to 1000 bytes (this is an absurdly low number). 我们假设我们将最小堆大小设置为1000字节(这是一个荒谬的低数字)。 Now lets say that I instantiate an object in my program that contains some text that is two thousand characters long. 现在让我说我在我的程序中实例化一个包含一些长度为两千个字符的文本的对象。 I cannot save this object without first expanding my heap size. 如果不先扩展堆大小,我无法保存此对象。 Now, presumably my maximum heap parameter is large enough to allow this - but that is the reason to set the maximum heap size. 现在,可能我的最大堆参数足够大以允许这个 - 但这是设置最大堆大小的原因。

However, suppose my server has 4G of ram, and I set the minimum heap size to that. 但是,假设我的服务器有4G ram,我将最小堆大小设置为。 (An absurdly large number.) If no other programs took up any memory, this would work. (一个荒谬的大数字。)如果没有其他程序占用任何内存,这将工作。 However, if I started a second process with my java program, it would not be able to allocate sufficient memory and quit. 但是,如果我使用我的java程序启动第二个进程,它将无法分配足够的内存并退出。

The minimum size does two things for you; 最小尺寸为您做两件事; first, it makes memory available quickly to allow rapid startup. 首先,它使内存快速可用,以便快速启动。 Secondly, it lets you tune your jvm so that you have some invariants, allowing you to make predictions about how many processes you can run. 其次,它可以让你调整你的jvm,以便你有一些不变量,允许你预测你可以运行多少个进程。 If your minimum heap size is too large, you're probably wasting memory on a process that never needs that much, limiting the capacity of your system. 如果您的最小堆大小太大,那么您可能会在一个从不需要那么多的进程上浪费内存,从而限制了系统的容量。 If you set it too small, programs will take a long time to start up, adversely affecting the process's performance. 如果将其设置得太小,程序将需要很长时间才能启动,从而对流程的性能产生负面影响。

设置最小堆大小允许Java预先分配一些内存,这可以缩短启动时间。

Setting the minimum size explicitly ( above the default ) helps with allocation fragmentation at the OS level and start up time performance. 显式设置最小大小(高于默认值)有助于在操作系统级别进行分配碎片并启动时间性能。

The Java Heap is backed by memory allocated by the OS, the bigger the initial block the less re-allocation and fragmentation that will occur. Java堆由OS分配的内存支持,初始块越大,将发生的重新分配和碎片越少。

Setting the minimum equal to or almost equal to the maximum, will eliminate these situations completely. 将最小值设置为等于或几乎等于最大值,将完全消除这些情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM