<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Adam Frisby &#187; UGAIM</title>
	<atom:link href="http://www.adamfrisby.com/blog/tag/ugaim/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adamfrisby.com/blog</link>
	<description>ZOMGWTFHAI</description>
	<lastBuildDate>Sat, 26 Dec 2009 07:02:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Inside the Asset Server</title>
		<link>http://www.adamfrisby.com/blog/2009/07/inside-the-asset-server/</link>
		<comments>http://www.adamfrisby.com/blog/2009/07/inside-the-asset-server/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 09:43:27 +0000</pubDate>
		<dc:creator>Adam Frisby</dc:creator>
				<category><![CDATA[OSGrid]]></category>
		<category><![CDATA[OpenSim]]></category>
		<category><![CDATA[assets]]></category>
		<category><![CDATA[fragstore]]></category>
		<category><![CDATA[inventory]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[second life]]></category>
		<category><![CDATA[UGAIM]]></category>

		<guid isPermaLink="false">http://www.adamfrisby.com/blog/?p=379</guid>
		<description><![CDATA[The single most misunderstood bit of technology in both OpenSim and Second Life is the thing called the asset server; while my understanding of the backend of Second Life&#8217;s asset cluster is limited (Squid+Isilon AFAIK) &#8211; my understanding of OpenSim&#8217;s is fairly comprehensive.
Let&#8217;s start with the basics &#8211; the asset server is a gigantic document [...]]]></description>
			<content:encoded><![CDATA[<p>The single most misunderstood bit of technology in both OpenSim and Second Life is the thing called the asset server; while my understanding of the backend of Second Life&#8217;s asset cluster is limited <em>(<a href="http://www.squid-cache.org/">Squid</a>+<a href="http://www.isilon.com/">Isilon</a> AFAIK)</em> &#8211; my understanding of OpenSim&#8217;s is fairly comprehensive.</p>
<p>Let&#8217;s start with the basics &#8211; the asset server is a gigantic document storage server. In our cases, documents are things such as primitives, textures, sounds, avatars &#8211; the works.</p>
<p>Each document is referred to by a specific unique filename called a UUID &#8211; which is  a 128-bit number (think 3 with 38 zeros behind it &#8211; big number) &#8211; a UUID looks something like this &#8220;d61c1990-79b9-11de-8a39-0800200c9a66&#8243; when represented in hexadecimal notation. You have probably seen them around a lot &#8211; just using OpenSim or Second Life.</p>
<p>A UUID is an excellent choice for a filename; because you can make them up randomly and statistically guaruntee it hasnt been used before (the chance of a UUID duplicate for a good random UUID is about <a href="http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Random_UUID_probability_of_duplicates">1 in a very very very <em>very</em> large number</a>). This means you can have multiple asset servers on the one grid &#8211; each upload can be given an ID randomly, without the need for a central authority to give them out.</p>
<p>They also optimize extremely well &#8211; each &#8220;bit&#8221; is a single yes or no question; to find out exactly where an asset is located, you can play a game of 20 questions, but in this case, with 128 bits &#8211; you can ask 128 questions. For example; finding which server an asset is located on, in a server farm with 4 machines (labelled 1,2,3 &amp; 4) could be found with the following question chain&#8230;</p>
<ol>
<li>Is the asset on a server labelled closer to 4 than 1? (yes &#8211; servers 3,4 still possibilities)</li>
<li>Is the asset on an odd numbered server? (yes &#8211; located on server 3)</li>
</ol>
<p>Asset found on server #3. It&#8217;s not very long is it? Even with say 300 servers; you can find the answer within 9 questions. Some further searching is needed to be done to locate the asset on the physical disk itself; but even then you will be asking a very small number of questions &#8211; far less than the maximum 128 allowed.</p>
<p>To put this into a diagram, fetching an asset directly by it&#8217;s indexed UUID is equivilent to something like this:</p>
<div id="attachment_381" class="wp-caption alignnone" style="width: 653px"><img class="size-full wp-image-381" title="Fetching an Asset" src="http://www.adamfrisby.com/blog/wp-content/uploads/assetfetch.png" alt="Fig 1. How asset UUIDs divide and conquer" width="643" height="525" /><p class="wp-caption-text">Fig 1. How asset UUIDs divide and conquer</p></div>
<p>Given that computers are capable of asking and answering questions very very quickly (several billion per second); and that none of the above questions require a central server; you can expand your asset server farm in a fairly linear fashion without scaling constraints; providing that you structure your data appropriately.</p>
<p>128 questions also means that you can define very very precise questions; so many that if you created 100 trillion assets every second; the sun would be lifeless before you ran out of address space that can be answered by that many questions. (Although a piece of statistical mathematics called the <a href="http://en.wikipedia.org/wiki/Birthday_Paradox">Birthday Paradox</a> does make the address space significantly less usable the closer you get to that point &#8211; but for other reasons)</p>
<p>At this point, we know how assets are stored and retrieved &#8211; files are uploaded into the server farm, and given a UUID; that UUID can be used to find out where the asset is located precisely, and return the data later. However, when you access an item off the asset server; there&#8217;s only a modest chance you are accessing the asset by it&#8217;s UUID directly.</p>
<p>A lot of the time, you will be accessing the asset through a layer of redirection called the Inventory Server &#8211; if you have a texture within your inventory; there are actually two components; the first component is the data itself (the asset), and the second component is the inventory shell (uploader, time uploaded, permissions, reference to the asset, etc). When you lose an item of inventory (such as during a transaction); it is often not the asset servers fault, but instead the inventory server.</p>
<p>The inventory server exists so that if you give a copy of a texture to a friend; you and that friend do not make a duplicate copy of the heavier portion (the asset) &#8211; both inventory items, yours and your friends will have the same underlying asset ID. This also means that copying an item within your inventory will not prevent it from being saved during a asset glitch (as both point at the same data).</p>
<p>In Second Life®, the inventory server is using MySQL (and <em>probably</em> InnoDB), and the asset server uses IsilonFS (a custom hardware appliance based system.); in OpenSim this will vary a lot depending on the providers configuration &#8211; most grids use a SQL backend for storing both assets and inventory. By default, OpenSim will use a small embedded database for both Inventory and Assets &#8211; called SQLite. For grids, we recommend something more robust.</p>
<p>In grid mode, MySQL is still an appropriate solution for Inventory; however asset data will often exceed the normal operating tolerances of MySQL and lead to frequent table corruption, table locking issues (which in turn make performance suck) and other nasties. No large grid should be using MySQL for assets (small home and private grids are however fine.)</p>
<p>Grids such as ReactionGrid which use MS-SQL can get a bit further than MySQL when storing asset data (for inventory they are fundementally the same); MS-SQL like most <em>sane </em>database engines, store BLOB data seperately in a BSP-Tree indexed system; this means they can scale up pretty far (although at about the point of clustering, things degrade.); Postgres can do the same &#8211; however as best I am aware, Postgres is not yet properly supported in OpenSim.</p>
<p>For bigger grids like OSGrid (where we have hundreds of gigabytes of assets) a dedicated solution is ideal &#8211; unlike Second Life, we cant afford to purchase high end NAS-equipment for our storage solutions; so we have built a distributed system called Fragstore which has two big features.</p>
<ol>
<li> A configurable backend &#8211; it can use distributed storage systems (such as Project Voldemort or Hadoop), or export to a filesystem (which can be a distributed filesystem via projects like KosmosFS.)</li>
<li>A duplicate detection system &#8211; so files uploaded twice only get stored once.</li>
</ol>
<p>The duplicate detection is achieved via a secondary layer of indirection; when we allocate a UUID, we hash the incoming data (256-bit SHA1) and store the UUID and the Hash into a small database table (currently MySQL based); when we recieve future uploads; if the hash matches, the result is only stored once on disk.</p>
<p>The final point I would like to touch on is asset transmission and security &#8211; assets are transmitted in both SL and OpenSim over HTTP; the reason this works and is secure is because the UUIDs used in the requests are unguessable. Even by a computer making millions of guesses per second; the chance of hitting a valid address is very very small (same probability as generating a duplicate UUID).</p>
<p>From the asset server to the region server, the request is something in the form of http://assetserver.com/&lt;uuid&gt;/data &#8211; which will return the asset in a encoded container (usually packaging a little bit more information about the asset such as the content type, etc.) &#8211; using /metadata instead of /data will get you a JSON-encoded package with a bit more information about the asset (creation date, specific asset type, etc.)</p>
<p>From the region servers to the users &#8211; this transmission can vary a little. In both SL and OpenSim, the region servers act as proxy caches for the asset server; because assets cannot be updated (and instead are replaced) &#8211; this works fairly well. If twenty users in a region see a texture &#8211; it only needs to be fetched off the core asset service once; because the region will send it twenty times to the users; rather than twenty users hitting the core server.</p>
<p>In the case of OSGrid, this means we have 2,500+ reverse proxies sitting infront of the asset server (albeit in a somewhat suboptimal layout.); it reduces the bandwidth on the core asset server by approximately 90%+ (<a href="http://assets.osgrid.org/stats/">you can see our asset stats here</a>); which means we can get away with much lower operating costs (since asset delivery costs are shared with region operators).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamfrisby.com/blog/2009/07/inside-the-asset-server/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
