51 lines
1.8 KiB
Groovy
51 lines
1.8 KiB
Groovy
package recreationaltech.plugin
|
|
|
|
import nextflow.util.Duration
|
|
|
|
class K8sNoiseRuntimeEstimator extends K8sRuntimeEstimator {
|
|
// Magnitude of the noise we add
|
|
private long noiseMag
|
|
|
|
private HashMap<String, ArrayList<Tuple2<Long, Long>>> data;
|
|
private synchronized Random rnd;
|
|
|
|
/**
|
|
* Initialize the estimator with data recorded by K8sRuntimeRecorder
|
|
* @param dataFilePath
|
|
* @param noiseMagnitude magnitude of the noise added to recordings
|
|
*/
|
|
K8sNoiseRuntimeEstimator(String dataFilePath, Duration noiseMagnitude) {
|
|
this.data = parseDataFile(dataFilePath)
|
|
this.noiseMag = noiseMagnitude.toMillis()
|
|
this.rnd = new Random()
|
|
}
|
|
|
|
/**
|
|
* Initializes the runtime estimator with statically known data.
|
|
* @param data Map from task name to list of recordings, where each recording is a tuple (input-size, runtime-in-ms)
|
|
*/
|
|
K8sNoiseRuntimeEstimator(HashMap<String, ArrayList<Tuple2<Long, Long>>> data, Duration noiseMagnitude) {
|
|
this.data = data;
|
|
this.noiseMag = noiseMagnitude.toMillis()
|
|
}
|
|
|
|
/**
|
|
* Returns an estimation of the task runtime in milliseconds
|
|
* @param taskName the name of the task
|
|
* @param inputSize the total input size in bytes
|
|
* @return estimated task runtime in milliseconds OR infinity if the task is unknown.
|
|
*/
|
|
@Override
|
|
double estimate(String taskName, long inputSize) {
|
|
ArrayList recordings = data.get(taskName)
|
|
for (Tuple2<Long, Long> recording : recordings) {
|
|
if (recording.get(0).longValue() == inputSize) {
|
|
double noise = rnd.nextDouble(-1.0, 1.0) * (double)noiseMag
|
|
long ms = recording.get(1).longValue()
|
|
return (double)ms + noise
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
}
|