Last active
September 27, 2022 09:25
-
-
Save SriramKeerthi/0f1513a62b3b09fecaeb to your computer and use it in GitHub Desktop.
Revisions
-
SriramKeerthi revised this gist
Oct 18, 2019 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ package com.caffinc.grex.core; /** * SPDX-License-Identifier: MIT * * Generates Load on the CPU by keeping it busy for the given load percentage * @author Sriram */ -
Sriram Keerthi M K revised this gist
Mar 9, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,7 +48,7 @@ public void run() { try { // Loop for the given duration while (System.currentTimeMillis() - startTime < duration) { // Every 100ms, sleep for the percentage of unladen time if (System.currentTimeMillis() % 100 == 0) { Thread.sleep((long) Math.floor((1 - load) * 100)); } -
Sriram Keerthi M K created this gist
Mar 9, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ package com.caffinc.grex.core; /** * Generates Load on the CPU by keeping it busy for the given load percentage * @author Sriram */ public class Load { /** * Starts the Load Generation * @param args Command line arguments, ignored */ public static void main(String[] args) { int numCore = 2; int numThreadsPerCore = 2; double load = 0.8; final long duration = 100000; for (int thread = 0; thread < numCore * numThreadsPerCore; thread++) { new BusyThread("Thread" + thread, load, duration).start(); } } /** * Thread that actually generates the given load * @author Sriram */ private static class BusyThread extends Thread { private double load; private long duration; /** * Constructor which creates the thread * @param name Name of this thread * @param load Load % that this thread should generate * @param duration Duration that this thread should generate the load for */ public BusyThread(String name, double load, long duration) { super(name); this.load = load; this.duration = duration; } /** * Generates the load when run */ @Override public void run() { long startTime = System.currentTimeMillis(); try { // Loop for the given duration while (System.currentTimeMillis() - startTime < duration) { // Every 100ms, sleep for the percentage of "unloaded" time if (System.currentTimeMillis() % 100 == 0) { Thread.sleep((long) Math.floor((1 - load) * 100)); } } } catch (InterruptedException e) { e.printStackTrace(); } } } }