Memcached为具有大量选择的小型数据库带来好处

I am building a web app in php with mysql as database.

I am using memcached to store sessions and I am thinking if I should also store (in another memcached instance), database records.

The db is going to be pretty small and updated once in a while. There are going to be a lot of selects though, as we expect high traffic.

For a small database would I benefit if I store records in memcached or should I leave it to the mysql cache and tune the db for lots of connections (would appreciate some pointers for optimizing mysql)?

Thanks

Why dont you run some benchmarks and then spread that load !!

http://www.php.net/manual/en/intro.apc.php

Page generated in 0.003202 secs using 2 DB calls and 0 DBCache hits (users ttl=5 countries ttl=5 and both items have expired)

Page generated in 0.002728 secs using 1 DB calls and 1 DBCache hits (users ttl=5 countries ttl=immortal and users has expired)

Page generated in 0.000067 secs using 0 DB calls and 2 DBCache hits (users ttl=5 countries ttl=immortal and both are fetched from cache)

how fast - 0.000067 ouch !! 

Sample PHP Script using APC

<?php

require_once "CacheDB.php";

ob_start(); 

echo "<h3>APC info:</h3>";

print_r(apc_sma_info());

try{

    //I assume you've already have a db connection available for the cacheDB to use

    $db = @new mysqli("127.0.0.1","foo_dbo","pass","foo_db",3306);

    if ($db->connect_errno)
        throw new Exception("Could not connect: " . $db->connect_error);

    //start the demo...

    $startTime = microtime(true);

    $cacheDB = new CacheDB($db);

    $rows = $cacheDB->Query("call list_users()", CacheDB::TTL_5); //5 second Time To Live (TTL) (30 secs might be more realistic)
    if($rows){
        echo "<h3>Users:</h3><ul>";
        foreach($rows as $row) echo sprintf("<li>%s</li>", $row["username"]);
        echo "</ul>";
    }

    $rows = $cacheDB->Query("call list_countries()", CacheDB::TTL_IMMORTAL); //never expires

    if($rows){
        echo "<h3>Countries:</h3><ul>";
        foreach($rows as $row) echo sprintf("<li>%s</li>", $row["name"]);
        echo "</ul>";
    }

    echo sprintf("<p><b>Page generated in %s secs using %d DB calls and %d DBCache hits</b></p><p>Refresh me !!</p>",
            number_format(microtime(true) - $startTime, 6, ".", ""), 
            $cacheDB->GetDBHits(), $cacheDB->GetCacheHits());

    $db->close();
}
catch(Exception $ex)
{ 
    ob_clean(); 
    echo sprintf("zomg borked - %s", $ex->getMessage());
}

//finally

ob_end_flush();

?>