punkish has asked for the wisdom of the Perl Monks concerning the following question:
CREATE TABLE t (id INTEGER PRIMARY KEY, str TEXT)
and filled the table with 20_000 random strings. Then I used the following simplistic script to benchmark.
use Cache::Memcached; my $memd = new Cache::Memcached {'servers' => [ "localhost:11212" ]}; use DBI qw(:sql_types); my $dbh = DBI->connect("dbi:SQLite:dbname=mem.sqlite"); use Benchmark qw(:all); my $count = 40_000; cmpthese($count, { 'query_dbh' => sub { my $id = int(rand(20_000)); my $sth = $dbh->prepare("SELECT str FROM t WHERE id = ?"); $sth->execute($id); my ($str) = $sth->fetchrow_array; open F, ">", "foo.txt" or die $!; print F "id: $id, str: $str\n"; close F; }, 'query_mem' => sub { my $id = int(rand(20_000)); open F, ">", "foo.txt" or die $!; my $str = $memd->get($id); unless ($str) { my $sth = $dbh->prepare("SELECT str FROM t WHERE id = ?"); $sth->execute($id); ($str) = $sth->fetchrow_array; $memd->set($id, $str); } print F "id: $id, str: $str\n"; close F; } }); Rate query_mem query_dbf query_mem 2723/s -- -29% query_dbh 3846/s 41% --
I consistently get results such as above, while I expected the memcache to slowly fill up and speed up the queries way faster than only accessing the file based db. What am I doing wrong, or are my expectations wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: learning memcached
by Marshall (Canon) on May 22, 2011 at 03:59 UTC | |
by punkish (Priest) on May 22, 2011 at 15:29 UTC | |
by steve (Deacon) on May 24, 2011 at 15:42 UTC | |
by punkish (Priest) on May 27, 2011 at 22:04 UTC | |
|
Re: learning memcached
by Anonymous Monk on May 21, 2011 at 02:44 UTC | |
by punkish (Priest) on May 21, 2011 at 02:51 UTC | |
by Anonymous Monk on May 21, 2011 at 03:04 UTC | |
by punkish (Priest) on May 21, 2011 at 03:10 UTC | |
by Anonymous Monk on May 21, 2011 at 03:18 UTC |