Consoles
 

Archive for the ‘Python’ Category

Lifting the Tail: Inside Agora Skunk Works

by Aaron Westendorf, June 28th, 2010 at 09:08am - No Comments »
Posted in: Engineering, Infrastructure, Python
We’ve been hard at work for over a year developing the next generation of game integration technology here at Agora, and over the next few months we’ll be releasing some of the code that we’ve developed, discussing some of the challenges we face and how we’re using all the new technology to build the best gaming experience around.

To start, a brief explanation of the challenges we face.  As you might imagine, we deal with a lot of data.  The volume is only increasing, and with our friends at MLG, we expect significantly more of it.  Along with the volume of data, it also comes to us in many different forms and protocols; sometimes it’s pushed to us, and sometimes we have to go fetch it.  We have to respond to any number of business decisions made by developers and publishers, adapt to developers’ needs in a manner which does not negatively impact their schedule, and be a consistent and reliable partner to all our clients.  We have to deliver comprehensive documentation to both game and website developers, and our business relationships are aided by a consistent offering.

In the past, each game’s services would be its own Rails application.  We built a suite of re-usable components, but for each title we would have to re-write a lot of boiler-plate code and set up an entirely new suite of servers, complete with application hosts, web and caching proxies, databases and so on.  As our data throughput grew, we found that we needed to add additional components to our stack, such as Sparrow, to turn synchronous workloads into asynchronous ones.  Each project required extensive monitoring and reporting, an interactive console for viewing production data and testing staging code.

We were very successful, but found the business costs too high and that we were missing several features that were important to our long term strategy of being the best in the industry at game integration.  Our experience with a virtualized hosting environment opened our eyes to the possibilities of turning our data processing and web services loose on a commoditized, shared platform.

With a general set of requirements in hand, we set forth, and what we came away with has been incubating, gestating and flowering into a powerful toolset that has met all our expectations, and then some.

Our first task was to choose the core set of technologies and the basic processing scheme that we would be using.  After an exhaustive search, lots of hacking and whiteboard scribblings, we settled on the following key features:

  • Python for all application code
  • AMQP, via RabbitMQ, for all inter-process communication
  • MySQL, Tokyo Tyrant and memcache for data storage services
  • Protocol translators to bridge external traffic to AMQP via a simple binary protocol
  • libevent for as many as IO operation as possible

We chose Python from the suitable dyanmic languages primarily for its memory management and speed.  We were shifting to a single-threaded multi-process environment where memory costs are high and performance paramount, and Python has an extensive pedigree in this area.  We did choose to sacrifice some memory by adhering to a single-threaded model in order to keep the application stack simple and use the kernel for all context switching.

AMQP’s routing scheme gives us powerful tools to shard and aggregate traffic across our cluster.  We chose RabbitMQ because of its Erlang heritage, its performance, reliability, clustering capabilities and commercial support.  By splitting up each game’s services into discrete packages which can each run numerous instances, we can readily divide traffic across a cluster of RabbitMQ hosts and attach listeners for monitoring, diagnostics and metrics.  The dotted-notation of AMQP’s topic exchanges allow for routing traffic between titles, environments, services and even specific commands.

To get the most out of the kernel and reduce latency, we use libevent for all of our AMQP traffic and in our protocol translators.  We extensively patched the py-amqplib to work within this asynchronous environment.  This fork has been in production use for some time now but is slated for a ground-up re-write and release into the wild.

We considered many other database solutions, but at the time that we had to make our decision, felt that Tokyo Tyrant was the best NoSQL database to introduce into our stack because of its sparse table capabilities, high performance, low resource usage and simple setup.  We’re very excited with all the new development that is taking place in this field, and will be writing more about our experience with these tools over the coming years.

What we ended up with has met all of the goals that we set out to achieve.  We have successfully abstracted scaling, monitoring, protocol presentation and metric aggregation, allowing us to focus entirely on delivering functionality to our customers.  Now that our customers include MLG, this means that we’ll be rolling out some of the biggest and baddest applications in the gaming community, with confidence and reliability.
  • Reddit
  • Digg
  • del.icio.us
  • Facebook
  • Tumblr
  • Twitter

Mocking HTTP request and response with Python and Mox

by David Czarnecki, October 1st, 2009 at 09:55am - No Comments »
Tagged As: , , , , ,
Posted in: Engineering, Python, Uncategorized

I recently started integrating with some web services in Python and wanted to be able to test all the requests and responses with valid and invalid data. However, I need to be able to do this without actually hitting the web service when testing. And of course I don’t want to change my web service code to conditionally do things if running in a test environment. Enter mocking and Mox.

One of our engineers, Tim, has written an excellent post on his adventures as a Ruby programmer getting up to speed on testing and mocking in Python using Mox. You should read it.

Back to my issue with mocking the HTTP request and response.

Here is what I came up with. I first created a MockResponse class that adds a read() method to the string class.

</code>

class MockResponse(str):
'''
Mock response class with a method called read which will be used similar to the response from an HTTP request to a URL
'''
def read(self):
return self

And here is a test in which I mock out the request and response for the urllib2.OpenerDirector.open method. I don't so much care what the request string is passed to the open call, so I use IgnoreArg(). And I return the XML that would be returned by the actual web service to indicate the username and/or password were incorrect.


def test_logging_in_to_network_with_bad_username_and_password(self):
my_network_service = MyNetworkService('foo', 'bar')
self.mock(urllib2.OpenerDirector, 'open')
urllib2.OpenerDirector.open(mox.IgnoreArg()).AndReturn(MockResponse('''
< ?xml version="1.0" encoding="UTF-8"?>
<login>
<status>
<id>30000</id>
<message>ACCT_LOGIN_FAILED</message>
</status>
<accountid>7</accountid>
</login>
'''))
self.replay_all()

self.assertEqual(False, my_network_service.login())
self.mox.UnsetStubs()
self.mox.VerifyAll()

If there's a better way, I'd love to hear your suggestions.

  • Reddit
  • Digg
  • del.icio.us
  • Facebook
  • Tumblr
  • Twitter

Suh-weet

by Brian Corrigan, March 22nd, 2009 at 10:12am - No Comments »
Tagged As:
Posted in: Python

One of our engineers has been doing some work with RRDTool (Round Robin Database); and more specifically PYRRD.  He’s using it to combine real time usage stats with a prediction algorithm so that we can pre-emptively allocate resources to different parts of the system.  Its real spiffy.

His additions to the PYRRD library just got commited to the trunk build, and he’s credited in the readme.

http://code.google.com/p/pyrrd/source/browse/trunk/ChangeLog
http://code.google.com/p/pyrrd/source/browse/trunk/README

  • Reddit
  • Digg
  • del.icio.us
  • Facebook
  • Tumblr
  • Twitter

Python Is Mocking Me: A Ruby Programmer’s Adventures With Python/Mox

by Tim Jones, February 23rd, 2009 at 01:16pm - 7 Comments »
Posted in: Engineering, Python, Uncategorized

Overview

Much of Agora’s work over the last few years has been done in Ruby. Recently though, we’re migrating major components to Python in order to enjoy the benefits of cross platform compatibility with Windows. The purpose of this post is to discuss testing in Python; specifically mocking.
(more…)

  • Reddit
  • Digg
  • del.icio.us
  • Facebook
  • Tumblr
  • Twitter