[8.10] [Profiling] More realistic CO2 and $ calculations (#164282) (#164411)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Profiling] More realistic CO2 and $ calculations
(#164282)](https://github.com/elastic/kibana/pull/164282)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Tim
Rühsen","email":"tim.ruhsen@elastic.co"},"sourceCommit":{"committedDate":"2023-08-22T10:02:17Z","message":"[Profiling]
More realistic CO2 and $ calculations (#164282)\n\nThis PR amends two
constants for the CO2 emission and dollar cost\r\ncalculations to get
more realistic results for the year
2023.","sha":"826633cffa677302154ea82ff8288a86a80d6d5a","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v8.10.0","v8.11.0"],"number":164282,"url":"https://github.com/elastic/kibana/pull/164282","mergeCommit":{"message":"[Profiling]
More realistic CO2 and $ calculations (#164282)\n\nThis PR amends two
constants for the CO2 emission and dollar cost\r\ncalculations to get
more realistic results for the year
2023.","sha":"826633cffa677302154ea82ff8288a86a80d6d5a"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/164282","number":164282,"mergeCommit":{"message":"[Profiling]
More realistic CO2 and $ calculations (#164282)\n\nThis PR amends two
constants for the CO2 emission and dollar cost\r\ncalculations to get
more realistic results for the year
2023.","sha":"826633cffa677302154ea82ff8288a86a80d6d5a"}}]}] BACKPORT-->

Co-authored-by: Tim Rühsen <tim.ruhsen@elastic.co>
This commit is contained in:
Kibana Machine 2023-08-22 06:10:44 -04:00 committed by GitHub
parent fcf7fbbeba
commit 96c2337d3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 34 deletions

View file

@ -16,35 +16,36 @@ describe('calculateImpactEstimates', () => {
});
expect(totalCPU).toEqual({
annualizedCo2: 17.909333333333336,
annualizedCoreSeconds: 1752000,
annualizedDollarCost: 20.683333333333334,
co2: 0.0005111111111111112,
coreSeconds: 50,
dollarCost: 0.0005902777777777778,
percentage: 0.1,
coreSeconds: 50,
annualizedCoreSeconds: 1752000,
co2: 0.00006265168194444443,
annualizedCo2: 2.1953149353333328,
dollarCost: 0.0005902777777777778,
annualizedDollarCost: 20.683333333333334,
});
expect(selfCPU).toEqual({
annualizedCo2: 8.954666666666668,
annualizedCoreSeconds: 876000,
annualizedDollarCost: 10.341666666666667,
co2: 0.0002555555555555556,
coreSeconds: 25,
dollarCost: 0.0002951388888888889,
percentage: 0.05,
coreSeconds: 25,
annualizedCoreSeconds: 876000,
co2: 0.000031325840972222215,
annualizedCo2: 1.0976574676666664,
dollarCost: 0.0002951388888888889,
annualizedDollarCost: 10.341666666666667,
});
expect(totalSamples).toEqual({
percentage: 1,
coreSeconds: 500,
annualizedCoreSeconds: 17520000,
co2: 0.005111111111111111,
annualizedCo2: 179.09333333333333,
co2: 0.0006265168194444444,
annualizedCo2: 21.95314935333333,
dollarCost: 0.0059027777777777785,
annualizedDollarCost: 206.83333333333337,
});
});
it('calculates impact', () => {
const { selfCPU, totalCPU, totalSamples } = calculateImpactEstimates({
countExclusive: 1000,
@ -54,31 +55,31 @@ describe('calculateImpactEstimates', () => {
});
expect(totalCPU).toEqual({
annualizedCo2: 17.909333333333336,
annualizedCoreSeconds: 1752000,
annualizedDollarCost: 20.683333333333334,
co2: 0.0005111111111111112,
coreSeconds: 50,
dollarCost: 0.0005902777777777778,
percentage: 0.1,
coreSeconds: 50,
annualizedCoreSeconds: 1752000,
co2: 0.00006265168194444443,
annualizedCo2: 2.1953149353333328,
dollarCost: 0.0005902777777777778,
annualizedDollarCost: 20.683333333333334,
});
expect(selfCPU).toEqual({
annualizedCo2: 17.909333333333336,
annualizedCoreSeconds: 1752000,
annualizedDollarCost: 20.683333333333334,
co2: 0.0005111111111111112,
coreSeconds: 50,
dollarCost: 0.0005902777777777778,
percentage: 0.1,
coreSeconds: 50,
annualizedCoreSeconds: 1752000,
co2: 0.00006265168194444443,
annualizedCo2: 2.1953149353333328,
dollarCost: 0.0005902777777777778,
annualizedDollarCost: 20.683333333333334,
});
expect(totalSamples).toEqual({
percentage: 1,
coreSeconds: 500,
annualizedCoreSeconds: 17520000,
co2: 0.005111111111111111,
annualizedCo2: 179.09333333333333,
co2: 0.0006265168194444444,
annualizedCo2: 21.95314935333333,
dollarCost: 0.0059027777777777785,
annualizedDollarCost: 206.83333333333337,
});

View file

@ -7,13 +7,20 @@
const ANNUAL_SECONDS = 60 * 60 * 24 * 365;
// The assumed amortized per-core average power consumption.
const PER_CORE_WATT = 40;
// The assumed amortized per-core average power consumption (based on 100% CPU Utilization).
// Reference: https://www.cloudcarbonfootprint.org/docs/methodology/#appendix-i-energy-coefficients
const PER_CORE_WATT = 7;
// The assumed CO2 emissions per KWH (sourced from www.eia.gov)
const CO2_PER_KWH = 0.92;
// The assumed CO2 emissions in kg per kWh (the reference uses metric tons/kWh).
// This value represents "regional carbon intensity" and it defaults to AWS us-east-1.
// Reference: https://www.cloudcarbonfootprint.org/docs/methodology/#appendix-v-grid-emissions-factors
const CO2_PER_KWH = 0.379069;
// The cost of a CPU core per hour, in dollars
// The assumed PUE of the datacenter (1.7 is likely to be an on-prem value).
const DATACENTER_PUE = 1.7;
// The cost of an x86 CPU core per hour, in US$.
// (ARM is 60% less based graviton 3 data, see https://aws.amazon.com/ec2/graviton/)
const CORE_COST_PER_HOUR = 0.0425;
export function calculateImpactEstimates({
@ -61,7 +68,7 @@ function calculateImpact({
const coreSeconds = totalCoreSeconds * percentage;
const annualizedCoreSeconds = coreSeconds * annualizedScaleUp;
const coreHours = coreSeconds / (60 * 60);
const co2 = ((PER_CORE_WATT * coreHours) / 1000.0) * CO2_PER_KWH;
const co2 = ((PER_CORE_WATT * coreHours) / 1000.0) * CO2_PER_KWH * DATACENTER_PUE;
const annualizedCo2 = co2 * annualizedScaleUp;
const dollarCost = coreHours * CORE_COST_PER_HOUR;
const annualizedDollarCost = dollarCost * annualizedScaleUp;