Skip to content

Commit

Permalink
Merge pull request #8 from pradykaushik/issues/issue-4-update-readme-…
Browse files Browse the repository at this point in the history
…dockerfile-code-systemload-memory-pressure-module

Issues/issue 4 update readme dockerfile code systemload memory pressure module
  • Loading branch information
pradykaushik committed Oct 19, 2019
2 parents b6538a7 + 0a3b71a commit 37e1ba7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ COPY . /
# Compiling the source files for SimulateConstIncreaseLoadAverage.
# RUN javac SimulateConstIncreaseLoadAverage.java

# Compiling the source files for SimulateCPULoadWithMemoryPressure.
# RUN javac SimulateCPULoadWithMemoryPressure.java

# Generate CPU load with step size 1%.
# Please note that this is a default run command.
# Further command line arguments can be given.
Expand All @@ -28,3 +31,6 @@ COPY . /

# Generate Load Average with LOAD_AVERAGE_LIMIT_CORE = 10.0 and STEP_SIZE = 0.2.
# CMD java SimulateConstIncreaseLoadAverage

# Generate CPU Load with Memory Pressure with CPU load in range [60,80]% and RAM usage as 4096 bytes.
# CMD java SimulateCPULoadWithMemoryPressure 60 80 4096
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# CPU Load Generator

A CPU Load generator that constantly increases the CPU utilization of a machine from 1% to 100%.
CPU Load generator that constantly increase the CPU utilization of a machine from 1% to 100%.
Forked from [SriramKeerthi-Gist](https://gist.github.com/SriramKeerthi/0f1513a62b3b09fecaeb) and added functionality.

## Instructions to execute the program
Expand Down Expand Up @@ -50,7 +49,7 @@ A 1 minute load average generator that constantly increases the load average for
Two _command-line_ arguments can be specified.

* **START\_LOAD\_AVERAGE\_CORE** - TYPE: _decimal_ (default = 1/numCores). This specifies the starting value of 1min load average for a given core. This value signifies the number of processes that would be executed in the first minute.
* **STEP\_SIZE** - TYPE: _decimal_ (default = 0.2). This specifies the increase in load average that is to be generated every minute.
* **STEP\_SIZE** - TYPE: _decimal_ (default = 0.2). This specifies the increase in load average that is to be generated every minute.


Run the following command to compile.
Expand All @@ -72,3 +71,35 @@ _Note:_ The above command is also set as the command to execute when the contain
```commandline
docker run pkaushi1/cpu-loadavg-generator:latest
```

# CPU Load Generator with Memory Pressure
Generates CPU load with Memory pressure.

## Instructions to execute the program
Three _command-line_ arguments can be specified.

* **minCpuLoadPercentage** - Minimum CPU usage pressure.
* **maxCpuLoadPercentage** - Maximum CPU usage pressure.
* **ramUsageBytes** - RAM usage bytes.


Run the following command to compile.
```commandline
javac SimulateCPULoadWithMemoryPressure.java
```

Run the following command to generate CPU load with memory pressure.
```commandline
java SimulateCPULoadWithMemoryPressure
```


## Using the dockerized application
Use the dockerized application and run any one of the above commands,
```commandline
docker run pkaushi1/cpu-load-with-memory-pressure-generator:latest <command>
```
_Note:_ The above command is also set as the command to execute when the container is launched. So, one could just type the below command to run the load average generator.
```commandline
docker run pkaushi1/cpu-load-with-memory-pressure-generator:latest
```
28 changes: 15 additions & 13 deletions SystemLoad.java → SimulateCPULoadWithMemoryPressure.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@
/**
* Generates CPU and memory pressure
*/
public class SystemLoad {
public class SimulateCPULoadWithMemoryPressure {

public static void main(String[] args) {
try {
int numCore = Integer.parseInt(args[0]);
int numThreadsPerCore = Integer.parseInt(args[1]);
int minCpuLoadPercentage = Integer.parseInt(args[2]);
int maxCpuLoadPercentage = Integer.parseInt(args[3]);
int ramUsageBytes = Integer.parseInt(args[4]);

ProcessorArchInfo procArchInfo = ProcessorArch.getProcessorArchInformation();
int numCore = procArchInfo.getNumCores();
int numThreadsPerCore = procArchInfo.getNumThreadsPerCore();
int minCpuLoadPercentage = Integer.parseInt(args[0]);
int maxCpuLoadPercentage = Integer.parseInt(args[1]);
int ramUsageBytes = Integer.parseInt(args[2]);

int threadsToCreate = numCore * numThreadsPerCore;
for (int thread = 0; thread < threadsToCreate; thread++) {
byte[] memory = new byte[ramUsageBytes / threadsToCreate];
Expand All @@ -45,8 +46,8 @@ public static void main(String[] args) {
System.out.println("Failed to start!" + e.getMessage());
e.printStackTrace();
System.out.println("Usage: ");
System.out.println("javac SystemLoad.java");
System.out.println("java SystemLoad [num-of-cores] [num-of-threads-per-core] [min-cpu-usage-pressure] [max-cpu-usage-pressure] [memory-bytes-pressure]");
System.out.println("javac CPULoadWithMemoryPressure.java");
System.out.println("java CPULoadWithMemoryPressure [min-cpu-usage-pressure] [max-cpu-usage-pressure] [memory-bytes-pressure]");
}
}

Expand All @@ -59,7 +60,7 @@ private static class BusyThread extends Thread {
private final int minCpuLoadPercentage;
private final int maxCpuLoadPercentage;
private final byte[] memory;

public BusyThread(String name, int minCpuLoadPercentage, int maxCpuLoadPercentage, byte[] memory) {
super(name);

Expand All @@ -74,11 +75,12 @@ public BusyThread(String name, int minCpuLoadPercentage, int maxCpuLoadPercentag
*/
@Override
public void run() {

final int cpuPressureRange = maxCpuLoadPercentage - minCpuLoadPercentage;

try {
System.out.println(String.format(Locale.US, "Thread %s starting with CPU pressure [%d-%d] and %d bytes", getName(), minCpuLoadPercentage, maxCpuLoadPercentage, memory.length));
System.out.println(String.format(Locale.US, "Thread %s starting with CPU pressure [%d-%d] and %d bytes",
getName(), minCpuLoadPercentage, maxCpuLoadPercentage, memory.length));
Thread.sleep(cpuPressureRange);

while(true) {
Expand Down
9 changes: 9 additions & 0 deletions cpu-load-with-memory-pressure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"name": "cpu-load-with-memory-pressure",
"cpu": 10.0,
"ram": 8192,
"image": "pkaushi1/cpu-load-with-memory-pressure-generator:latest",
"cmd": "java SimulateCPULoadWithMemoryPressure 60 80 4096"
}
]

0 comments on commit 37e1ba7

Please sign in to comment.