Is memcached really faster than MySQL on very simple query?

Evan Martin martine at danga.com
Thu Jul 13 13:22:56 UTC 2006


Until your MySQL becomes a bottleneckf, there is no reason to
complicate your setup by sticking memcached in.  (Unless you think you
might need it in the future, in which case it might be worth thinking
about how to design your code to help.)

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