I’ve released a new version of deSleeper. This update provides an alternative way to “precache” hostnames in a kind of offline ARP table. Also fixes some errors that occurred when additional types of network cards (such as those VMWare installs) were present.
Thursday, March 26, 2009
Sunday, March 22, 2009
I run an open-source project, deSleeper, on Codeplex. The purpose of this utility is quite simple. Allow users to remotely wake up their machines from low-power states. If users use these features they’ll find it more practical to have their PC’s off or in sleep mode more often, thus saving energy.
Every network card has the basics to make this work, but there are plenty of obstacles that can get in the way. The purpose of deSleeper is to give ways around those obstacles, and hopefully simplify the process as well. I think I’ve succeeded in the first goal, though the second is still a work in progress. It’s simpler than without deSleeper, but it isn’t average user simple.
While I work on that, anyone who uses deSleeper may find it helps to understand the architecture when you're unsure how to setup your system. I’ve endeavored to help you do this by writing an architecture and setup guide.
- Target - The machine that goes to sleep automatically or manually and needs to be reactivated remotely.
- Client - The machine you're using when you want to wake up the client.
- Proxy - The machine which listens for requests from clients and uses it's superior network access to get a magic packet to the network card of the target.
Understanding these components helps understand the steps necessary to set them up.
These steps are:
- Configure the target's network interface. It is not always necessary, but many network cards do not have wake-on-LAN enabled by default. You don't need deSleeper to do this, but help you avoid hunting around in Device Manager deSleeper provides the "Network Card Configuration" tab. If you know how to do this without deSleeper's help you don't need to install deSleeper on the target.
- Install Proxy Service - Clients usually have obstacles between them and the target. The proxy service needs to be installed on a machine physically located on a network that avoids these obstacles. The safest spot is connected to the same network switch, but depending on your network setup farther away may work as well. There are plenty of variables here so when in doubt closer is better. The "Service Installation" tab is only available if you install the full version. This tab helps configure the proxy service which will run in the background and boot with proxy machine.
- Install Client - The easiest step, install your client. You can use the full version or the client only version.
Once everything is setup, all that is left to do is send a wake up request.
The requests use web-services calls to contact the proxy with the target information. Where this request is sent is the "destination". deSleeper also supports a "local" destination that does not use a proxy, but requires the client and target not to have obstacles in between each other.
Either the proxy, or if "local" the client, then constructs a "magic packet". Essentially a magic packet is a set of bytes in a simple pattern that the network card of the sleeping target can recognize it without the assistance of the CPU. When the network card recognizes a magic packet stamped with it's unique name (known as the MAC address), it sends messages to other components of the machine that turn on the CPU, memory, hard disk, etc, or take them out of super-low power states into operational states.
What can go wrong?
- If the network card isn't watching for the magic packet it won't wake up the machine.
- Magic packets are broadcast. Because the machine is off, it's not really possible to direct the request at the target. Networks limit the scope of broadcasts for many reasons. If the machine that broadcasts the magic packet is in a different scope from the target, the broadcast will never reach it.
- When using the "Host Name" wake up method, it needs to be possible to resolve the Host Name into a MAC address, because the MAC address is a critical part of the magic packet. On most networks it's not possible to do this while a machine is off. For this reason, the proxies maintain a "cache" of host name and MAC address pairs. But to initialize this cache it's necessary to send a wake up request once while the machine is on. Somewhat counter-intuitive to send a wake up request while online, which is why I'm looking into some other solutions, but it works well after the single request. Cache's on a proxy survive shutdowns and restarts, but they may not survive a reinstall of the deSleeper service.
Friday, March 20, 2009
Idempotency is a funny sounding word with a simple meaning, but a complex reality. Perhaps it’s even unfair to say it has a simple meaning because I’ve seen many attempts to define it that turn out rather convoluted. In the simple terms, I would define idempotency as the property of being able to perform the same action twice or more times in sequence, and end up with the same result as if it was performed once.
Those terms leave a fair bit of wiggle room when you really get down to the details. For example, those terms say nothing about additional actions occurring in between the first and last occurrence of the idempotent action. If there is one and only one action that can modify a resource than it’s not necessary to consider those details, but quite often that is not the case. Even operations like an HTTP PUT are only idempotent when the input is the same. Every different input for PUT is non-idempotent, with respect to every other input, unless of course If-Match is used and then some inputs are idempotent to other inputs but not to all.
As I’ve found in relation asynchronicity, a simple word, used without context, can cause more confusion than clarity. The transmission of a message and the receipt of it’s response may be asynchronous from a user’s perspective, but still remain synchronous from a HTTP protocol perspective. That is, from the user’s perspective clicking a link in the browser is asynchronous, because while the requests are sent, received, processed and rendered, only any modern computer the user can click on another tab, open another program, etc. But from the HTTP protocol perspective, even if the HTTP library provides a method like BeginGet, EndGet, some infrastructure is required to construct the request, transmit that request, and do nothing else until the response arrives (Even this is blurring the truth a bit since there is the timeout…).
So, back to idempotency, I rarely see the context of idempotency discussed or defined in a more clarified structure. I’ve occasionally seen references to idempotent sequences, but very rarely, not even enough to feel confident that my definition is the same as everyone else’s. The HTTP RFC gives this description:
A sequence is idempotent if a single execution of the entire sequence always yields a result that is not changed by a reexecution of all, or part, of that sequence.
I wouldn’t be at all surprised to find people who would believe an idempotent sequence was a sequence, that if performed twice or more in a row was idempotent, but the description above goes farther than that. In that description, the order of first execution of each action must remain constant, but reexecution can occur anytime after this first condition is met.
I can think of another, stricter set of actions, where the set of actions produces the same result regardless of order entirely, the only requirement to achieve the same result is that every action in a set is executed at least once. For the lack of knowing anything better to call such a set of action, I’d call them an idempotent set.
I think it’s not uncommon for architects and developers to overreach at times and assume something that is a collection of independently idempotent actions, is an idempotent set. You need an idempotent set in order to accommodate fully out of order execution, with a deterministic result. An idempotent sequence works only if you’re willing to accept a slightly non-deterministic result.
Another common circumstance that arises, is a set of actions, that will result in the same outcome as long as the first execution of a “final” action follows the initial execution of all other actions. This circumstance, which I’m struggling to find a good term for, is quite common.
I would love to hear from others on what definitions, or other common interaction patterns you’ve had experience with that relate to idempotency.