<?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>Julius Beckmann &#187; MySQL</title>
	<atom:link href="http://juliusbeckmann.de/blog/category/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://juliusbeckmann.de/blog</link>
	<description>Ich bin nicht verrückt, nur technisch begabt ...</description>
	<lastBuildDate>Wed, 05 Jun 2013 11:02:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL: Save RAM by disabling InnoDB</title>
		<link>http://juliusbeckmann.de/blog/mysql-save-ram-by-disabling-innodb.html</link>
		<comments>http://juliusbeckmann.de/blog/mysql-save-ram-by-disabling-innodb.html#comments</comments>
		<pubDate>Wed, 24 Nov 2010 20:50:41 +0000</pubDate>
		<dc:creator>Julius</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[InnoDB]]></category>
		<category><![CDATA[OpenVZ]]></category>
		<category><![CDATA[RAM]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Tipp]]></category>
		<category><![CDATA[VServer]]></category>

		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=617</guid>
		<description><![CDATA[If you run a MySQL Server and have not much RAM, like in a OpenVZ Container or VirtualServer, there is some saving possibility by disabling InnoDB in your my.cnf. By default InnoDB Engine is enabled and uses about 100MB of RAM. You can disable InnoDB in your /etc/mysql/my.cnf with the keyword "skip-innodb". But check first [...]]]></description>
			<content:encoded><![CDATA[<p>If you run a MySQL Server and have not much RAM, like in a OpenVZ Container or VirtualServer, there is some saving possibility by disabling InnoDB in your my.cnf.<br />
By default InnoDB Engine is enabled and uses about 100MB of RAM. You can disable InnoDB in your <em>/etc/mysql/my.cnf</em> with the keyword "<strong>skip-innodb</strong>".<br />
But check first if there are any databases with InnoDB Tables in your MySQL Server. They will stop working if you just disable it.</p>
]]></content:encoded>
			<wfw:commentRss>http://juliusbeckmann.de/blog/mysql-save-ram-by-disabling-innodb.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Micro vs. Macro optimization, or &quot;Get the low hanging fruit first&quot;</title>
		<link>http://juliusbeckmann.de/blog/php-micro-vs-macro-optimization-or-get-the-low-hanging-fruit-first.html</link>
		<comments>http://juliusbeckmann.de/blog/php-micro-vs-macro-optimization-or-get-the-low-hanging-fruit-first.html#comments</comments>
		<pubDate>Tue, 16 Feb 2010 12:56:46 +0000</pubDate>
		<dc:creator>Julius</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[fruits]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[micro]]></category>
		<category><![CDATA[optimieren]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=549</guid>
		<description><![CDATA[After using and developing PHP for a few years now, i heard pretty much stuff about optimization, special technice's and other myths and fairy tales. But this article is not about tips or tricks, it is about if this the real key to better performance. Nearly all of us have heard about hints like "static [...]]]></description>
			<content:encoded><![CDATA[<p>After using and developing PHP for a few years now, i heard pretty much stuff about optimization, special technice's and other myths and fairy tales. But this article is not about tips or tricks, it is about if this the real key to better performance.<br />
<span id="more-549"></span><br />
Nearly all of us have heard about hints like "static method calls are faster" or "++$i is faster than $i++". First is wrong, second is true by the way, but more important is the question, does it really perform better in overall?</p>
<p>I would like to categorize the optimization possibility's into micro-optimization and macro-optimization.</p>
<h2>Micro-optimization:</h2>
<p>I already mentioned the ++$i tip. This would be a perfect example for a micro-optimization. Imagine you have a website, just a normal one with a few thousand hits a day. Simple fetching articles from database and formatting/outputting these. Of course you could use ++$i instead of $i++, but what will be the achievement? Lets guess there are about 1000 PHP operations done on a normal page request. About 50 of them could be optimized with ++$i which is guessed 10% faster. </p>
<div class="codesnip-container" >950 + 50 * (1-0.10) = 950 + 45 = 995 calls left.</div>
<p>You saved 5 simple operations, what are about 0,5%. </p>
<p>This might look noticeable at first, but this is only the number of operations, not the real spend time where these 5 calls will not be measurable any more. Every request the PHP parser has to read and parse the PHP file. On every SQL SELECT there is the database overhead which also depends on database server load. Our previous result combined with that knowledge might be ~0.1% at the end. Conclusion: This kind of optimization simply does not make the page significantly  faster.</p>
<h2>Macro-optimization:</h2>
<p>First, this is not about using macros like in C. No simple code substitution. It is the opposite of the micro-optimization. Once again a example with the simple imaginary PHP website. The main menu using JavaScript is generated by a complex SQL query on every request. This whole procedure takes about 10ms (unrealistic i know, but it is _just_ for the example calculation). 9ms for the SQL query and 1 ms PHP. For all of you who do not know why SQL is slower: Because there are sockets / TCP, database-daemon and harddisk access involved.</p>
<p>THIS is the point where we could use a macro-optimization.<br />
Either, we could invest much work and create a different menu system without javascript and faster SQL queries, or we could do it a much easier. </p>
<p>If we have APC for caching (other anything else), we could use the following strategy: </p>
<div class="codesnip-container" >1. Check for a cached result of our SQL query.<br />
2. If yes, skip to 5.<br />
3. We have no cached entry and perform the SQL query now.<br />
4. The result of the query will be saved in our cache for 1 hours.<br />
5. Use the result to generate the menu.</div>
<p>After this optimization that _just_ affect the SQL fetching part, we have a APC cache request that might take ~1 ms. So we reduced our 9ms SQL to 1ms APC. Of course the overall benefit will not be that big, but will be notice- and measurable. But what really makes the point here is, that we need to query only 24 times a day and not on _every_ request.</p>
<h2>Low hanging fruit</h2>
<p><img alt="" src="/blog/files/images/lowapples.png" class="alignright" width="224" height="261" /><br />
After reading about micro and macro optimization, you might understand the meaning of this much better.<br />
There are several ways to optimize, some of them are easy and fast. These are the "low hanging fruit" - easy to pick. This fruits should be always the first thought when it comes to optimizing. Some of them can be found easily with profiling.<br />
I want to give you a few hints for optimizing your PHP (Python, Ruby, ...) application.:</p>
<p>1. Keep an eye on the IO load. The harddisk of the server is mostly the slowest part and should be used only if necessary.</p>
<p>2. Try to avoid complex SQL querys. The database servers are often under heavy load, even if they have some integrated caching, there is still the SQL overhead.</p>
<p>3. Try to store results. If you need to analyse the browser of your clients, do not do this every request, save the needed values in their $_SESSION and check only if the UserAgent has been changed with a simple crc32 hash.</p>
<p>4. Try to cache. If you have parts in your code that are called nearly every request, have the same result and do not change often. Cache them! Some options are: APC, XCache, Memcache, eAccelerator, tmpFS.</p>
<p>5. Try to avoid unnecessary function calls. Try to store the result of that function and use it multiple times.</p>
<h2>High hanging fruit</h2>
<p><img alt="" src="/blog/files/images/tallapples.png" class="alignright" width="224" height="261" /><br />
I do not say you should not use ++$i or static methods. I want to clarify that there are more important parts worth optimizing.<br />
If you write new code, it should always be your aim writing the fastest code possible. Some of these tips floating on the internet might be helpful, but please check if they are true first!<br />
Some tips i tested myself:<br />
1. ++$i is faster than $i++<br />
2. Static methods are not always faster. (<a href="http://www.ingo-schramm.de/blog/archives/4-PHP-Myth-static-function-call-faster-than-instance-function-call.html">source</a>)<br />
3. Relative paths are slower to include than absolute.<br />
4. foreach is fastest for iterating over arrays. (<a href="/blog/php-foreach-vs-while-vs-for-the-loop-battle.html">benchmark</a>)<br />
5. floor and ceil can be replaced bei (int) casts. (<a href="/blog/php-floor-and-ceil-are-slow.html">benchmark</a>)<br />
6. Try to avoid preg_* function if possible. (<a href="/blog/php-do-not-rebuild-preg_-functions.html">benchmark</a>)</p>
<h2>Conclusion</h2>
<p>If you are hungry, profile the tree first, then pick some of the large low hanging fruits.<br />
While coding pick some of the tiny high hanging.<br />
I hope you had fun reading about my point of view.</p>
]]></content:encoded>
			<wfw:commentRss>http://juliusbeckmann.de/blog/php-micro-vs-macro-optimization-or-get-the-low-hanging-fruit-first.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP/MySQL: Warning: mysql_query(): Unable to save result set ...</title>
		<link>http://juliusbeckmann.de/blog/php-mysql-warning-mysql_query-unable-to-save-result-set.html</link>
		<comments>http://juliusbeckmann.de/blog/php-mysql-warning-mysql_query-unable-to-save-result-set.html#comments</comments>
		<pubDate>Mon, 18 Jan 2010 15:08:36 +0000</pubDate>
		<dc:creator>Julius</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Error]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[Solution]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=507</guid>
		<description><![CDATA[Today i found a error in a tiny script i was working on. The error Message looked like this: Warning: mysql_query() [function.mysql-query]: Unable to save result set in /var/www/example.php on line 55 First i found a few hints about repairing or optimizing MySQL tables, but this did not work out. After a few debugging outputs [...]]]></description>
			<content:encoded><![CDATA[<p>Today i found a error in a tiny script i was working on.<br />
The error Message looked like this:</p>
<div class="codesnip-container" >Warning: mysql_query() [function.mysql-query]: Unable to save result set in /var/www/example.php on line 55</div>
<p>First i found a few hints about repairing or optimizing MySQL tables, but this did not work out.<br />
After a few debugging outputs a realized that the query was not properly written.<br />
<span id="more-507"></span><br />
The original query looked like this:</p>
<div class="codesnip-container" >
<div class="sql codesnip" style="font-family:monospace;"><span class="kw1">SELECT</span> id<br />
<span class="kw1">FROM</span> <span class="st0">`table`</span> <br />
<span class="kw1">WHERE</span> <span class="st0">`order`</span> <span class="sy0">&gt;</span><br />
<span class="br0">&#40;</span><br />
&nbsp; <span class="kw1">SELECT</span> <span class="st0">`order`</span> <br />
&nbsp; <span class="kw1">FROM</span> <span class="st0">`table`</span> <br />
&nbsp; <span class="kw1">WHERE</span> active <span class="sy0">=</span> 1<br />
<span class="br0">&#41;</span><br />
<span class="kw1">LIMIT</span> <span class="nu0">1</span>;</div>
</div>
<p>As you can see the query as a non correlated subquery. It worked fine nearly all the time, but only when the subquery returns only zero or one lines. If there are more lines MySQL generates the "Unable to save result set", because `order` cant be bigger then 2 resultvalues at the same time.<br />
The right query looks like this:</p>
<div class="codesnip-container" >
<div class="sql codesnip" style="font-family:monospace;"><span class="kw1">SELECT</span> id<br />
<span class="kw1">FROM</span> <span class="st0">`table`</span> <br />
<span class="kw1">WHERE</span> <span class="st0">`order`</span> <span class="sy0">&gt;</span><br />
<span class="br0">&#40;</span><br />
&nbsp; <span class="kw1">SELECT</span> <span class="st0">`order`</span> <br />
&nbsp; <span class="kw1">FROM</span> <span class="st0">`table`</span> <br />
&nbsp; <span class="kw1">WHERE</span> active <span class="sy0">=</span> 1<br />
&nbsp; <span class="kw1">LIMIT</span> 1<br />
<span class="br0">&#41;</span><br />
<span class="kw1">LIMIT</span> <span class="nu0">1</span>;</div>
</div>
<p>A extra LIMIT 1 makes the deal perfect, and saved a little bit of my day.</p>
]]></content:encoded>
			<wfw:commentRss>http://juliusbeckmann.de/blog/php-mysql-warning-mysql_query-unable-to-save-result-set.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benchmark: APC vs. MySQL MEMORY fetching Speed</title>
		<link>http://juliusbeckmann.de/blog/benchmark-apc-vs-mysql-memory-fetching-speed.html</link>
		<comments>http://juliusbeckmann.de/blog/benchmark-apc-vs-mysql-memory-fetching-speed.html#comments</comments>
		<pubDate>Wed, 02 Sep 2009 15:07:44 +0000</pubDate>
		<dc:creator>Julius</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[APC]]></category>
		<category><![CDATA[Benchmark]]></category>

		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=409</guid>
		<description><![CDATA[I once wrote a article about APC and MySQL MEMORY table caching and found out that APC needs very much memory compared to MySQL MEMORY. Now i did a short benchmark to check out the fetching speed of these two solutions with a interesting result. Script First, the benchmark script: &#60;?php // Simple test script [...]]]></description>
			<content:encoded><![CDATA[<p>I once wrote a article about <a href="/blog/php-apc-oder-mysql-memory-table-fuer-temporaeren-cache.html">APC and MySQL MEMORY table caching</a> and found out that APC needs very much memory compared to MySQL MEMORY. Now i did a short benchmark to check out the fetching speed of these two solutions with a interesting result.<br />
<span id="more-409"></span></p>
<h3>Script</h3>
<p>First, the benchmark script:</p>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="kw2">&lt;?php</span></p>
<p><span class="co1">// Simple test script benchmarking cache access times</span><br />
<span class="co1">// of APC and MySQL MEMORY</span><br />
<span class="co1">// by: Julius Beckmann (juliusbeckmann.de)</span></p>
<p><span class="co1">// Config</span><br />
<span class="re0">$n</span> <span class="sy0">=</span> <span class="nu0">10000</span><span class="sy0">;</span><br />
<span class="re0">$newline</span> <span class="sy0">=</span> <span class="st0">&quot;&lt;br/&gt;<span class="es1">\n</span>&quot;</span><span class="sy0">;</span></p>
<p><span class="co1">// Init benchmark array with $n entrys</span><br />
<span class="re0">$array</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$i</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span><br />
<span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$i</span><span class="sy0">++</span> <span class="sy0">&lt;</span> <span class="re0">$n</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="re0">$array</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <a href="http://www.php.net/rand"><span class="kw3">rand</span></a><span class="br0">&#40;</span>0<span class="sy0">,</span>999999<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw1">echo</span> <span class="st0">&quot;Testarray has &quot;</span><span class="sy0">.</span><a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$array</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot; random integer entrys&quot;</span><span class="sy0">.</span><span class="re0">$newline</span><span class="sy0">;</span></p>
<p>
<span class="co1">// Check direct array access time</span><br />
<span class="re0">$time_start</span> <span class="sy0">=</span> <a href="http://www.php.net/microtime"><span class="kw3">microtime</span></a><span class="br0">&#40;</span><span class="kw4">true</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$i</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span><br />
<span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$i</span> <span class="sy0">&lt;</span> <span class="re0">$n</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="re0">$devnull</span> <span class="sy0">=</span> <span class="re0">$array</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="sy0">++</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="re0">$time_end</span> <span class="sy0">=</span> <a href="http://www.php.net/microtime"><span class="kw3">microtime</span></a><span class="br0">&#40;</span><span class="kw4">true</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$time</span> <span class="sy0">=</span> <span class="re0">$time_end</span><span class="sy0">-</span><span class="re0">$time_start</span><span class="sy0">;</span><br />
<span class="kw1">echo</span> <a href="http://www.php.net/number_format"><span class="kw3">number_format</span></a><span class="br0">&#40;</span><span class="re0">$time</span><span class="sy0">,</span> <span class="nu0">3</span><span class="sy0">,</span> <span class="st_h">'.'</span><span class="sy0">,</span> <span class="st_h">''</span><span class="br0">&#41;</span><br />
&nbsp; <span class="sy0">.</span><span class="st0">&quot; seconds - direct array access&quot;</span><span class="sy0">.</span><span class="re0">$newline</span><span class="sy0">;</span><br />
&nbsp; </p>
<p><span class="co1">// Adding these array values to APC</span><br />
<span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$array</span> <span class="kw1">as</span> <span class="re0">$k</span> <span class="sy0">=&gt;</span> <span class="re0">$v</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; apc_store<span class="br0">&#40;</span><span class="st_h">'test_'</span><span class="sy0">.</span><span class="re0">$k</span><span class="sy0">,</span> <span class="re0">$v</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="co1">// Benchmarking apc_fetch</span><br />
<span class="re0">$time_start</span> <span class="sy0">=</span> <a href="http://www.php.net/microtime"><span class="kw3">microtime</span></a><span class="br0">&#40;</span><span class="kw4">true</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$i</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span><br />
<span class="re0">$count</span> <span class="sy0">=</span> <a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$array</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$i</span> <span class="sy0">&lt;</span> <span class="re0">$count</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="re0">$devnull</span> <span class="sy0">=</span> apc_fetch<span class="br0">&#40;</span><span class="st_h">'test_'</span><span class="sy0">.</span><span class="re0">$i</span><span class="sy0">++</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="re0">$time_end</span> <span class="sy0">=</span> <a href="http://www.php.net/microtime"><span class="kw3">microtime</span></a><span class="br0">&#40;</span><span class="kw4">true</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$time</span> <span class="sy0">=</span> <span class="re0">$time_end</span><span class="sy0">-</span><span class="re0">$time_start</span><span class="sy0">;</span><br />
<span class="kw1">echo</span> <a href="http://www.php.net/number_format"><span class="kw3">number_format</span></a><span class="br0">&#40;</span><span class="re0">$time</span><span class="sy0">,</span> <span class="nu0">3</span><span class="sy0">,</span> <span class="st_h">'.'</span><span class="sy0">,</span> <span class="st_h">''</span><span class="br0">&#41;</span><br />
&nbsp; <span class="sy0">.</span><span class="st0">&quot; seconds - apc_fetch()&quot;</span><span class="sy0">.</span><span class="re0">$newline</span><span class="sy0">;</span><br />
<span class="co1">// Deleting APC entrys</span><br />
<span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$array</span> <span class="kw1">as</span> <span class="re0">$k</span> <span class="sy0">=&gt;</span> <span class="re0">$v</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; apc_delete<span class="br0">&#40;</span><span class="st_h">'test_'</span><span class="sy0">.</span><span class="re0">$k</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></p>
<p>
<span class="co1">// Benchmark mysql</span></p>
<p><span class="co1">// Connect</span><br />
<span class="re0">$link</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_connect"><span class="kw3">mysql_connect</span></a><span class="br0">&#40;</span><span class="st_h">'localhost'</span><span class="sy0">,</span> <span class="st_h">'username'</span><span class="sy0">,</span> <span class="st_h">'password'</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="re0">$link</span><span class="br0">&#41;</span> <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st_h">'Not connected : '</span> <span class="sy0">.</span> <a href="http://www.php.net/mysql_error"><span class="kw3">mysql_error</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$db_selected</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_select_db"><span class="kw3">mysql_select_db</span></a><span class="br0">&#40;</span><span class="st_h">'database'</span><span class="sy0">,</span> <span class="re0">$link</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="re0">$db_selected</span><span class="br0">&#41;</span> <a href="http://www.php.net/die"><span class="kw3">die</span></a> <span class="br0">&#40;</span><span class="st_h">'Can\'t use foo : '</span> <span class="sy0">.</span> <a href="http://www.php.net/mysql_error"><span class="kw3">mysql_error</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
<span class="co1">// Adding these array values to mySQL Memory table</span><br />
<span class="coMULTI">/* TABLE:<br />
&nbsp;CREATE TABLE `test_memory` (<br />
`key` INT UNSIGNED NOT NULL ,<br />
`value` INT UNSIGNED NOT NULL<br />
) ENGINE = MEMORY <br />
*/</span><br />
<span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$array</span> <span class="kw1">as</span> <span class="re0">$k</span> <span class="sy0">=&gt;</span> <span class="re0">$v</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st_h">'INSERT INTO test_memory (`key`,`value`) VALUES ('</span><span class="sy0">.</span><span class="re0">$k</span><span class="sy0">.</span><span class="st_h">', '</span><span class="sy0">.</span><span class="re0">$v</span><span class="sy0">.</span><span class="st_h">');'</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="co1">// Benchmark mysql memory table</span><br />
<span class="re0">$time_start</span> <span class="sy0">=</span> <a href="http://www.php.net/microtime"><span class="kw3">microtime</span></a><span class="br0">&#40;</span><span class="kw4">true</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$i</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span><br />
<span class="re0">$count</span> <span class="sy0">=</span> <a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$array</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$i</span> <span class="sy0">&lt;</span> <span class="re0">$count</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="sy0">,</span><span class="re0">$devnull</span><span class="br0">&#41;</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_fetch_row"><span class="kw3">mysql_fetch_row</span></a><span class="br0">&#40;</span><a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st_h">'SELECT * FROM `test_memory` WHERE `key` ='</span><span class="sy0">.</span><span class="re0">$i</span><span class="sy0">++.</span><span class="st_h">';'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="re0">$time_end</span> <span class="sy0">=</span> <a href="http://www.php.net/microtime"><span class="kw3">microtime</span></a><span class="br0">&#40;</span><span class="kw4">true</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$time</span> <span class="sy0">=</span> <span class="re0">$time_end</span><span class="sy0">-</span><span class="re0">$time_start</span><span class="sy0">;</span><br />
<span class="kw1">echo</span> <a href="http://www.php.net/number_format"><span class="kw3">number_format</span></a><span class="br0">&#40;</span><span class="re0">$time</span><span class="sy0">,</span> <span class="nu0">3</span><span class="sy0">,</span> <span class="st_h">'.'</span><span class="sy0">,</span> <span class="st_h">''</span><span class="br0">&#41;</span><br />
&nbsp; <span class="sy0">.</span><span class="st0">&quot; seconds - mysql_query from MEMORY table FIRST RUN&quot;</span><span class="sy0">.</span><span class="re0">$newline</span><span class="sy0">;</span><br />
<span class="co1">// Benchmark a second time to check for mysql caches</span><br />
<span class="re0">$time_start</span> <span class="sy0">=</span> <a href="http://www.php.net/microtime"><span class="kw3">microtime</span></a><span class="br0">&#40;</span><span class="kw4">true</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$i</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span><br />
<span class="re0">$count</span> <span class="sy0">=</span> <a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$array</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$i</span> <span class="sy0">&lt;</span> <span class="re0">$count</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="sy0">,</span><span class="re0">$devnull</span><span class="br0">&#41;</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_fetch_row"><span class="kw3">mysql_fetch_row</span></a><span class="br0">&#40;</span><a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st_h">'SELECT * FROM `test_memory` WHERE `key` ='</span><span class="sy0">.</span><span class="re0">$i</span><span class="sy0">++.</span><span class="st_h">';'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="re0">$time_end</span> <span class="sy0">=</span> <a href="http://www.php.net/microtime"><span class="kw3">microtime</span></a><span class="br0">&#40;</span><span class="kw4">true</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$time</span> <span class="sy0">=</span> <span class="re0">$time_end</span><span class="sy0">-</span><span class="re0">$time_start</span><span class="sy0">;</span><br />
<span class="kw1">echo</span> <a href="http://www.php.net/number_format"><span class="kw3">number_format</span></a><span class="br0">&#40;</span><span class="re0">$time</span><span class="sy0">,</span> <span class="nu0">3</span><span class="sy0">,</span> <span class="st_h">'.'</span><span class="sy0">,</span> <span class="st_h">''</span><span class="br0">&#41;</span><br />
&nbsp; <span class="sy0">.</span><span class="st0">&quot; seconds - mysql_query from MEMORY table SECOND RUN&quot;</span><span class="sy0">.</span><span class="re0">$newline</span><span class="sy0">;</span><br />
<span class="co1">// Trunc memory table </span><br />
<a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st_h">'TRUNCATE TABLE test_memory;'</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p><span class="sy1">?&gt;</span></div>
</div>
<h3>Result</h3>
<p>Output of the script:</p>
<div class="codesnip-container" >Testarray has 10000 random integer entrys<br />
0.002 seconds - direct array access<br />
0.011 seconds - apc_fetch()<br />
1.304 seconds - mysql_query from MEMORY table FIRST RUN<br />
1.167 seconds - mysql_query from MEMORY table SECOND RUN</div>
<p>The measured times are <strong>only</strong> fetching times. Fetching should by done much often in reality than storing, so it is way more important.</p>
<p>As you can see the direct access is the fastes. APC is ony 5 times slower than direct access. That is very fast compared to the MySQL equivalent. MySQL took about 100 times longer than APC. This result is astonishing. I though MySQL might be about 5 or 10 times slower then APC, but 100 is very much.<br />
I also let the MySQL select run twice to check for buffers that might come in but no better result.<br />
A "stangl" already mentioned, the overhead produced by MySQL for querying, parsing, and returning is very big and slow compared to APC.</p>
<h3>Conclusion</h3>
<p>If you need only very few variables to store, try APC first. MEMORY TABLES might be handy when you need to save more than APC can handle effictively.</p>
<p>If anybody can find a mistake i did, please let me know. Maybe MEMORY tables are not that slow as my benchmark turned out.</p>
]]></content:encoded>
			<wfw:commentRss>http://juliusbeckmann.de/blog/benchmark-apc-vs-mysql-memory-fetching-speed.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL: MySQL5 Update</title>
		<link>http://juliusbeckmann.de/blog/mysql-mysql5-update.html</link>
		<comments>http://juliusbeckmann.de/blog/mysql-mysql5-update.html#comments</comments>
		<pubDate>Tue, 15 Jul 2008 19:50:44 +0000</pubDate>
		<dc:creator>Julius</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[apt-get]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Update]]></category>

		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=50</guid>
		<description><![CDATA[Für alle Admins die die Ehre haben einen Server zu betreuen, es gibt ein Mysql 5 Update. Sowohl der Server als auch die Libs werden geupdatet. Das ganze erfordert einen Mysql-Server Neustart, also aufpassen was sonst noch so läuft. Um das Update durchzuführen einfach folgende Befehle auf Debian basierenden System (also auch Ubuntu und so [...]]]></description>
			<content:encoded><![CDATA[<p>Für alle Admins die die Ehre haben einen Server zu betreuen, es gibt ein Mysql 5 Update. Sowohl der Server als auch die Libs werden geupdatet. Das ganze erfordert einen Mysql-Server Neustart, also aufpassen was sonst noch so läuft.</p>
<p><span id="more-50"></span></p>
<p>Um das Update durchzuführen einfach folgende Befehle auf Debian basierenden System (also auch Ubuntu und so ähnlich) eingeben:</p>
<p>Paketquellen aktualisieren:</p>
<div class="codesnip-container" >apt-get update</div>
<p>Alle Pakete auf Aktualisierungen prüfen:</p>
<div class="codesnip-container" >apt-get upgrade</div>
<p>P.S. für Anfänger:<br />
Diese beiden Befehle merken und ab und zu mal ausführen.</p>
]]></content:encoded>
			<wfw:commentRss>http://juliusbeckmann.de/blog/mysql-mysql5-update.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
