<?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>Bagesh Singh&#039;s Blog &#187; sql</title>
	<atom:link href="http://www.bageshsingh.com/bagesh-blog/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bageshsingh.com/bagesh-blog</link>
	<description>Shortest Distance to  Web Solutions &#38; Software Solutions</description>
	<lastBuildDate>Wed, 22 Feb 2012 18:42:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How did I reduce CPU overhead problem caused by MySql?</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/11/reduce-cpu-overhead-problem-by-mysql/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/11/reduce-cpu-overhead-problem-by-mysql/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 17:12:05 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=828</guid>
		<description><![CDATA[We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access from a PHP [...]]]></description>
			<content:encoded><![CDATA[<p>We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access from a PHP file was creating the overhead to the CPU of the server.</p>
<h4>Problem of CPU Overhead with MySql</h4>
<p>Let me explain the problem clearly first,</p>
<p>We’re working on a website which was similar to http://www.swoopo.co.uk/ and as you can see clearly in that website the most recent data should be fetched form MySql database in each second. in the PHP page, which was being called from Ajax every second, had around 5 SQL queries to retrieve data from server.</p>
<p>First of all, I optimized that page reducing the 5 queries into single query by using left outer joins among 3 tables. And then, I did benchmark test by using Apache benchmark tool(ab) 50 request with concurrency of 50 with the following command.</p>
<blockquote><p>ab -n 50 -c 50 http://xyz.com/ajax_page.php</p></blockquote>
<p>And then in another SSH shell prompt, I run the top command to view the CPU usages parallelly.</p>
<p>I was still horrified that the CPU usages by mysql after 50 concurrent user was going out of control(100%) despite of optimized query. But many joins have been used in that single query and lots of data were there in those tables so the database overhead was high even though it was a single query.</p>
<h4>How did I reduced the CPU overload drastically caused by MySql?</h4>
<p>Now, the first challenge was to reduce the database access. It was clear that it was caused by concurrent database overhead in the PHP page which was being called in every second. Here is the simple steps what I did to reduce the database overhead.</p>
<ol>
<li>I created another PHP file in which I’ve transferred the mysql query causing CPU overhead and called it from Cronjob.</li>
<li>Created a temporary table for storing the output given by  PHP page called from CronJob.</li>
<li>Then, I scheduled the CronJob in every second, don’t tell me that CronJob can’t be run less than a minute, take a look at this post before saying this.And from each call, the output data was stored in the temporary table.</li>
<li>And, finally from the Ajax the a new PHP page was called which was only accessing the data from temporary table with single row.</li>
</ol>
<p>I did the same benchmarking again to the newly made page(which is accessing data only from temporary table) and saw that CPU usages after the this process reduced drastically.</p>
<p>I know I can further reduce the CPU overhead by storing the temporary data in a text file. You guyz know that I’m lazy so that part is left for another day.</p>
<div id="seo_alrp_related"><h2>Posts Related to How did I reduce CPU overhead problem caused by MySql?</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql/" rel="bookmark">How did I reduce CPU overhead problem caused by MySql?</a></h3><p>From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql-2/" rel="bookmark">How did I reduce CPU overhead problem caused by MySql?</a></h3><p>From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/09/how-to-optimize-mysql-query-and-mysql-database/" rel="bookmark">How to optimize mysql query and mysql database?</a></h3><p>There is lots of way to optimize mysql. once you optimize your query and database of mysql it will make your website and application very ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/05/mysql-and-sql-injection/" rel="bookmark">MySQL and SQL Injection</a></h3><p>If you take user input through a webpage and insert it into a MySQL database there's a chance that you have left yourself wide open ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/how-to-do-mysql-optimization/" rel="bookmark">how to do MySQL Optimization</a></h3><p>myisamchk is used to get information about your database tables or to check, repair, or optimize them. This command can check or repair MyISAM tables. ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/11/reduce-cpu-overhead-problem-by-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How did I reduce CPU overhead problem caused by MySql?</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql-2/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql-2/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 11:22:51 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=213</guid>
		<description><![CDATA[From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access [...]]]></description>
			<content:encoded><![CDATA[<p>From last day, We were having problem with a project which was shut  down in the middle due to heavy traffic. As a technical manager, I was  the person who to take charge over the project bring it down to the  track. After doing few benchmark test, I came to know that the MySql  access from a PHP file was creating the overhead to the CPU of the  server.</p>
<h4>Problem of CPU Overhead with MySql</h4>
<p>Let me explain the problem clearly first,</p>
<p>We</p>
<div id="seo_alrp_related"><h2>Posts Related to How did I reduce CPU overhead problem caused by MySql?</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql/" rel="bookmark">How did I reduce CPU overhead problem caused by MySql?</a></h3><p>From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/reduce-cpu-overhead-problem-by-mysql/" rel="bookmark">How did I reduce CPU overhead problem caused by MySql?</a></h3><p>We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/02/how-to-solve-the-problem-of-retrieving-same-value-by-ajax-%e2%80%93-browser-cache-problem/" rel="bookmark">How to solve the problem of retrieving same value by Ajax</a></h3><p>You might have faced the problem of the getting same response on the consecutive request to a PHP file from Ajax. Well, what happens when ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/solving-floating-point-number-precision-lost-problem-in-php/" rel="bookmark">Solving Floating point number precision lost problem in PHP</a></h3><p>The problem of precision lost in floating point number in PHP haunted me for about 10 minutes yesterday but I quickly figured out the problem ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/02/solving-european-characters-western-charset-problem-with-ajax-and-php/" rel="bookmark">Solving European characters (Western charset) problem with Ajax and PHP</a></h3><p>Today, I would like to tell you how to handle character set problem which occurs during the data fetched from PHP using Ajax mainly on ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How did I reduce CPU overhead problem caused by MySql?</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 16:02:41 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=88</guid>
		<description><![CDATA[From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access [...]]]></description>
			<content:encoded><![CDATA[<p>From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access from a PHP file was creating the overhead to the CPU of the server.</p>
<h4>Problem of CPU Overhead with MySql</h4>
<p>Let me explain the problem clearly first,</p>
<p>We</p>
<div id="seo_alrp_related"><h2>Posts Related to How did I reduce CPU overhead problem caused by MySql?</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql-2/" rel="bookmark">How did I reduce CPU overhead problem caused by MySql?</a></h3><p>From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/reduce-cpu-overhead-problem-by-mysql/" rel="bookmark">How did I reduce CPU overhead problem caused by MySql?</a></h3><p>We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/02/how-to-solve-the-problem-of-retrieving-same-value-by-ajax-%e2%80%93-browser-cache-problem/" rel="bookmark">How to solve the problem of retrieving same value by Ajax</a></h3><p>You might have faced the problem of the getting same response on the consecutive request to a PHP file from Ajax. Well, what happens when ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/solving-floating-point-number-precision-lost-problem-in-php/" rel="bookmark">Solving Floating point number precision lost problem in PHP</a></h3><p>The problem of precision lost in floating point number in PHP haunted me for about 10 minutes yesterday but I quickly figured out the problem ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/02/solving-european-characters-western-charset-problem-with-ajax-and-php/" rel="bookmark">Solving European characters (Western charset) problem with Ajax and PHP</a></h3><p>Today, I would like to tell you how to handle character set problem which occurs during the data fetched from PHP using Ajax mainly on ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

