1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.cost;
/**
* Calculate tco and waste for one cluster within one Vespa application in one zone.
*
* @author smorgrav
*/
public class CostCluster {
private final double tco;
private final double waste;
private final CostClusterInfo clusterInfo;
private final CostResources systemUtilization;
private final CostResources targetUtilization;
private final CostResources resultUtilization;
/**
* @param clusterInfo Value object with cluster info e.g. the TCO for the hardware used
* @param systemUtilization Utilization of system resources (as ratios)
* @param targetUtilization Target utilization (ratios - usually less than 1.0)
*/
public CostCluster(CostClusterInfo clusterInfo,
CostResources systemUtilization,
CostResources targetUtilization) {
this.clusterInfo = clusterInfo;
this.systemUtilization = systemUtilization;
this.targetUtilization = targetUtilization;
this.resultUtilization = calculateResultUtilization(systemUtilization, targetUtilization);
this.tco = clusterInfo.getFlavor().cost() * Math.min(1, this.resultUtilization.getMaxUtilization());
this.waste = clusterInfo.getFlavor().cost() - tco;
}
public double getTco() {
return tco;
}
public double getWaste() {
return waste;
}
public CostClusterInfo getClusterInfo() {
return clusterInfo;
}
public CostResources getSystemUtilization() {
return systemUtilization;
}
public CostResources getTargetUtilization() {
return targetUtilization;
}
public CostResources getResultUtilization() {
return resultUtilization;
}
static CostResources calculateResultUtilization(CostResources system, CostResources target) {
double cpu = ratio(system.getCpu(),target.getCpu());
double mem = ratio(system.getMemory(),target.getMemory());
double disk = ratio(system.getDisk(),target.getDisk());
double diskbusy = ratio(system.getDiskBusy(),target.getDiskBusy());
return new CostResources(mem, cpu, disk, diskbusy);
}
private static double ratio(double a, double b) {
if (b == 0) return 1;
return a/b;
}
}
|