1 /*
2 * $Id: ResourceQualityCalculator.java 1540 2011-08-17 13:30:37Z hoheisel $
3 *
4 * Copyright 2008 Fraunhofer Gesellschaft, Munich, Germany,
5 * for its Fraunhofer Institute for Computer Architecture and Software Technology (FIRST), Berlin, Germany
6 * All rights reserved.
7 *
8 * See http://www.first.fraunhofer.de and http://www.gridworkflow.org/gwes for more details.
9 */
10
11 package net.kwfgrid.gwes.prorater;
12
13 /**
14 * This class contains methods for the calculation of resource qualities based on monitoring information.
15 * @author Andreas Hoheisel, Fraunhofer FIRST
16 * (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
17 * @author Dietmar Sommerfeld, GWDG
18 * @version $Id: ResourceQualityCalculator.java 1540 2011-08-17 13:30:37Z hoheisel $
19 */
20 public class ResourceQualityCalculator {
21
22 private ResourceQualityCalculator() {
23 // only static methods!
24 }
25
26 /**
27 * Calculate the quality of a Batch Queue resource, such as PBS and LSF.
28 * @param runningJobs The number of running jobs in all queues.
29 * @param waitingJobs The number of waiting jobs in all queues.
30 * @return The quality as float number between 0 and 1.
31 */
32 public static float calculateBatchQueueQuality(int runningJobs, int waitingJobs) {
33 float quality;
34
35 // there are no jobs waiting in queue
36 if (waitingJobs == 0) {
37 quality = 1f;
38 }
39
40 // there are jobs waiting in queue
41 else {
42 if (runningJobs == 0) {
43 // if there are waiting jobs but no running jobs, there must be something wrong with this resource
44 quality = 0f;
45 } else {
46 quality = (float) Math.exp(-1.0f * ((float)waitingJobs) / ((float)runningJobs) );
47 }
48 }
49
50 return quality;
51 }
52
53 /**
54 * Calculate the quality of a PBS resource that supports waiting time estimation.
55 * @param queueWaittime The estimated queue waiting time in minutes
56 * @return The quality as float number between 0 and 1.
57 */
58 public static float calculateWaittimeQuality(float queueWaittime) {
59 float quality;
60 double time, base;
61
62 // with 3. alternative queueWaittime is negative if actual waittime already exceeds estimation
63 // positive values are calculated estimations, negative values are currently elapsed waittimes
64 time = Math.abs(queueWaittime);
65 base = Math.log1p(time) / Math.log(2.0d);
66
67 // quality=POTENZ(0,92;POTENZ(LOG(queueWaittime+1;2);1,5))
68 quality = (float) Math.pow(0.92d, Math.pow(base, 1.5d));
69
70 return quality;
71 }
72
73 /**
74 * Calculate the quality of a Fork resource.
75 * @param load The load of the resource (as defined in the linux program "top").
76 * @param cpus The number of cpus.
77 * @return The quality as float number between 0 and 1.
78 */
79 public static float calculateForkQuality(int load, int cpus) {
80 float quality;
81 float q = ((float)load) / 100f;
82 quality = 1.0f - q / ((float)cpus);
83 if (quality < 0f) quality = 0;
84 else if (quality > 1f) quality = 1f;
85 return quality;
86 }
87
88 }