Code Wars V

Program / Task Name:

   Server Blade Power Consumption




Point Value:




Task Description

Server blades are the newest trend in Web Server design. A web site may be built on a large number of very compact ‘blade’ servers, which omit the expansion slots, floppy and CD-ROM drives in order to squeeze the server into a very small package. The blades fit into an “Enclosure”, which allows up to 20 blade servers to share common parts (cooling fans, power supplies, etc.). Each blade server consumes less power than a traditional web server, but since upwards of 300 blade servers fit into a single computer rack, power consumption is still an important issue!

In addition, blade servers include power-saving modes, which allow them to reduce their power usage during off-peak hours. This is the same technology used in laptop computers to squeeze more time out of their batteries. A blade normally operates in FULL power mode, providing the most performance available. When the server is not busy, it will go to LOW power mode, reducing performance but saving electricity. If the server is not needed for a while, it can go into SLEEP mode, which turns the server off, but allows it to ‘wake up’ quickly when needed (servers consume a little bit of power while in sleep mode).

Your task is to build a reporting system which, given a one-day log file showing changes in power usage, will generate a daily power and system uptime report for an enclosure of 20 blade servers.

Each blade server can be identified by its location within the enclosure (each blade server occupies a single “bay”, or slot, in the enclosure). These bays are numbered from 1 to 20. A blade’s power consumption can be calculated by multiplying its power consumption rate by the time spent operating at that rate. Power consumption is measured in Watt-hours, which we commonly abbreviate as just “Watts”. For example, your desk lamp probably has a 60 Watt light bulb (it’s really a 60 Watt-hour light bulb). If you run the lamp for 2 hours, you’ve consumed 120 Watts. You buy power from the electric company in units of kilowatt-hours. If power costs $0.09 per kilowatt-hour, running that lamp for 2 hours cost about a penny (.120 kilowatt-hours at $.09 per kilowatt-hour equals $.0108).

Since computers convert all electrical energy they consume into waste heat, we can also calculate how much heat is produced by the blades. This information is important to computer room designers, as it tells them how big their air conditioning equipment needs to be. Heat output is measured in BTU’s per hour (again, we usually just say BTU’s). 1 Watt-hour of energy converted to heat will generate 3.412 BTU/hr. So that desk lamp would have generated 409.44 BTU’s while it was on.

Program Input

The input file consists of two header lines, followed by the Power Event Log. Commas separate each field in the input file. The first header line contains a report date (MM/DD/YYYY), the customer’s company name, and the cost of electricity per kilowatt-hour (in dollars and cents). The second header line describes the power consumption ratings of a single blade in its four operating modes: OFF, SLEEP, LOW, and FULL.

The Power Event Log contains a list of each power event, listed on its own line. Each event contains three fields, separated by commas. The first field is the time of the event, in the format HH:MM, in 24-hour time (for example, 12:39am is stored as 00:39, while 2:00pm is stored as 14:00). This is followed by the blade’s bay number, and lastly by the new power state of the blade. For example, the line “00:01,1,FULL” means that the blade in bay #1 went to FULL power mode at 12:01am.

You should continue reading Power Event Log entries until you reach the end of the file. The Power Event Log could contain hundreds or even thousands of entries.

The log should be interpreted using the following rules:

  • The log always starts at 00:00 (midnight), although no events are guaranteed to occur at midnight

  • Before the start of the log, all server blades are OFF

  • Log entries will always occur ascending in time (time never goes backwards!)

  • Log entries occurring within the same minute can be assumed to occur simultaneously (at the start of each minute)

  • The log ends at 00:00 on the next day, and the last event could occur at 23:59 (11:59pm)

A simple example input file is shown below (for a system with 5 blades).


Program Output

The program must respond by writing a report to the output file. The report header must include a report title, the date of the report, and the customer’s name. The main report section must list each blade (1-20) on a separate line, with each line containing the bay number, the total uptime for the blade in that bay (HH:MM), and the total power consumed by the blade (in Watts, to two decimal places). Uptime counts the number of minutes a blade server is in either the FULL or LOW power states.

At the end of the report, four lines must appear that show the following information for all 20 blades: The total uptime (HH:MM), the total power consumed, heat produced, and cost of the electricity used (all to two decimal places).

Do not round any values until ALL of the calculations have been made. The following values must fall within the specified error ranges:

Power Consumed (by a single blade): +/- .5 Watt
Total Power Consumption: +/- 5 Watts
Total Heat Produced: +/- 5 BTUs
Total Electrical Service Cost: +/- $0.02

See the results below for examples.


       Server Blade Power Log

       January 31, 2002



Bay    Uptime        Power Consumed

---    ------        --------------

1      23:59         520.46 Watts

2      19:07         439.84 Watts

3      14:48         385.68 Watts

4      14:48         385.44 Watts

5      00:00         41.98 Watts


Total combined uptime: 72:42

Total power consumption: 1773.40 Watts

Total heat produced was 6050.84 BTUs

Total electrical service cost was $0.14


hp Code Wars
Hello -- Dominos?...
  (c) 2004 Hewlett-Packard Company