  Cloud platforms are increasing their emphasis on sustainability and reducing
their operational carbon footprint. A common approach for reducing carbon
emissions is to exploit the temporal flexibility inherent to many cloud
workloads by executing them in periods with the greenest energy and suspending
them at other times. Since such suspend-resume approaches can incur long delays
in job completion times, we present a new approach that exploits the elasticity
of batch workloads in the cloud to optimize their carbon emissions. Our
approach is based on the notion of "carbon scaling," similar to cloud
autoscaling, where a job dynamically varies its server allocation based on
fluctuations in the carbon cost of the grid's energy. We develop a greedy
algorithm for minimizing a job's carbon emissions via carbon scaling that is
based on the well-known problem of marginal resource allocation. We implement a
CarbonScaler prototype in Kubernetes using its autoscaling capabilities and an
analytic tool to guide the carbon-efficient deployment of batch applications in
the cloud. We then evaluate CarbonScaler using real-world machine learning
training and MPI jobs on a commercial cloud platform and show that it can yield
i) 51% carbon savings over carbon-agnostic execution; ii) 37% over a
state-of-the-art suspend-resume policy; and iii) 8% over the best static
scaling policy.
