HeapSpace

This program fills up the heap space. If a memory error occurs depends on the computer executing the program.

The parameters for influencing the memory consumption can be given at the command line.

Basic Functionality

Introduction

The program simulates a Java program such as an application server. All parameters are adjustable at the command line.

The program reserves regularly a chunk of memory and releases it after some time.

Details

The following explains the program when running with the default parameters.

All following values are evenly distributed between the lower and upper bound.

The reserved amount of memory is between 1 KiByte and 4 MiByte. This is done by a class that reserves a byte[] with the given size.

The interval of object creation is between 0 and 200 milliseconds.

80% of the reserved memory is short lived and released after 0 to 1000 milliseconds (1 second).

15% of the reserved memory is medium lived and released after 1000 milliseconds (1 second) up to 150'000 milliseconds (150 seconds/2 minutes 30 seconds).

5% of the reserved memory is long lived and released after 150'000 milliseconds (150 seconds/2 minutes 30 seconds) up to 600'000 milliseconds (600 seconds/10 minutes).

Estimated Memory Consumption

The previous section shows the basic parameters. With this values the average memory consumption of the program can be estimated as follows. The values that are relevant are emphasized in the text.

Each reserved byte[] has a size of 2 MiByte on average (exactly 2048.5 KiByte on average).

On average every 100 milliseconds a new allocation is done. The exact value depends on the time which it takes to reserve the memory. This value would be added to the calculation value.

So we have an allocation rate of 20 MiByte/s (2 MiByte per allocation / 0.1 sec per allocation).

80% of the objects live for 0.5 sec on average. So from here we have a memory consumption of 8 MiByte (20 MiByte/s * 80% * 0.5 sec).

15% of the objects live 75 sec (exactly 75.5 sec). So we have on average we have 225 MiByte (20 MiByte/s * 15% * 75 sec) from the medium lived objects.

And at last we have 5% of the objects living for 375 sec (150 sec + (600 sec - 150 sec * 2)). On average this are 375 MiByte (20 MiByte/s * 5% * 375 sec).

This sums up to approx. 500 MiByte which the programs needs at least. Because a garbage collector needs some head space, and depending on the used JRE different garbage collectors are used, at least 1 GiByte should be reserved to run this application without memory issues.

Parameters

Introduction

The following sections explain all parameters that could be changed for a different behavior of the program.

Block Size

The block size (-b, --block-size) determines the maximum amount of memory that is reserved. The block size is given in blocks of 1 KiByte. The default value of 4096 reserves a maximum amount of 4 MiByte (4096 * 1 KiByte). The actual reserved amount of memory is determined a random number generator with the lower bound 1 and the upper bound 4096, which leads to an average amount of reserved memory of 2048.5 KiByte.

When rising the block size more memory will be reserved whereas reducing the size reduces the memory amount. This dependency is linear so that a doubled amount will lead to twice the amount of memory consumption.

Creation Interval

The creation interval (-c, --create) determines the maximum interval between object creation. The creation interval is given in milliseconds. The default value of 200 create a new object latest 200 milliseconds after the last object. The actual interval is determined by a random number generator with the lower bound 0 and the upper bound 200, which leads to an average creation interval of 100 milliseconds.

When rising the creation interval less objects will be created and vice versa. This dependency is reciprocal linear, a doubled creation interval leads to the half number of created objects.

Lifetime Parameters

The lifetime parameters have strong interdependencies, therefore all 5 parameters will be explained as a whole.

The 5 parameters (and their default values) are:

  • -s, --short-time: short living lifetime (default: 1000 milliseconds).
  • -m, --medium-time: medium living lifetime (default: 150'000 milliseconds / 150 seconds / 2 minutes 30 seconds)
  • -l, --long-time: long living lifetime (default: 600'000 milliseconds / 600 seconds / 10 minutes)
  • --med-prob: medium living probability (default: 15.0%)
  • --long-prob: long living probability (default: 5.0%)

The probabilities determine how many created objects are created with the given lifetime. With the default values a long lived object will be created with a probability of 5% (5 out of 100 objects will be long lived) and a medium lived object will be created with a probability of 15%. Short lived objects will be created with a probability of 80% (100% - (5% + 15%)).

The sum of the probabilities of medium lived objects and long lived objects may not be greater than 100%.

The lifetime of an object is determined by one of the other three parameters: -s, -m and -l.

The lifetime of a short lived object is determined by the parameter -s (or --short-time). A short lived object will live at most the parameters time milliseconds. After that the object will be made available for being collected.

The lifetime of a medium lived object is determined by the parameter -m (or --medium-time) and the short lifetime. A medium lived object will live longer than a short lived object, so the lower bound of the lifetime is given by the short lifetime of an object. The maximum lifetime of a medium lived object is given by the parameter on the command line.

The lifetime of a long lived object is determined by the parameter -l (or --long-time) and the medium lifetime.