Friday, April 23, 2010

Games on App Engine: An interview with Jay Kyburz, developer for Neptune’s Pride

One of the many classes of application that App Engine facilitates building is online games, particularly collaborative ones. Games often start off small, but can see incredible growth rates as people convince their friends to join, and App Engine’s seamless scaling makes handling these sort of traffic spikes a breeze. Recently, we got together with Jay Kyburz, developer for the game Neptune’s Pride, and asked him a few questions about his game, and how App Engine has worked out for him.

Q. Can you tell us a little about Neptune’s Pride?
Neptune's Pride is a real-time multi-player game of strategy, intrigue and galactic conquest. The game is played over several weeks, and players can log in at any time to upgrade their stars, dispatch their ships and most important of all, conspire with the other players.

Neptune's Pride is not like most web strategy games. The game itself is very simple, which allows players to focus on high level strategic decisions, teamwork and diplomacy.

Q. How long did it take to build your back-end on App Engine? Did you build it from scratch, or port it from another setup?
Neptune's Pride is my first App Engine game, and in fact my first web-based game. It's difficult to say exactly how long was spent developing the back-end as the game grew organically.

One thing I can say is that I spent much less time working on server code than I do working on the interface. Less than 5% of my time is spent writing code that runs on the server.

Q. Which runtime did you implement Neptune's Pride in?
Python, I love Python! Python is my language of choice for any project. Plus, the Java runtime didn't exist when I first started working on Neptune's Pride.

If there were a Javascript runtime I would consider using it, only so that my client and server code were written in the same language. What I want to know is why browsers don't have Python interpreters?

[Ed: There is a Java-based Javascript runtime available, at appenginejs.org.]

Q. What tip(s) would you offer new developers still exploring or just getting started with App Engine?
The power of App Engine is that you don't need to think about App Engine. "It just works!"

If you're a small developer like me, you don't really care much about what’s happening on the server. Some engineers want to tinker with things and know they have total control. My application’s interface is far more important.

I don't know if this is good advice, but one thing I wish I had done differently would be to have fewer, larger models.

There are a few occasions where I thought It would be a good idea to break a model up because some of the time I only need a subset of the data. I use reference properties to connect my models together so it's no work to retrieve the extra data, however it introduces additional requests, and additional points of failure. I think I would have preferred to just pull more data out of the database with fewer requests.

Q. Your core application is a game - how do you use App Engine to support what has traditionally been a client-centric type of app?
Actually, I didn't really tackle this problem very well. My game code was written as a stand alone Python application with no knowledge at all of the underlying database. Every time the user logs in or gives an order to one of their units, I just pull the whole structure out of the database, un-pickle it, process the order, and shove it back in.

This was fine for Neptune's Pride where a game can have no more that 12 players and has a finite set of data.

I have already started planning a game, more like an MMO, were all players can interact with each other and play on a "global" playing field. This game will need to be much smarter about how data is stored and retrieved from the database.

Q. What App Engine tools or APIs have been particularly useful in developing Neptune's Pride?
I don't know I can point to any one API or tool that has been particularly useful. Isn't the power of App Engine the fact that it's a one stop shop?

Q. What led you to choose App Engine as the platform to use?
Because it was easy. I know its not a very exciting thing to say on the App Engine blog, but really I chose it because I don't want to be thinking about my server, I want to be thinking about my game. App Engine allows me to do that.

Q. Are there any features that you're looking forward to, or that will be particularly useful for you?
I like the sound of background servers that run longer than 30 seconds. I have a couple of processes now that prune data out of the database, these operations are slow. Perhaps I shouldn't bother given how cheap storage is, but I like the idea of my application running forever with no human interaction.

These cleanup operation are the only things that occasionally throw Deadline Exceeded Errors.

Comet communication sounds like something I should be interested in!

Q. If you could change one aspect of App Engine, what would it be?
Another difficult question! Nothing is really getting in my way.

Google has so many great services and tools. I'd like it to be even easier to hook them all up together. If I were going to ask the App Engine team for any one feature it would be to have a look at all the other services out there and make sure it's easy to access them, then give me some code I can just copy and paste into my app :)

Q. Have you had any difficulty scaling your app as it increased in popularity?
Nope, again everything has just worked. As somebody who is new to all this I don't really even know what kinds of problems to expect as I scale, or what performance I should expect, or even the definition of a lot of users. All I can tell you is that I've seen no performance change between 2k requests and 200k requests a day.

I did hit my quota one day, and as a result the game was down for about 4-5 hours. Now I like to keep my usage under 10% of my quota so that if I do experience a spike in traffic there is plenty of room to grow.

I imagine if I grow much bigger I will need to change the application’s interface so that it’s easier for you to find a game, or join your friends in a game. I'm holding off making these changes because I'm also trying to work out the best way to build "social" tools into the game.

I want players to be able build a network of friends they enjoy playing against, then provide some tools to help them stay in touch and coordinate the creation of new games or other events like competitions.

Q. Have you used Appstats? Did you learn anything surprising about your app, and did it have an impact on your app's performance?
I did implement the stats when they first came out but didn't find anything very exciting. I simply confirmed what I already knew, which was that my game code is the slowest part of the application.

Q. Your monetization strategy is quite novel for an online game. What has the uptake and user response been like? Would you recommend it to other developers?
Actually, I just thought I was doing what everybody else is doing these days, a virtual currency. I chose it over a subscription model so players have the freedom to spend it as fast or as slow as they like.

I'm not sure I will use it on the next game. I've been considering a non renewing subscription rather than extracting credits from players every time they join a game. Pay once, forget about it, and enjoy all the sites features as a premium member.

Q. What peak QPS do you see currently? What is your latency for different types of requests?
The game peaks at about 6-8 Requests/Second. Average CPU is about 280ms (130 API).

Q. Any tips to help me overrun the interstellar empires of the rest of the App Engine team?
Know when to strike!

No comments: