grondilu,

This is a code snippet from a working program, to show you how to use the 'BerkeleyDB::Env'. Think of the environment as a holding directory, where related databases are stored, and the related BerkeleyDB internal files and cache are stored. I wouldn't use '/tmp' since it's world readable, but that's your call.

I pulled a lot of unrelated testing out, so it may not compile, but you'll be in the ballpark. This shows with the default cache size, but I usually 16MB in production.

One important thing, I left the 'Fcntl' in to help you think about the potential for race conditions. I use an extra file to lock the BerkeleyDB environment before using the BerkeleyDB calls. Without it, you are suspect to many race conditions. If you are going to run in single user mode, you don't need it. But for multi-user or multi-tasking you'll save yourself a lot of headaches. BerkeleyDB is very fast and you don't notice any overhead with the extra flocks.

use strict; + use BerkeleyDB; our %Session = (); use Fcntl qw( :flock ); my $DBHome = "/home/FlexBase/"; system("rm /home/FlexBase/*"); ## Temporary for testing our $filename = "/home/FlexBase/TestBDB"; use constant CACHE => '1048576'; my $Cachesize = CACHE; our $env = new BerkeleyDB::Env ( -Home => '/home/FlexBase', -Cachesize => CACHE, -Flags => DB_INIT_MPOOL|DB_INIT_CDB|DB_CREATE ) or die "cannot open ENV: $! $BerkeleyDB::Error\n"; our %Pyr = (); our $db1 = tie %Pyr, 'BerkeleyDB::Btree', ( -Filename => "$filename", -Env => $env, # -Pagesize => 4096, ## Use of this makes the Berk +eleyDB operate worst! -Flags => DB_CREATE );

If you super search on BerkeleyDB, you'll find some examples of subroutines that show the external locking and some timing information.

Good Luck!

"Well done is better than well said." - Benjamin Franklin


In reply to Re: can't manage to use BerkeleyDB::Env by flexvault
in thread can't manage to use BerkeleyDB::Env by grondilu

Title:
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, details, 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, summary, 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.