# Optimizing hardware costs for Amazon EC2

by April 27, 2009

Velocity Labs believes heavily in the power of cloud computing. Dynamically allocated hardware on a pay-for-what-you-need basis has tremendous advantages when it comes to helping clients manage and provision their clusters. The main advantage of cloud computing is dynamically growing, or shrinking, hardware as the needs of the application change.

Because of the dynamic nature of cloud computing, we don't need a guaranteed answer on hardware requirements up front. However, a client may want a ballpark figure in order to set aside the right amount of budget or let investors know the estimated operational cost. You could crunch the numbers yourself, but why would you do that when we've already automated the process for you?

### Determining optimal cost

We've constructed a very basic model for minimizing the cost of Amazon EC2 hardware resources which satisfies a minimum number of EC2 Compute Units and a given amount of RAM per process.

The technique uses linear programming and the GNU linear programming kit (GLPK). Note: I'm a math geek that likes linear modeling, so if you're unfamiliar with either, I'd be happy to chat with you about them over lunch.

### Installation

First, install the GLPK. On Ubuntu execute the command

on Mac OS X execute the command

Next, create the following as `cloud_cost.txt`.

### Computing the cost

The model requires the specification of two variables: total number of EC2 Compute Units and RAM. Both variables are specified at the bottom with `param unitsNeeded` and `param ramRequiredPerAppInstance` respectively. Change these params to reflect your particular situation. Note: A future article will explore capacity planning in more detail.

When you're ready, execute the solver using the following command:

### Analyzing the results

The program generates the result into a file called `result.txt`. Assuming 500 EC2 Compute Units with 125MB of RAM per process, the file will look something like the following:

The objective function was cost, so the optimal arrangement of hardware needed to get that computational power costs \$14,400/month. The second column of the hardware arrangement indicates the number of instance needed. In this case we need 25 high-CPU, extra large instances.

Did you find this useful? Let us know in the comments!

### Curtis Miller

#### Managing Partner

Startup junkie, Rubyist and gamer. Loves to brainstorm about new ideas.

### Need help with your project?

We specialize in Ruby on Rails and JavaScript projects. Code audits, maintenance and feature development on existing apps, or new application development. We've got you covered.