Is memcached really faster than MySQL on very simple query?

Ian Kallen spidaman at gmail.com
Thu Jul 13 14:00:52 UTC 2006


I think a lot of the replies you've received miss the point. If your
application really entails iteratively reading the same key from a
table with one record, then don't bother with memcached. Meanwhile,
back in the real world, where you have applications that have lots of
read/write concurrency, result sets from joins, record sizes with
substantial data payloads, etc and you're measuring performance in
milliseconds (use Time::HiRes, not perl's built-in time()), you'll
find that memcached usually provides one to two orders of magnitude
performance increases.

meta issue:
I do agree that it's probably worthwhile to update the memcached
documentation to provide clear use cases and scenarios. These
comparisons, the questions about cache/backend consistency, key
redistribution, which PHP client sucks less and yadda yadda yadda are
getting tedious (this is a testament to memcached's success, bravo
Brad!). I'd be happy to help, perhaps danga can toss a mediawiki
instance online, that way the list members can doc these things.
-Ian

On 7/13/06, howard chen <howachen at gmail.com> wrote:
>
> hi, some interesting findings done by me...
> p.s. i am not an expert, so pls kindly correct me if i am wrong :)
>
>
> //script 1.
> use Cache::Memcached;
>
>
> $memd = new Cache::Memcached { 'servers' => ['127.0.0.1:11211',
> '127.0.0.1:11212'], 'debug' => 0, 'compress_threshold' => 10_000, };
>
> $memd->set("1001001",
> "sfdjfdjsfsdfu8duf8dhsujsdfjsfdsfhd8sfhsdfd7sfhdsfenwurerefdsfjdnfjdsnfdsuhufsidufhdsuifhuiheu");
>
> my $startTime = time();
>
> for ($count=1; $count<10000; $count++) {
>         my $tmp = $memd->get("1001001");
> }
>
> my $endTime = time();
> print $endTime - $startTime;
> print "\n";
>
> // 13 seconds
> //---------------------------------------------------------------------------
> //script 2.
>
> use DBI;
>
> my $dsn = 'DBI:mysql:' . "test" . ":" . "127.0.0.1";
> my $dbh = DBI->connect( $dsn, "root", "" );
>
> my $startTime = time();
>
> for ($count=1; $count<10000; $count++) {
>
>  my $sth = $dbh->prepare("select lastname from test");
>  $sth->execute();
>  my @data = $sth->fetchrow_array();
> }
>
> my $endTime = time();
> print $endTime - $startTime;
> print "\n";
>
> // 11 seconds
>
>
> //----------------------------------------------------------------------
>
> //MYSQL table
>
> DROP TABLE IF EXISTS `test`;
> CREATE TABLE `test` (
>   `LastName` varchar(255) default NULL
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
>
> INSERT INTO `test` VALUES
> ('sfdjfdjsfsdfu8duf8dhsujsdfjsfdsfhd8sfhsdfd7sfhdsfenwurerefdsfjdnfjdsnfdsuhufsidufhdsuifhuiheu');
>
>
> //--------------------------------------------------------------------------
>
> seems MySQL is quite efficient in handling simple query?
>
> regards,
> howa
>
>


More information about the memcached mailing list