From the Canyon Edge -- :-Dustin

Monday, July 13, 2009

Introducing PowerNap!

Ladies and gentlemen, I'm pleased to announce an exciting, new open source project from Canonical for the Ubuntu Server -- PowerNap!

Mark's Karmic Koala announcement alluded to this work when he wrote:
A savvy Koala knows that the best way to conserve energy is to go
to sleep, and these days even servers can suspend and resume, so imagine
if we could make it possible to build a cloud computing facility that
drops its energy use virtually to zero by napping in the midday heat,
and waking up when there's work to be done. No need to drink at the
energy fountain when there's nothing going on. If we get all of this
right, our Koala will help take the edge off the bear market.
I have just uploaded PowerNap to Karmic, and we are well on our way to integrating the technology into the 9.10's Ubuntu Enterprise Cloud.

Actually, I spent last week in sunny Santa Barbara, California working with Dan Nurmi, of Eucalyptus Systems. We shot some amateur digital videos of Ubuntu Karmic Servers, PowerNap/PowerWake, Eucalyptus, and a Watt meter in action. I'll get those posted soon!

I'll go into much deeper technical detail on the design and implementation of PowerNap over the next few weeks in subsequent posts, but I'll give an overview here...

How Does It Work?

PowerNap operates sort of like a screen saver for servers. Besides watching the console and terminals for keyboard activity, it also watches the system's process table for activity.

An administrator defines a list of regular expressions describing some critical MONITORED_PROCESSES that should be running. When powernapd notices that all of the MONITORED_PROCESSES have been absent from the process table for some configurable ABSENT_SECONDS, powernapd emits a warning to all users of the system that it will run powernap, unless canceled within the next GRACE_SECONDS.

Sample Configuration

In the Ubuntu Enterprise Cloud case, the configuration file, /etc/powernap/config, might look something like:
MONITORED_PROCESSES = [ "^/usr/bin/kvm " ]
ABSENT_SECONDS = 300
GRACE_SECONDS = 60
Thus, if no instance of kvm runs for 5 minutes, then the system will emit a warning, and powernap after a 1 minute grace period.

PowerNap Now!

Alternatively, a system administrator can force the system to powernap immediately by either running /usr/sbin/powernap directly, or sending powernapd the "now" signal with: service powernap now. In fact, this is what the Eucalyptus Node Controller does, such that it can maintain state, and directly control its managed nodes.

What constitutes a powernap?

So, powernap will first check if /etc/powernap/action is executable, and if so, it will run that file. This will allow you, as an administrator, to run any arbitrary script or program of your design when powernapd determines that your server has become idle. Your script could send an email, for example.

echo "Inefficient server, wasting energy" | mail Al_Gore@example.com
But in the default case, powernap will check if your server supports suspend-to-ram, and if so, it will pm-suspend your system. Otherwise, it will suspend-to-disk, or power the system off, depending on the sleep states supported by your hardware.

Slick, huh? :-D

Beyond the Cloud

While PowerNap is bespoke for the Ubuntu Enterprise Cloud, I have implemented it in manner that I hope is generically useful.

In fact, I'm currently using PowerNap on my Mythbuntu front ends! My configuration currently looks something like:
MONITORED_PROCESSES = [ "mplayer", "vlc", "xine", "mythfrontend.real", "xmms", "gthumb" ]
ABSENT_SECONDS = 240
GRACE_SECONDS = 60
My hardware supports S3 suspend-to-ram, so this is great! If 4 minutes go by, where I'm not running any of my media players (mplayer, vlc, xine, mythfrontend.real, xmms), I'm given a 1 minute grace period, and then my system suspends. I have configured wake-on-usb and wake-on-lan in the BIOS, so I can resume the system in a couple of seconds either by tapping a key or sending a WoL magic packet.

But in the mean time, I've reduced the power consumption of 4 systems by 90%, for most of every day while I'm not directly using MythTV!

What about Waking Systems?

Which brings me to PowerNap's kid brother...PowerWake. /usr/bin/powerwake is another Python script. This script is designed to be a smarter, remote waking utility. Currently, it supports wake-on-lan, but it will eventually support other mechanisms, such as IPMI, and perhaps NUT.

With respect to wake-on-lan, it's "smarter" than some other wake-on-lan utilities because it uses a hierarchy of cache files, configuration files, and the current arp table, such that you can wake a system by MAC address, or IP address, or hostname. I find this far more convenient than trying to remember or look up MAC addresses. powerwake respects static configuration in /etc/ethers and maintains a dynamically learning cache of known MAC addresses in /var/cache/powerwake/ethers.

Interesting?

I'm eager to hear what other uses you might have for PowerNap and/or PowerWake for your data centers, basements, and living rooms!

Saving a few Watts,
:-Dustin