<?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>webr3.org &#187; ram</title>
	<atom:link href="http://webr3.org/blog/tag/ram/feed/" rel="self" type="application/rss+xml" />
	<link>http://webr3.org/blog</link>
	<description>brain&#039;s on fire!</description>
	<lastBuildDate>Tue, 19 Jul 2011 15:38:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Speeding up Apache2 and MySQL5 the easy way.</title>
		<link>http://webr3.org/blog/optimization/speeding-up-apache2-and-mysql5-the-easy-way/</link>
		<comments>http://webr3.org/blog/optimization/speeding-up-apache2-and-mysql5-the-easy-way/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 22:28:14 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[backend db server]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[HTTP persistent connection]]></category>
		<category><![CDATA[Hypertext Transfer Protocol]]></category>
		<category><![CDATA[Keepalive]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=85</guid>
		<description><![CDATA[One of the sites I manage is what I'd would call a high traffic website, traffic sits around 900 requests a second all day and peaks around 3500 a second in rush hour (when the new stories for the day are published each morning). Nearer 6000 per second at peak.
Skippable Details
All this traffic is round [...]]]></description>
			<content:encoded><![CDATA[<p>One of the sites I manage is what I'd would call a high traffic website, traffic sits around 900 requests a second all day and peaks around 3500 a second in rush hour (when the new stories for the day are published each morning). Nearer 6000 per second at peak.</p>
<h3>Skippable Details</h3>
<p>All this traffic is round robin'd to 2 apache2 servers (each is 2x 2.86 quad xeons w/ 4GB ram) and one backend db server of similar spec.</p>
<p>Over the years familiar problems rear there heads, the mysql "Too Many Connections" error, Apache running like a dog under stress etc.</p>
<p>This weekend I got the chance to rebuild the servers from scratch, and a chance to optimize everything - works very very well now!</p>
<h3>Easy Optimization - Apache2</h3>
<p>KeepAliveTimeout: Number of seconds to wait for the next request from the same client on the same connection.</p>
<p>Translate this to "Number of seconds to lock up a worker thread just incase another request comes in from the same client on the same connection" - in short a lot of browsers will request the page, keep the connection alive and use it to request images, css etc.</p>
<p>The default is 15 seconds; in my experience about 40-50% of connections will use KeepAlive, so if you have enough ram to support 500 requests before going in to swap memory, and you get 500 requests a second, by the time 3 seconds are past you've got a load of workers with RAM assigned doing nothing and all the hard work is getting done using swap memory instead, from this poitn on basically all the hard work is getting done using swap rather than ram, ya?</p>
<p>Thus, the simple fix is to knock KeepAliveTimeout right down - some people recommend 2 seconds, my personal preference is 4 seconds - works a charm for me :)</p>
<p>To analyse this yourself just check the server-status provided by apache (normally only viewable from localhost, easy way around this is to &lt;?php echo file_get_contents('http://localhost/server-status'); ?&gt;</p>
<h3>Easy Optimization - MySQL Server</h3>
<p>Other than the normal cnf values you should be optimizing [ key_buffer, sort_buffer_size, max_allowed_packet, thread_stack, thread_cache_size, max_connections, table_cache, query_cache_limit, query_cache_size ] - there is one more that is very important; namely wait_timeout.</p>
<p>wait_timeout - The number of seconds the server waits for activity on a noninteractive connection before closing it.</p>
<p>By default this value is very high, but often you get connections that just aren't closed properly, especially in the PHP apache world - if you ever hit that "Too many connections" error or see a lot of connections open for prolonged periods of time then this could / should be addressed.</p>
<p>Often you will see connections sitting idle for 10-15 seconds, for no good reason. Best to address it I'd say; and thus we lower wait_timeout to 5 seconds.</p>
<p>Connections are cleared faster, more resources free for other connections and all round its good. Remember one of mysql's strongest features is it's ability to open and close connections ultra-fast.</p>
<h3>Summary</h3>
<p>Honestly just check the your apache server status, see how many connections are open, how many of them are flagged K for keep alive then drop the keep alive time, take a note of processor usage / memory usage, drop the KeepAliveTimeout to 2, 4, 6, 8 and check it all again, you may be very suprised, it sure beats weeks of manual code optimizatios to make those scripts run faster.</p>
<p>Regards</p>
<p><img class="alignnone size-full wp-image-86" title="top" src="http://webr3.org/blog/wp-content/uploads/2009/07/top.jpg" alt="top" width="600" height="250" /></p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/optimization/speeding-up-apache2-and-mysql5-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Something about practical usage of flash.Memory in HaXe</title>
		<link>http://webr3.org/blog/haxe/something-about-practical-usage-of-flash-memory-in-haxe/</link>
		<comments>http://webr3.org/blog/haxe/something-about-practical-usage-of-flash-memory-in-haxe/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 17:17:18 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[3D computer graphics]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Fast Memory]]></category>
		<category><![CDATA[flash player]]></category>
		<category><![CDATA[Integer]]></category>
		<category><![CDATA[Lookup table]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=79</guid>
		<description><![CDATA[It's dawned on me that I've completely negated to mention why the haXe implementation of flash.Memory (flash player 10's new opcodes / fastmemory support) is so good.
Other than the really obvious bit that its direct access to a block of ram/fast memory which works extremely quickly, there is one other small but vital detail that's [...]]]></description>
			<content:encoded><![CDATA[<p>It's dawned on me that I've completely negated to mention why the haXe implementation of flash.Memory (flash player 10's new opcodes / fastmemory support) is so good.</p>
<p>Other than the really obvious bit that its direct access to a block of ram/fast memory which works extremely quickly, there is one other small but vital detail that's haXe specific and makes a vast difference between alchemy and haxe.</p>
<h2>The Big Difference</h2>
<p>You can think of flash.Memory as a static ByteArray, thus it is accessible from <em>both</em> static class and instance methods.</p>
<p>Now, another feature which offers huge speed increases in haXe is inlining.</p>
<p>Spelling it out - You can only inline static private methods, flash.Memory is all static access. So stick all your data (or big chunks of it) in flash.Memory and then inline  most of your heavy number crunching class.</p>
<p><strong>All inlined, all using fast memory = very very quick swfs!</strong></p>
<h2>Ideas and Tricks</h2>
<p>First of all, get the thought of only being able to have one chunk or type of data in fast memory at a time, you can partition it up and load everything in there.</p>
<p>A common setup I use is to have the first 1024 bytes as fast storage for float, int, byte, uint variables, the next xxx-thousand bytes as raw bitmap data, then all the other data I may want - like a block of 500k x,y,z floats for 3d data, followed by a few lookup charts.</p>
<p>the first 1024 bytes as fast storage for float, int, byte, uint variables - <em>because</em> you can then access the most commonly used vars using small int offsets (0-255) - and since its a small int your using it avoids all stacks completely, the bytecode will only contain the opcode to get the value from fast memory followed by the offset actually in the bytecode - for anything 256 and over its going to hit the int stack to get the offset first (which is barely noticable, but you know every fraction counts)</p>
<p>the next xxx-thousand bytes as raw bitmap data - <em>because </em>you can then work on your bitmap data ultra fast and write it back to the BitmapData instance using setPixels; very fast indeed, faster than a fixed sized vector even.</p>
<p>then all the other data - this is partially obvious, what may not be is the use of lookup charts, but I'll cover that in a moment.</p>
<h3>Accessing..</h3>
<p>Remember flash.Memory differs from a byte array in that you have to add in the offset for each value you want to grab</p>
<ul>
<li>Byte = 1 Byte</li>
<li>Int = 4 Bytes</li>
<li>Float = 4 Bytes</li>
<li>Double = 8 Bytes</li>
</ul>
<p>To use flash.Memory with functions which require a ByteArray.. [ like BitmapData.getPixels() -  Sound.extract() ] .. you can access it directly from flash.system.ApplicationDomain.currentDomain.domainMemory for example:</p>
<pre>// set position to start of the data we need
flash.system.ApplicationDomain.currentDomain.domainMemory.position = SOME_OFFSET;
// use the fast memory
bitmapData.setPixels( bitmapData.rect , flash.system.ApplicationDomain.currentDomain.domainMemory );</pre>
<p><strong>note:</strong> don't be fooled though, you can't simply call the functions on the bytearray in currentDomain, although <em>it is the data</em> that is in fast memory, it does not use the opcodes, which are what speed it up!</p>
<p><strong>Lookup Charts</strong></p>
<p>Often you'll find yourself calling the same code over and over and over; perhaps without realising just how much; consider we make an animation which uses perlin noise to generate 2d or 3d data - like this example - the example reads about 40k uint values from perlin noise, then converts each pixel to individual r,g,b values, then turns it in to a float -1 to 1 using a simple calculation. Thing is.. that means the same calculation runs 3x40000 times per frame at 50 frames a second.. 6 million times a second!</p>
<p>In this scenario, there are only 256 possible inputs to the calculation and 256 results - so rather than working it out 6 million times we can load it all in to a lookup chart, stick the lookup chart in fast memory and then lookup values rather than calculating - often you can really speed things up by doing this. <a href="http://webr3.org/experiments/perlin-particles/light-cloud/PerlinParticleEffects.hx">Practical example with comments here</a>.</p>
<p>Hope this is of use to somebody and clears things up a bit; I use the methods often so you'll see them in the source of my experiments.</p>
<p><img class="alignnone size-full wp-image-80" title="nopic" src="http://webr3.org/blog/wp-content/uploads/2009/07/nopic.jpg" alt="nopic" width="600" height="250" /></p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/haxe/something-about-practical-usage-of-flash-memory-in-haxe/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

