Skip to content

Commit

Permalink
Merge pull request #36 from Green-Software-Foundation/models-refactoring
Browse files Browse the repository at this point in the history
Refactors teads-aws and teads-curve models
  • Loading branch information
jmcook1186 authored Feb 8, 2024
2 parents 3994008 + 089bc7e commit 3ebc2aa
Show file tree
Hide file tree
Showing 8 changed files with 922 additions and 739 deletions.
550 changes: 312 additions & 238 deletions src/__tests__/unit/lib/teads-aws/index.test.ts

Large diffs are not rendered by default.

465 changes: 290 additions & 175 deletions src/__tests__/unit/lib/teads-curve/index.test.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/lib/ccf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Interpolation,
KeyValuePair,
ModelParams,
IComputeInstance,
ComputeInstance,
} from '../../types/common';

import {allDefined, validate} from '../../util/validations';
Expand All @@ -28,7 +28,7 @@ import * as AZURE_EMBODIED from './azure-embodied.json';
const {InputValidationError, UnsupportedValueError} = ERRORS;

export class CloudCarbonFootprint implements ModelPluginInterface {
private computeInstances: Record<string, Record<string, IComputeInstance>> =
private computeInstances: Record<string, Record<string, ComputeInstance>> =
{};

private instanceUsage: KeyValuePair = {
Expand Down Expand Up @@ -385,7 +385,7 @@ export class CloudCarbonFootprint implements ModelPluginInterface {
vCPUs: cpus,
consumption,
maxvCPUs: parseInt(instance[maxvCPUs], 10),
} as IComputeInstance;
} as ComputeInstance;
});
}

Expand Down
30 changes: 16 additions & 14 deletions src/lib/teads-aws/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# Teads' AWS Estimation Model

> [!NOTE]
> `Teads-AWS` is a community model, not part of the IF standard library. This means the IF core team are not closely monitoring these models to keep them up to date. You should do your own research before implementing them!
> [!NOTE] > `Teads-AWS` is a community model, not part of the IF standard library. This means the IF core team are not closely monitoring these models to keep them up to date. You should do your own research before implementing them!
Teads Engineering Team built a model for estimating AWS instances energy usage. This model creates a power curve on a correlation to SPEC Power database. This allows the model to generate a power curve for any AWS EC2 instance type based on publicly available AWS EC2 Instance CPU data.

The main benefit of this model is that it accounts for all the components involved in an instance's compute capacity.


## Model name

IF recognizes the Teads AWS model as `teads-aws`
Expand All @@ -20,18 +17,17 @@ IF recognizes the Teads AWS model as `teads-aws`
- `interpolation`: the interpolation method to apply to the TDP curve
- `instance-type`: the name of the instance type, e.g. `t2.micro`

### Observations
### Inputs

- `cpu-util`: percentage CPU usage for the given time period
- `timestamp`: a timestamp for the observation
- `duration`: the amount of time, in seconds, that the observation covers.
- `timestamp`: a timestamp for the input
- `duration`: the amount of time, in seconds, that the input covers.

## Returns

- `energy`: The energy used in operating the application, in kWh
- `embodied-carbon`: The carbon used in manufacturing and disposing of the device


## Implementation

IEF implements this plugin based on the data gathered from the CCF (Cloud Carbon Footprint) dataset.
Expand All @@ -44,27 +40,28 @@ Resulting values are an estimate based on the testing done by Teads' Engineering
2. [TEADS Engineering: Estimating AWS EC2 Instances Power Consumption](https://medium.com/teads-engineering/estimating-aws-ec2-instances-power-consumption-c9745e347959)

## Example

```typescript
import {TeadsAWS} from '@grnsft/if-unofficial-models';

const teads = new TeadsAWS();
teads.configure({
instance_type: 'c6i.large'
})
instance_type: 'c6i.large',
});
const results = teads.execute([
{
duration: 3600, // duration institute
cpu: 0.1, // CPU usage as a value between 0 and 1 in floating point number
datetime: '2021-01-01T00:00:00Z', // ISO8601 / RFC3339 timestamp
}
},
]);
```

## Example `impl`

```yaml
name: teads-aws
description: simple demo invoking sci-m
description: simple demo invoking TeadsAWS model
tags:
initialize:
models:
Expand All @@ -77,15 +74,20 @@ graph:
pipeline:
- teads-aws # duration & config -> embodied
config:
teads-aws:
instance-type: m5n.large
interpolation: linear
expected-lifespan: 252288000
inputs:
- timestamp: 2023-07-06T00:00
duration: 3600
cpu-util: 10
```
You can run this by passing it to `impact-engine`. Run impact using the following command run from the project root:

```sh
npm i -g @grnsft/if
npm i -g @grnsft/if-unofficial-models
impact-engine --impl ./examples/impls/teads-aws.yml --ompl ./examples/ompls/teads-aws.yml
```
impact-engine --impl ./examples/impls/test/teads-aws.yml --ompl ./examples/ompls/teads-aws.yml
```
Loading

0 comments on commit 3ebc2aa

Please sign in to comment.