<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>mysql on S Anand</title>
    <link>https://www.s-anand.net/blog/tag/mysql/</link>
    <description>Recent content in mysql on S Anand</description>
    <generator>Hugo -- 0.164.0</generator>
    <language>en-us</language>
    <lastBuildDate>Wed, 14 Jul 2010 05:23:29 +0000</lastBuildDate>
    <atom:link href="https://www.s-anand.net/blog/tag/mysql/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Install XAMPP</title>
      <link>https://www.s-anand.net/blog/install-xampp/</link>
      <pubDate>Wed, 14 Jul 2010 05:23:29 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/install-xampp/</guid>
      <description>&lt;p&gt;I’ve been going around setting up open source software a fair bit recently. To minimise the pain of explaining it, I’m putting together a short videos that explain the process.&lt;/p&gt; &lt;p&gt;Here’s the first, on &lt;a href=&#34;www.apachefriends.org/en/xampp-windows.html&#34;&gt;XAMPP&lt;/a&gt;, which is a starting point for most open source applications. It bundles Apache (web server), MySQL (database), Perl and PHP.&lt;/p&gt; &lt;p&gt;To install it, search and download “XAMPP for Windows”, and press enter for every question. Then install your application under C:\xampp\htdocs. That’s it.&lt;/p&gt; &lt;p&gt;&lt;object width=&#34;600&#34; height=&#34;475&#34;&gt;&lt;param name=&#34;movie&#34; value=&#34;http://www.youtube.com/v/cT0LwR1WmM8&amp;amp;hl=en_GB&amp;amp;fs=1&#34;&gt;&lt;/param&gt;&lt;param name=&#34;allowFullScreen&#34; value=&#34;true&#34;&gt;&lt;/param&gt;&lt;param name=&#34;allowscriptaccess&#34; value=&#34;always&#34;&gt;&lt;/param&gt;&lt;embed src=&#34;http://www.youtube.com/v/cT0LwR1WmM8&amp;amp;hl=en_GB&amp;amp;fs=1&#34; type=&#34;application/x-shockwave-flash&#34; allowscriptaccess=&#34;always&#34; allowfullscreen=&#34;true&#34; width=&#34;600&#34; height=&#34;475&#34;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;http://chandoo.org/wp/&#34;&gt;Chandoo&lt;/a&gt;&lt;/strong&gt; &lt;em&gt;14 Jul 2010 11:32 am&lt;/em&gt;:
Good one..
Recently I had to install XAMP (no need for Perl, yet..) and I went with Windows Platform Installer. Found it much more simple and easy&amp;hellip; &lt;a href=&#34;http://www.microsoft.com/web/downloads/platform.aspx&#34;&gt;http://www.microsoft.com/web/downloads/platform.aspx&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
    <item>
      <title>Reducing the server load</title>
      <link>https://www.s-anand.net/blog/reducing-the-server-load/</link>
      <pubDate>Wed, 06 Jun 2007 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/reducing-the-server-load/</guid>
      <description>&lt;p&gt;I&amp;rsquo;m been using a shared hosting service with &lt;a href=&#34;http://www.100ws.com/&#34;&gt;100 WebSpace&lt;/a&gt; over the last 7 years. It&amp;rsquo;s an ad-free account that offers 100MB of space and 3GB of bandwidth per month. Things were fine until two months ago, which was when my &lt;a href=&#34;https://www.s-anand.net/blog/hindi&#34;&gt;song search engines&lt;/a&gt; started attracting an audience. I had anticipated that I might run out of bandwidth, so I used a &lt;a href=&#34;http://www.freehostia.com/&#34;&gt;different server&lt;/a&gt; (that has 5GB of bandwidth per month quota) for loading the songs. But what I didn&amp;rsquo;t anticipate whas that &lt;strong&gt;my server load would run over the allotted CPU limit&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;d think this is unusual, given how cheap computing power is, and that I&amp;rsquo;d run out of bandwidth quicker. But no. My allotted limit was 1.3% of CPU usage (whatever that meant), and about 2 months ago, I hit 1.5% a few times. I upgraded my account to one which had a 2.5% limit immediately, but the question was: &lt;strong&gt;why did this happen?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This blog uses a lot of Perl scripts&lt;/strong&gt;. I store all articles on a MySQL database. Every time a link is requested, I dynamically generate the HTML by pulling up the article from the MySQL database and formatting the text based on a template.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.s-anand.net/blog/assets/flickr-schematic-of-how-my-website-displays-pages_533687183_o-gif.webp&#34;&gt;&lt;img alt=&#34;Schematic of how my website displays pages&#34; loading=&#34;lazy&#34; src=&#34;https://www.s-anand.net/blog/assets/flickr-schematic-of-how-my-website-displays-pages_533687183_o-gif.webp&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I also use MySQL to store users&amp;rsquo; comments. Every time I display each page, I also pull out the comments related to that page.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I can&amp;rsquo;t store the files directly as HTML because I keep changing the template&lt;/strong&gt;. Every time I change the template, I have to regenerate all the files. If I do that on my laptop and upload it, I consume a lot of bandwidth. If I do that on the server, I consume a lot of server CPU time.&lt;/p&gt;
&lt;p&gt;Anyway, since I&amp;rsquo;d upgraded my account, I thought things would be fine. Two weeks ago, I hit the 2.5% limit as well. No choice. Had to do something.&lt;/p&gt;
&lt;p&gt;If you read the &lt;a href=&#34;http://www.google.co.uk/search?&amp;amp;q=o%27reilly+database+war+stories&#34;&gt;O&amp;rsquo;Reilly Radar Database War Stories&lt;/a&gt;, you&amp;rsquo;ll gather that &lt;strong&gt;databases are great for queries, joins and the like, while flat files are better to process large volume data as a batch&lt;/strong&gt;. Since page requests come one by one, and I don&amp;rsquo;t need to do much batch processing, I&amp;rsquo;d gone in for a MySQL design. &lt;strong&gt;But there&amp;rsquo;s a fair bit of overhead to each databasse query&lt;/strong&gt;, and that&amp;rsquo;s the key problem. Perl takes a while to load (and I suspect my server is not using &lt;a href=&#34;http://perl.apache.org/&#34;&gt;mod_perl&lt;/a&gt;). The &lt;a href=&#34;http://dbi.perl.org/&#34;&gt;DBI module&lt;/a&gt; takes a while to load. Connecting to MySQL takes a while. (The query itself, though, is quite fast.)&lt;/p&gt;
&lt;p&gt;So &lt;strong&gt;I moved to flat files instead&lt;/strong&gt;. Instead of looking up from a database, I just look up a test file using &lt;a href=&#34;http://en.wikipedia.org/wiki/Grep&#34;&gt;grep&lt;/a&gt;. (I don&amp;rsquo;t use Perl&amp;rsquo;s regular expression matching because &lt;a href=&#34;http://swtch.com/~rsc/regexp/regexp1.html&#34;&gt;regular expression matching in UNIX is faster than in Perl&lt;/a&gt;.) I have a 1.6MB text file that contains all my blog entries.&lt;/p&gt;
&lt;p&gt;But looking up a 1.6MB text file takes a while. So I split the file based on the first letter of the title. So this post (&lt;a href=&#34;https://www.s-anand.net/blog/reducing-the-server-load/&#34;&gt;Reducing the server load&lt;/a&gt;) would go under a file &lt;code&gt;x.r.txt&lt;/code&gt; (for &amp;lsquo;R&amp;rsquo;) while my last post (&lt;a href=&#34;https://www.s-anand.net/blog/calvin-and-hobbes-animated/&#34;&gt;Calvin and Hobbes animated&lt;/a&gt;) would go under a file &lt;code&gt;x.c.txt&lt;/code&gt; (for &amp;lsquo;C&amp;rsquo;). This speeds up the grep by a factor of 5-10.&lt;/p&gt;
&lt;p&gt;On average, using MySQL query used to take 0.9 seconds per query. Now, using grep, it&amp;rsquo;s down to about 0.5 seconds per query. &lt;strong&gt;Flat files reduced the CPU load by about half&lt;/strong&gt;. (And as a bonus, my site has no SQL code. I never did like SQL that much.)&lt;/p&gt;
&lt;p&gt;So that&amp;rsquo;s why you haven&amp;rsquo;t seen any posts from me the last couple of weeks. Partly because I didn&amp;rsquo;t have anything to say. Partly because I was forced to revamp this site.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sathya&lt;/strong&gt; &lt;em&gt;6 Jun 2007 12:00 pm&lt;/em&gt;:
Wow. thats quite interesting. Perhaps you could have also tried caching. keep a copy of &amp;lsquo;&amp;lsquo;hot&amp;rsquo;&amp;rsquo; (Most Recently used -MRU) stuff in memory, so you dont have to relaod it again. Given that most of the hits would be for the latest entries ( or atleast 80% of the hits are for 20% of ur posts) then caching might be an option. However, I dont know how much of RAM quota you have ;-)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;somnath&lt;/strong&gt; &lt;em&gt;6 Jun 2007 12:00 pm&lt;/em&gt;:
Do you work at your company in business consulting or technology. Having known you for the past eight years (jeez a long time) I have no doubt you manage not just both but spend quality time with your family as well. Maybe it would be a good idea to blog about your typical day when you juggle between work (consulting for a big client), passion (revaming this site or taking pictures or doing a project like building media pc etc. etc.) and family (playing with a baby daughter is wonderful). BTW got your mail but I check internet mail very infrequently. Cheers!&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Saurabh&lt;/strong&gt; &lt;em&gt;6 Jun 2007 12:00 pm&lt;/em&gt;:
This one is slightly off the topic..I also started using freehostia a few months back, however I find that 2 out of 7 days in a week, my website is not available for more than 96% of the time..(I monitor the uptime using something called as InternetSeer)..Would you have any tips here, is freehostia not a good option for free services or should I switch to some other service provider?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;http://www.google.com&#34;&gt;Rocco Blegen&lt;/a&gt;&lt;/strong&gt; &lt;em&gt;4 Dec 2011 4:14 am&lt;/em&gt;:
Howdy! This post couldn’t be written any better! Reading through this post reminds me of my old room mate! He always kept talking about this. I will forward this post to him. Pretty sure he will have a good read. Thank you for sharing!&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
    <item>
      <title>Using Google Code Search for hacking</title>
      <link>https://www.s-anand.net/blog/using-google-code-search-for-hacking/</link>
      <pubDate>Wed, 27 Dec 2006 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/using-google-code-search-for-hacking/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://www.shoemoney.com/2006/12/26/how-hackers-are-using-google-to-pwn-your-site/&#34;&gt;How hackers are using Google to pwn your site&lt;/a&gt;. Includes a very practical example of how to use Google Code Search to hack a MySQL account.&lt;/p&gt;
</description>
    </item>
  </channel>
</rss>
