What is this going to cost, anyway?

Ain’t nothing cheap about spaceships

As I wrap up this degree with the final capstone course (that I hopefully won’t have to retake), I find myself asking the exact same question I did when I was applying to the program – how much will it cost? This time I’m not talking about tuition – that last payment was four days ago and I’ll never think of it again – I’m talking about the cost of the cloud.

AsteroidCrusaders runs on AWS. So far we have three EC2 T2 micro instances (front end, back end, game server), a hosted zone, and some tables in DynamoDB. SSL certs are free these days if you’re willing to do a little maintenance every three months. There are a few other random costs like Secrets, but that is only a few cents. Our biggest single expense was for asteroidcrusaders.com at $12, I think that is for a year. So, if we didn’t have a free tier account that would all probably add up to 10-20 bucks per month.

But what happens if people actually play the game? We will have to leverage more of everything from AWS. And at some point, we’ll start to care about how much the infrastructure costs per user. We would need that number (hypothetically) to determine how many ads we have to saturate the page with or how much to charge for the very fine privilege of flying an orange triangle around instead of the boring old green one. There is plenty that goes into these calculations that I have no ability to predict right now, much like the memory leaks in my game code clogging up our EC2 game servers. Hopefully our EC2 usage efficiencies will go up in the near future. There is one cost, however, that I haven’t yet mentioned which will scale in a very predictable way: data transfer cost.

As we come up on the midpoint demonstration, AsteroidCrusaders runs all simulations on the server. Why? Because that makes it simple to synchronize all the clients and we need something to demonstrate. So 30 times per second, the game server collects all of the inputs from the connected players, does some trigonometry that had me reaching for my 8th graders math book, and feeds back to every connected client the new positions of all the triangles in space. What the game server does not do yet is check for collisions. We’re only at the course midpoint after all.

The point is AWS is going to charge us for each of the 30 position updates per second that are sent from the EC2 game server back to the client. After a free GB on the house, it’s going to cost about $0.10 per GB for a good while until bulk pricing starts to bring that back down. To plug in some numbers, for each object in the game world the game server send two 32 byte numbers for the x and y coordinates, 8 bytes for the object id, and a byte for its rotation, and perhaps 10 other bytes for random flags (we will omit all the bytes for the json structure we currently use and pretend we’re better than that). So that is 83 bytes per object in space sent to each connected client 30 times per second. With 50 asteroids and 3 players, that would be ( 83 * 53 * 3 * 30) 395910 bytes per second leaving AWS and getting charged. If those players play for an hour they will have used 1.43 GB, or $0.14!

OK, we’re not quite at tuition dollar amounts yet, but I’m still glad I took the time to figure this out before seeing the AWS bill (go ahead, ask me about my student loan interest), and we actually have taken steps to control this cost, such as taking steps to ensure a player can’t idle for too long in the game world and dropping the idea of letting players shoot thousands of missiles. Lasers are much cooler anyway.

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *