<?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>Mozilla Web Development &#187; Graph Server</title>
	<atom:link href="http://blog.mozilla.com/webdev/category/graph-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mozilla.com/webdev</link>
	<description>Everybody Likes Ninjas</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:50:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Native JSON in Firefox 3.1</title>
		<link>http://blog.mozilla.com/webdev/2009/02/12/native-json-in-firefox-31/</link>
		<comments>http://blog.mozilla.com/webdev/2009/02/12/native-json-in-firefox-31/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 17:28:42 +0000</pubDate>
		<dc:creator>rdoherty</dc:creator>
				<category><![CDATA[Graph Server]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/webdev/?p=222</guid>
		<description><![CDATA[In case you haven&#8217;t heard, one of Firefox 3.1&#8217;s awesome new features will be native JSON support. This is totally sweet for two reasons:

eval&#8217;ing JSON in the browser is unsafe. Using native JSON parsing protects you against possible code execution.
Safely eval&#8217;ing JSON with a 3rd party library can be orders of magnitude slower. Native JSON [...]]]></description>
			<content:encoded><![CDATA[<p>In case you haven&#8217;t heard, one of Firefox 3.1&#8217;s awesome new features will be <a href="https://developer.mozilla.org/En/Using_JSON_in_Firefox">native JSON</a> support. This is totally sweet for two reasons:</p>
<ol>
<li>eval&#8217;ing JSON in the browser is <a href="http://yuiblog.com/blog/2007/04/10/json-and-browser-security/">unsafe</a>. Using native JSON parsing protects you against possible code execution.</li>
<li>Safely eval&#8217;ing JSON with a 3rd party library can be orders of magnitude <a href="http://starkravingfinkle.org/blog/2008/02/extension-developers-native-json-parsing/">slower</a>. Native JSON parsing is much faster.</li>
</ol>
<p>How does native JSON work compared to plain old eval? Simple:</p>
<pre>var jsonString = '{"name":"Ryan", "address":"Mountain View, CA"}';
var person = JSON.parse(jsonString);
// 'person' is now a JavaScript object with 2 properties; name and address</pre>
<p>Pretty easy huh? And here&#8217;s how to get a JSON string from an object:</p>
<pre>var personString = JSON.stringify(person);
// 'personString' now holds the string '{"name":"Ryan", "address":"Mountain View, CA"}'</pre>
<p>&#8220;But wait!&#8221;, you say. &#8220;How is it safer? How much faster is it compared to eval?&#8221;. Ok, I&#8217;ll show you.</p>
<p>Native JSON parsing in Firefox 3.1 is safer because it does not support objects with functions. Attempting to convert an object with functions into a JSON string will only convert its properties and not its functions. And any malformed JSON string will result in a parse error instead of possible code execution.</p>
<p>Now, regarding speed, native JSON parsing is faster, <strong>much</strong> faster. Instead of pretty charts and graphs, I&#8217;ll give you a real-world example.</p>
<p>The <a href="http://graphs-stage2.mozilla.org/graph.html">new Graph Server</a> uses a JSON API to fetch test information and results, so I figured it would be a good application to benchmark. So I wrapped our code that parses the JSON response with some Firebug profiler calls:</p>
<pre>    console.time('parsejson');
    var obj = eval('(' + resp + ')');
    console.timeEnd('parsejson');</pre>
<p>Loading a test&#8217;s results (array with 3,000 indexes, 24k gzipped) gave me a time of 125ms. (Repeated tests yielded results +/- 5ms). Then I changed eval to JSON.parse:</p>
<pre>    console.time('parsejson');
    var obj = JSON.parse(resp);
    console.timeEnd('parsejson');</pre>
<p>Which resulted in an average time of 40ms! That&#8217;s about 2.7 times faster with 1 line of code changed. Not bad!</p>
<p>Granted, a difference of 80ms isn&#8217;t that much, but in an AJAX (or, more accurately, AJAJ?) application, it can add up.</p>
<p>What&#8217;s the use of native JSON if it&#8217;s only available in Firefox? Luckily, IE8 has implemented it in RC1, which is rumored to be released in March. Hopefully other browsers will follow suit too, but for now it&#8217;s best to use a JSON parser such as the one on <a href="http://www.json.org/js.html">json.org</a>. It&#8217;s small, safe and will not override native JSON implementation if detected.</p>
<p>Points to remember:</p>
<ul>
<li>Plain old eval is unsafe (especially if you don&#8217;t trust the source), use a JSON library to protect yourself.</li>
<li>Use native JSON when available.</li>
<li>Bug other <a href="http://webkit.org/">browser</a> <a href="http://www.opera.com/">vendors</a> to implement native JSON</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/webdev/2009/02/12/native-json-in-firefox-31/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Graph Server Re-Write</title>
		<link>http://blog.mozilla.com/webdev/2009/02/06/graph-server-rewrite/</link>
		<comments>http://blog.mozilla.com/webdev/2009/02/06/graph-server-rewrite/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 18:12:24 +0000</pubDate>
		<dc:creator>rdoherty</dc:creator>
				<category><![CDATA[Graph Server]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/webdev/?p=204</guid>
		<description><![CDATA[Over the past few months the Graph Server team and I have been hard at work re-writing the back end for the Graph Server and it&#8217;s finally come to fruition. 
For those that don&#8217;t know, the Graph Server is used to display performance test data of Firefox builds reported by Talos.

Our work initially started as [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past few months the <a href="https://wiki.mozilla.org/Perfomatic#People">Graph Server team</a> and I have been hard at work re-writing the back end for the <a href="http://graphs.mozilla.org">Graph Server</a> and it&#8217;s finally come to fruition. </p>
<p>For those that don&#8217;t know, the Graph Server is used to display performance test data of Firefox builds reported by <a href="https://wiki.mozilla.org/Buildbot/Talos">Talos</a>.</p>
<p><img src="http://people.mozilla.org/~rdoherty/graph-server.jpg" width="450" height="317" alt="Graph Server screenshot" /></p>
<p>Our work initially started as performance improvements and some new features, but the more we worked with the old architecture, it became quite apparent it would not scale (performance and feature-wise). </p>
<p>The old database schema duplicated test data in multiple tables and stored similar, but different data in the same tables. Tables had ballooned to millions (and billions) of rows that were queried for basic information such as all unique test names, resulting in queries that ran forever. And the queries that did finish were looped over in JavaScript to pull out test information, resulting in the browser locking up because it was looping over hundreds of thousands of rows.</p>
<p>If it&#8217;s not clear already, one of main issues was with the database schema; it needed to be normalized.</p>
<p>Here&#8217;s the old, non-normalized schema:</p>
<p><a href="http://people.mozilla.org/~rdoherty/old-schema.png"><img src="http://people.mozilla.org/~rdoherty/old-schema-small.gif" width="450" height="199" alt="Old Graph Server schema" /></a></p>
<p>And here&#8217;s the new, normalized schema after the team was locked in a room for an afternoon:</p>
<p><a href="https://wiki.mozilla.org/images/d/d2/Graph_server_new_db_schema2.png"><img src="http://people.mozilla.org/~rdoherty/graph-server-new.jpg" width="450" height="294" alt="New Graph Server schema" /></a></p>
<p><strong>Much</strong> cleaner, no duplicated data, easy to understand the various machines, branches and tests that are used for displaying test data. No need look at entire tables to find basic information such as test names.</p>
<p>With this new schema in place, it also required a re-write of our server-side scripts we use to fetch test information for the front end graphing component. Since Mozilla is as open as possible, instead of just changing what was needed, I decided to implement a <a href="https://wiki.mozilla.org/Perfomatic:API">JSON API</a> that would allow anyone to easily retrieve test data.</p>
<p>Lastly, our Talos <--> Graph Server communication needed to be re-written. Lars rewrote the collector script that accepts values from Talos and Alice rewrote the pieces of Talos that send data to the Graph Server.</p>
<p>After all that work, we now have a <a href="http://graphs-stage2.mozilla.org/graph.html">working stage server</a> (Firefox 3.1 or higher required due to native JSON requirement) with our new code. We have a bit more testing and some performance benchmarking to do before it goes live, but we&#8217;re happy that all the pieces are working. </p>
<p>Want to know more? We have a wiki page with more information at <a href="https://wiki.mozilla.org/Perfomatic#Rearchitecture">https://wiki.mozilla.org/Perfomatic#Rearchitecture</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/webdev/2009/02/06/graph-server-rewrite/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
