@cloud-carbon-footprint/gcp
Version:
The core logic to get cloud usage data and estimate energy and carbon emissions from Google Cloud Platform.
235 lines (230 loc) • 9.91 kB
text/typescript
/*
* © 2021 Thoughtworks, Inc.
*/
import {
CloudConstantsByProvider,
CloudConstantsEmissionsFactors,
COMPUTE_PROCESSOR_TYPES,
EstimateUnknownUsageBy,
getWattsByAverageOrMedian,
} from '@cloud-carbon-footprint/core'
import {
GCP_DUAL_REGIONS,
GCP_MULTI_REGIONS,
GCP_REGIONS,
} from '../lib/GCPRegions'
import { configLoader } from '@cloud-carbon-footprint/common'
export const GCP_CLOUD_CONSTANTS: CloudConstantsByProvider = {
SSDCOEFFICIENT: 1.2, // watt hours / terabyte hour
HDDCOEFFICIENT: 0.65, // watt hours / terabyte hour
MIN_WATTS_MEDIAN: 0.68,
MIN_WATTS_BY_COMPUTE_PROCESSOR: {
// CPUs
[]: 0.64,
[]: 0.65,
[]: 0.71,
[]: 1,
[]: 1.14,
[]: 2.17,
[]: 3.04,
[]: 0.82,
[]: 0.47,
[]: 0.45,
// GPUs
[]: 26,
[]: 18,
[]: 8,
[]: 35,
[]: 35,
[]: 35,
[]: 46,
[]: 9,
[]: 36,
[]: 26,
},
getMinWatts: (computeProcessors: string[]): number => {
const minWattsForProcessors: number[] = computeProcessors.map(
(processor: string) => {
return GCP_CLOUD_CONSTANTS.MIN_WATTS_BY_COMPUTE_PROCESSOR[processor]
},
)
const wattsForProcessors: number = getWattsByAverageOrMedian(
computeProcessors,
minWattsForProcessors,
)
return wattsForProcessors
? wattsForProcessors
: GCP_CLOUD_CONSTANTS.MIN_WATTS_MEDIAN
},
MAX_WATTS_MEDIAN: 4.11,
MAX_WATTS_BY_COMPUTE_PROCESSOR: {
// CPUs
[]: 3.97,
[]: 4.26,
[]: 3.69,
[]: 4.74,
[]: 5.42,
[]: 8.58,
[]: 8.25,
[]: 2.55,
[]: 1.69,
[]: 2.02,
// GPUs
[]: 229,
[]: 153,
[]: 71,
[]: 306,
[]: 306,
[]: 306,
[]: 407,
[]: 76.5,
[]: 306,
[]: 229,
},
getMaxWatts: (computeProcessors: string[]): number => {
const maxWattsForProcessors: number[] = computeProcessors.map(
(processor: string) => {
return GCP_CLOUD_CONSTANTS.MAX_WATTS_BY_COMPUTE_PROCESSOR[processor]
},
)
const wattsForProcessors: number = getWattsByAverageOrMedian(
computeProcessors,
maxWattsForProcessors,
)
return wattsForProcessors
? wattsForProcessors
: GCP_CLOUD_CONSTANTS.MAX_WATTS_MEDIAN
},
NETWORKING_COEFFICIENT: 0.001, // kWh / Gb
MEMORY_COEFFICIENT: 0.000392, // kWh / Gb
PUE_AVG: 1.1,
PUE_TRAILING_TWELVE_MONTH: {
[]: 1.08,
[]: 1.11,
[]: 1.11,
[]: 1.09,
[]: 1.07,
[]: 1.09,
[]: 1.12,
[]: 1.13,
},
getPUE: (region: string): number => {
// Return region-specific PUE if available, otherwise use fleet-wide average
return GCP_CLOUD_CONSTANTS.PUE_TRAILING_TWELVE_MONTH[region]
? GCP_CLOUD_CONSTANTS.PUE_TRAILING_TWELVE_MONTH[region]
: GCP_CLOUD_CONSTANTS.PUE_AVG
},
AVG_CPU_UTILIZATION_2020: 50,
REPLICATION_FACTORS: {
CLOUD_STORAGE_SINGLE_REGION: 2,
CLOUD_STORAGE_DUAL_REGION: 2,
CLOUD_STORAGE_MULTI_REGION: 2,
COMPUTE_ENGINE_REGIONAL_DISKS: 2,
CLOUD_FILESTORE: 2,
CLOUD_SQL_HIGH_AVAILABILITY: 2,
CLOUD_MEMORY_STORE_REDIS: 2,
CLOUD_SPANNER_SINGLE_REGION: 2,
CLOUD_SPANNER_MULTI_REGION: 2,
KUBERNETES_ENGINE: 3,
DEFAULT: 1,
},
// these constants accumulate as the usage rows are mapped over
KILOWATT_HOURS_BY_SERVICE_AND_USAGE_UNIT: {
total: {},
},
ESTIMATE_UNKNOWN_USAGE_BY: EstimateUnknownUsageBy.USAGE_AMOUNT,
SERVER_EXPECTED_LIFESPAN: 35040, // 4 years in hours
}
export const getGCPEmissionsFactors = (): CloudConstantsEmissionsFactors => {
// These emission factors take into account Google Carbon Free Energy percentage in each region. Source: https://cloud.google.com/sustainability/region-carbon
if (configLoader().GCP.USE_CARBON_FREE_ENERGY_PERCENTAGE)
return {
[]: 0.0002152373529,
[]: 0.0002152373529,
[]: 0.0003255,
[]: 0.00011124,
[]: 0.00011124,
[]: 0.0000072,
[]: 0.0000893,
[]: 0.00030912,
[]: 0.00028835,
[]: 0.0001776,
[]: 0.00037848,
[]: 0.0002592,
[]: 0.00038976,
[]: 0.00026496,
[]: 0.00029325,
[]: 0.000603,
[]: 0.00061732,
[]: 0.00035712,
[]: 0.0005046,
[]: 0.00047242,
[]: 0.00035949,
[]: 0.0004608,
[]: 0.00001143,
[]: 0.000121,
[]: 0.0000198,
[]: 0.00007396,
[]: 0.0001076,
[]: 0.00013301,
[]: 0.0000129,
[]: 0.000298,
[]: 0.000059,
[]: 0, // Montreal is 100% CFE
[]: 0.00000232,
[]: 0.00002838,
[]: 0.0000589,
[]: 0.00065472, // Sum of asia-northeast1 + asia-northeast2
[]: 0.00014444, // Sum of europe-west4 + europe-north1
[]: 0.00033732, // Sum of us-central1 + us-east1
[]: 0.00139032, // Sum of region group data centers within Asia
[]: 0.00121064, // Sum of region group data centers within EU
[]: 0.00143137, // Sum of all US data centers
[]: 0.0002152373529, // Average across all regions (excluding multi and dual regions)
}
// These emissions factors don't take into account Google's CFE%, and just use the Grid emissions factors published by Google.
return {
[]: 0.000456,
[]: 0.000456,
[]: 0.000434,
[]: 0.000309,
[]: 0.000309,
[]: 0.00006,
[]: 0.00019,
[]: 0.000448,
[]: 0.000365,
[]: 0.000296,
[]: 0.000456,
[]: 0.00036,
[]: 0.000464,
[]: 0.000384,
[]: 0.000425,
[]: 0.00067,
[]: 0.000671,
[]: 0.000372,
[]: 0.00058,
[]: 0.000598,
[]: 0.000521,
[]: 0.000576,
[]: 0.000127,
[]: 0.000121,
[]: 0.00011,
[]: 0.000172,
[]: 0.000269,
[]: 0.000283,
[]: 0.000086,
[]: 0.000298,
[]: 0.000059,
[]: 0.000028,
[]: 0.000029,
[]: 0.000129,
[]: 0.00019,
[]: 0.000848, // Sum of asia-northeast1 + asia-northeast2
[]: 0.00041, // Sum of europe-west4 + europe-north1
[]: 0.000828, // Sum of us-central1 + us-east1
[]: 0.001676, // Sum of region group data centers within Asia
[]: 0.001843, // Sum of region group data centers within EU
[]: 0.002805, // Sum of all US data centers
[]: 0.0003171470588, // Average of the above regions (excludes multi/dual-regions)
}
}