Disclaimer: This is probably a bad idea in motion, I make no claims as to how well this could hold up in the long run or real world - I have some personal concerns about how Amazon is able to scale their S3 service effectively, and the recent downtime should give cause to think first before putting this into production.
If you want to be a cool geek these days, you absolutely have to insert the words ‘cloud computing’ into every other sentence. It’s no suprise then that one of the more adopted and interesting toys in the last year or two has been the Amazon Simple Storage Service (S3 for short).
It’s a “cloud” based storage solution, where you can upload files onto the cloud relatively cheaply. It’s being used in places Akamai used to be used for mirroring and proxying of frequently accessed files. (Even Linden Lab uses it for distrobuting their updates.)
The price is right, and the solution is fully programmable via a convenient web API, so it’s snuck itself into all sorts of places. What I’d like to experiment here is using it as a complete grid asset server, for those who havnt toyed much with the OpenSim asset server under the hood - it’s effectively a webserver with two supported operations: “PUT” and “GET” - funnily enough this overlaps nicely with any network accessible storage system, S3 included.
Building a new asset storage module from scratch
First thing we need to do is go hunting for another asset storage module in OpenSim so we can take a look at the interface we are required to implement. After a quick hunt for “asset_database” (the OpenSim.ini setting) it turns up that we need to create a class that derives from AssetServerBase which in turn derives from IAssetServer.
This looks relatively painless so far, we need to make a class which implements all five of these functions. The next step is to go take a look around and see if there is a decent .NET library for interfacing with S3. Turns out there is - .NET S3. (Post-authoring note: Apparently Amazon have an official library which looks easier to use, for one it doesn’t require the delegate hackery seen in the GetAsset function)
This library, while not fantastically documented does seem to do the job quickly and easily.
Implementing the asset client
Now we are at the point where we can actually write our class, using the above library, I’ve skipped ahead and written the class as presented below:
As you can see, the meat of the function sits in the StoreAsset and GetAsset functions, in this case we’ve overridden them to save to an EC2 Bucket (”directory”). We’ve made the directory a parameter of the constructor, as long as each region on the “grid” uses the same directory, they will act as one giant asset database.
Final Steps: Hooking it up
If we head back to OpenSimBase.cs where we first went looking for “m_assetStorage” originally, on line 412 we see:
Below this, let’s add a new statement
Now, if we change the ini setting to read “s3″ our brand spanking new S3 client should fire up.
In Conclusion
I need to make some notes here, first hard coding classes like the above is a bad idea. We shouldnt be doing it for the grid asset server (and instead should be loading a class via reflection). Second we shouldnt be hard-coding the login keys - moving that up to an ini setting is preffered (and not too difficult to do properly). Third this is a untested bit of code, use it at your own risk, this was done as an experiment in approximately 45 minutes.
However, for all the above warts - this shows off the power of OpenSim for rapid prototyping, one of the great features of OpenSim is just how flexible it can be, and how little work is needed to do something completely crazy with it quickly and relatively easily.
Tags: amazon, assets, code, OpenSim, prototyping, s3, storage


7 Responses to “Prototyping with OpenSim: Testing out Amazon S3 as a Grid-Mode Asset Server”
I a not sure about others but the idea is there i just hope it won’t be using amazon’s s3 service. It may just be the path from Australia to S3 but this services is one of the slowest download point i have had to use.
The idea is great but we need a system such as the mentioned Akamai that will be a much better solution with local mirrors in Australia.
Whatever the interop solution involves it must take into consideration the geographically sparse user base!
Commendations for attacking the issue
i might try this out on a local grid server 
By norgan on Jul 25, 2008
Very nice Adam, though I’m not sure i’d want to be the one paying for the S3 storage if it was hooked up to a real grid
Have you thought about using SVN for a grid mode asset server ? The performance might suck but it would allow you to roll back individual assets etc.
By Rob Smart on Jul 25, 2008
Kewl! Have you thought at all about / played with using, say, a server from Amazon’s EC2 as the compute box for a region? Just to be ultimately cloudy.
Any changes likely to be required for that?
By Dale Innis on Jul 25, 2008
We’ve thought about (and implemented code) to host regions on EC2 in the past. (Might be something I discuss later)
However, this little module would complement them nicely, since S3 has exceptionally fast access to EC2 and vice versa - and it means you have one less server you need to run.
By Adam Frisby on Jul 25, 2008