MySQL
  Home arrow MySQL arrow Take Some Load off MySQL with MemCached
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Take Some Load off MySQL with MemCached
By: Chris Moyer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2008-07-29


    Table of Contents:
  • Take Some Load off MySQL with MemCached
  • A Solution - Caching
  • Enter MemCached
  • PHP MemCache PECL Extension

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Take Some Load off MySQL with MemCached
    ( Page 1 of 4 )

    While the execution speed of your codebase can be a factor in the overall scalability of your application, more often than not, your database will become a bottleneck first. Modern web development environments can generally serve many page loads per second, and each of these pages will often make many requests to the database for fresh information. These pages may also be rendered by an easily expandable pool of web servers. While databases, including MySQL, are adequately designed to handle a significant number of queries, eventually, the load from all these requests can become too much to handle.

    The Overworked Database

    A web page may generate dozens of queries on each page load – user credentials, session information, system notifications, new messages, latest headlines, configuration information, and content areas may be loaded on every single page and displayed to the user or acted upon by the page logic. As this data is read by the rendering process, other web requests or background processes may be modifying the data in these tables by inserting new headlines, publishing new content areas, and creating sessions for other users. Often, this contention between database reads and writes is where the bottlenecks occur. In order to maintain database integrity, protections are generally in place to prevent the same data from being read as it is written.

    In a typical MySQL installation, this problem can become quite apparent because the default table format of MySQL requires that an entire database table be locked while data is being updated in any row. This can create a cascading effect when one process writes to an important table. Perhaps the sessions table is updated whenever a user logs in or logs out.  If so, every page load will then read from the sessions table to determine the authentication status of a given user (based on their cookies). Once you reach a tipping point, the minor pauses caused by the writes to the table can pile up like a traffic jam, slowing the entire site down simply because of writes to a single database table.

    In a situation where you notice intermittent slowdowns of your site, you can attempt to troubleshoot the cause from the MySQL command line:

    mysql> show processlist;

    +----+------+-----------+------+---------+------+--------+--------------

    ------------------------------+

    | Id | User | Host | db | Command | Time | State | Info

    |

    +----+------+-----------+------+---------+------+--------+--------------

    | 1 | root | localhost | test | Query | 3 | Locked | select * from | 2 | root | localhost | test | Query | 6 | Locked | insert into ON

    As you can see, you’ll get simple feedback if queries are waiting on a locked table by the State field. The Time field shows how many seconds the query has been running.



     
     
    >>> More MySQL Articles          >>> More By Chris Moyer
     

       

    MYSQL ARTICLES

    - MySQL Security Tips
    - Designing a MySQL Database: Tips and Techniq...
    - The Three Most Important MySQL Queries
    - Null and Empty Strings
    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT