Inspiration
The Filecoin Green initiative is an attempt to provide transparency and insight into the electricity consumption and environmental impacts of the entire Filecoin blockchain network and to drive this impact to zero by allowing individual Filecoin Storage Providers (SPs) to make substantive, public, and verifiable environmental claims for their operations and to transition to environmentally sustainable carbon-neutral operations.
One requirement for SPs under the initiative is to record and publish the electricity consumption and CO2 emissions of the hardware for their operations:
The best source of activity data is metered electricity consumption, electricity utility bills, and reports that document electricity consumption in megawatt-hours (MWh) or kilowatt-hours (kWh). The activity data and information that SPs can submit may include, but is not limited to: -- Relevant minerIDs, which we can use to estimate bounds on power use -- Geolocation - approximate Lat / Long coordinates -- Monthly electricity bills -- Granular electricity use measurements, if available ...
Modern computing systems have many hardware components and the most accurate way to accurately measure system-wide electricity consumption is to use a specialized hardware power meter. However modern CPUs and GPUs contain user-accessible features for monitoring and controlling the power consumption of the underlying hardware via software interfaces. Blockchain nodes typically feature operations that require extremely heavy CPU and GPU usage that will typically dominate power consumption when active compared to other components like SSD drives, e.g. in the Filecoin energy consumption estimation model the estimated energy consumption rate for sealing a data sector is 3.42•10^-8 Wh/byte while the estimated rate for storing data is 3.00•10^-12 W/byte which is consumed continuously by the storage hardware. An estimate of the energy consumption rate for 4h of continuous proof-of-spacetime (PoSt) operations would be
(4 / 24) * (1 / (11 x 2000)) * 3.42•10^-8 W/byte
which is roughly comparable to the data storage consumption rate. This means we can still expect that measuring the electricity consumption of PoRe and PoSt calculations by the CPU and GPU components of a Filecoin SP hardware system can provide a useful estimate of electricity consumption of the entire hardware system, without the need to measure electricity consumption of other components like storage drives. On the Filecoin Green dashboard energy consumption of sealing operations is typically half that of storage operations, without accounting for PoSt and other CPU/GPU intensive operations.
For other blockchains that don't require continuous storage of large volumes of data we'd expect CPU/GPU electricity consumption to be much closer to the total system energy consumption of blockchain nodes.
This electricity consumption monitoring can be entirely software-based, automated, and can automatically publish measurement data to decentralized databases in real-time, without the need for installing additional hardware or modifying existing software or processes to facilitate electricity consumption measurement. This would allow blockchain sustainability initiatives like Filecoin Green to onboard miners very easily with a minimum of disruption to their existing operations or the need to purchase and install new hardware.
What it does
libpwrm is an embeddable library, CLI app and daemon for real-time, decentralized measuring and reporting on CPU and GPU hardware electricity consumption and CO2 emissions by blockchain nodes without requiring specialized hardware power meters. libpwrm provides software-based continuous monitoring of different hardware power consumption interfaces and automatic reporting of the measurement data and estimated emissions to the CO2.Storage IPFS-backed data network.
libpwrm can read power consumption data from different hardware power meters including laptop power supply meters. It can also read CPU power consumption data from Intel's Running Average Power Limit – RAPL interface which uses power metering builtin to Intel CPUs, and NVIDIA GPU power consumption data using the builtin GPU power meters and the NVML interface.
libpwrm runs continuously and publishes the power consumption and emissions data it collects for each system it runs on as assets on CO2.Storage. Each asset can be signed by the operator which authenticates the entity creating it and contains information that the blockchain node operator provides like a unique miner ID and geographic information together with up-to-date information on the current electricity consumption of their hardware. This allows individual blockchain node operators like Filecoin storage providers to automate reporting their electrical consumption data estimates in real-time without requiring installation of external power metering hardware or complex software or making changes to their existing processes.
The aggregated data collected can also provide a useful complement to existing methods of estimating power consumption of an entire blockchain network at a particular time.
libpwrm was originally entered into the Web3 Infinity hackathon where it was intended to use the Ceramic data network for storage. For the SBS Boston hackathon I added the following features:
- Connect to the WattTime API and fetch data on emissions for different electricity grids around the world. This allows the CO2 emissions for power usage by computer hardware in a particular geographical location to be estimated.
- Store the collecting power usage data and estimated emissions output as assets on the CO2.Storage service.
How we built it
The design goals of libpwrm are:
- Minimal dependencies, can be built and installed easily
- Can be used from different languages and FFIs like Golang's cgo
- Very lightweight, suitable for running continuously as a daemon without noticeable CPU utilization
libpwrm is written in C++. The code for reading system power meters and the Intel RAPL interface and other low-level interactions with the operating system is from the power monitoring and management program powerTOP. powerTOP contains a lot of code for detecting and interacting with hardware devices and peripherals via the Linux /dev filesystem interface without requiring additional dependencies. Using the powerTOP code as the core means libpwrm can easily support many different kinds of hardware and devices.
The code for power measurement readings for NVIDIA cards via NVML is adapted from here.
The NodeJS script for uploading the collected power usage and emissions data to CO2.Storage is based on the CLI example scripts
libpwrm estimates emissions using a statistical model developed by WattTime based on a value called the Marginal Operating Emissions Rate (MOER) for a local or regional electricity grid. MOER is key to [WattTime's mission] of enabling Automated Emissions Reduction (AER):
AER works by first quantifying the amount of environmental harm–most often measured in
greenhouse gas emissions per megawatt-hour–that would be caused by using a given amount of
additional electricity at different times and places. This is referred to as the marginal operating
emissions rate (MOER) for that time and place.
...
WattTime has for many years maintained a real-time API that provides sub-hourly
estimates of MOERs (including forecasts), 24/7 year-round, for all local electricity grids in the
continental United States and currently 27 other countries (as of mid-2022)
The MOER is specified in lbs/MWh according to the Balancing Authority (BA) that controls electricity output in a particular location. libpwrm estimates the electricity consumed by a hardware system or component over a period of time in kWh and MWh and then multiplies this by the MOER retrieved from WattTime to estimate the CO2 emitted for the period. This emissions estimate along with the energy consumed and identifying details of the hardware system can then be uploaded to CO2.Storage.
Getting started
Requirements:
- C++11 toolchain
- CMake 3.17 or greater.
- To monitor NVIDIA graphics card you'll need the CUDA Toolkit installed.
- To upload data to CO2.Storage you will need a recent version of NodeJS.
Installation
- Clone the git repository
git clone https://github.com/allisterb/libpwrm.git --recurse-submodules. - Run the
build-debugscript from the repo folder. - If you want to upload data to CO2.Storage:
- cd to the
src/co2.storagedirectory and runnpm install. - Create a
.envfile in the same directory with the required CO2.Storage settings plus other fields for recording power usage and emissions. See the.env.examplefile for an example.
- cd to the
- Run
./pwrm --helpfrom the repo folder to see the available commands. - To start the continuous monitoring daemon on the power usage of an NVIDIA card, run a command like
./pwrm daemon nv -r --wt-user mywtuser --wt-pass mywtpass --wt-ba mywtba --report-duration 60
What's next for libpwrm
The next feature I'd like to implement is saving hardware energy and emissions data as CSV so it can be visualized using the CodeCarbon offline visualization tool from the CodeCarbon project.
libpwrm currently supports only NVIDIA graphics cards and Intel CPUs. Future versions will support reading power management data from AMD's lineup of CPUs and GPUs via the /sys/kernel/debug/dri/0/amdgpu_pm_info device for instance.
Log in or sign up for Devpost to join the conversation.