Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I am trying to learn memcached, so I installed it on my laptop and fired it up. I also created a simple SQLite db 'mem.sqlite' like so


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?

when small people start casting long shadows, it is time to go to bed

In reply to learning memcached by punkish

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (4)
    As of 2018-05-22 17:57 GMT
    Find Nodes?
      Voting Booth?