Is memcached really faster than MySQL on very simple query?
howard chen
howachen at gmail.com
Thu Jul 13 10:48:19 UTC 2006
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20060713/ea608073/attachment.html
More information about the memcached
mailing list