summaryrefslogtreecommitdiff
path: root/lmdb.pl
diff options
context:
space:
mode:
Diffstat (limited to 'lmdb.pl')
-rwxr-xr-xlmdb.pl21
1 files changed, 13 insertions, 8 deletions
diff --git a/lmdb.pl b/lmdb.pl
index 1e5e11f..35931eb 100755
--- a/lmdb.pl
+++ b/lmdb.pl
@@ -17,7 +17,7 @@ my($env, $txn, $dbi);
sub db {
my $wr = shift;
$env = LMDB::Env->new($dbfile, { mapsize => 1<<36, maxdbs => 1, flags => MDB_NOSUBDIR|($wr?0:MDB_RDONLY) });
- $txn = $env->BeginTxn();
+ $txn = $env->BeginTxn($wr ? 0 : MDB_RDONLY);
$dbi = $txn->open('db', $wr ? MDB_CREATE : undef);
}
@@ -43,15 +43,20 @@ sub bench {
sub extract {
- db;
- my $db = LMDB_File->new($txn, $dbi);
- my $cur = $db->Cursor();
+ # This ugly periodic opening/closing of the database is to work around a
+ # memory leak somewhere.
eval {
- my($key, $value);
- $cur->get($key, $value, MDB_FIRST);
+ my $key;
while(1) {
- print "$key\n";
- $cur->get($key, $value, MDB_NEXT);
+ $env = $txn = $dbi = undef;
+ db;
+ my $db = LMDB_File->new($txn, $dbi);
+ my $cur = $db->Cursor();
+ $cur->get($key, (my $value), defined($key) ? MDB_SET_KEY : MDB_FIRST);
+ for (0..10_000) {
+ print "$key\n";
+ $cur->get($key, $value, MDB_NEXT);
+ }
}
}
}