Skip to content

Commit

Permalink
Merge pull request #16 from skrakau/handle_pue_param
Browse files Browse the repository at this point in the history
Handle PUE param
  • Loading branch information
skrakau authored Jul 31, 2023
2 parents 0bd593d + 67d8b30 commit e5d0e9f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import groovy.transform.PackageScope
* co2footprint {
* file = "co2footprint.txt"
* summaryFile = "co2footprint.summary.txt"
* pue = 1.4
* }
*
*
Expand All @@ -25,14 +26,18 @@ class CO2FootprintConfig {

final private String file
final private String summaryFile
final private Double pue // PUE: power usage effectiveness efficiency, coefficient of the data centre

CO2FootprintConfig(Map map){
def config = map ?: Collections.emptyMap()
file = config.file ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_FILE_NAME
summaryFile = config.summaryFile ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_SUMMARY_FILE_NAME
pue = config.pue ?: 1.67
}

String getFile() { file }

String getSummaryFile() { summaryFile }

Double getPUE() { pue }
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class CO2FootprintFactory implements TraceObserverFactory {
* Remaining factors
*/
// PUE: efficiency coefficient of the data centre
def pue = 1.67
def pue = config.getPUE()
// CI: carbon intensity [gCO2e kWh−1]
def ci = 475

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,36 @@ class CO2FootprintFactoryTest extends Specification {
traceRecord.'%cpu' = 100.0
traceRecord.memory = (7 as Long) * (1000000000 as Long)

def results = new CO2FootprintFactory().computeTaskCO2footprint(traceRecord)
def session = Mock(Session) { getConfig() >> [:] }
def factory = new CO2FootprintFactory()
factory.create(session)
def results = factory.computeTaskCO2footprint(traceRecord)

expect:
// Energy consumption converted to Wh and compared to result from www.green-algorithms.org
round(results[0]/1000) == 24.39
// CO2 converted to g
round(results[1]/1000) == 11.59
}

def 'test co2e calculation with non-default pue' () {
given:
def traceRecord = new TraceRecord()
traceRecord.realtime = (1 as Long) * (3600000 as Long)
traceRecord.cpus = 1
traceRecord.cpu_model = "Unknown model"
traceRecord.'%cpu' = 100.0
traceRecord.memory = (7 as Long) * (1000000000 as Long)

def session = Mock(Session) { getConfig() >> [co2footprint: [pue: 1.4]] }
def factory = new CO2FootprintFactory()
factory.create(session)
def results = factory.computeTaskCO2footprint(traceRecord)

expect:
// Energy consumption converted to Wh and compared to result from www.green-algorithms.org
round(results[0]/1000) == 20.45
// CO2 in g
round(results[1]/1000) == 9.71
}
}

0 comments on commit e5d0e9f

Please sign in to comment.