niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Berkeley DB
help creating a memory only B-tree
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
Author Message
bostic@sleepycat.com
*nix forums beginner


Joined: 21 Jun 2005
Posts: 49

PostPosted: Fri Mar 18, 2005 6:03 pm    Post subject: Re: help creating a memory only B-tree Reply with quote

Quote:
Am new to Berkeley DB. I heard its fast. I am tring to create a
memory
only database and it seems to be very slow. For inserting 10000 keys
(average 10 bytes/key) its taking 8seconds!! I must be doing
something
wrong. The library size is around 660KB. I built the library like
this:


I'd suggest pre-sorting your data -- inserting random data into
a Btree is often the worst possible case. Pre-sorted data is
the best case.

You're also using the default Berkeley DB cache size, which is
quite small, only 256KB. If you cannot sort your data, increasing
the cache size should help.

Regards,
--keith

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Keith Bostic bostic@sleepycat.com
Sleepycat Software Inc. keithbosticim (Yahoo)
118 Tower Rd. +1-781-259-3139
Lincoln, MA 01773 http://www.sleepycat.com
Back to top
berkeleydb_user
*nix forums beginner


Joined: 16 Mar 2005
Posts: 17

PostPosted: Wed Mar 16, 2005 7:48 pm    Post subject: help creating a memory only B-tree Reply with quote

Guys

Am new to Berkeley DB. I heard its fast. I am tring to create a memory
only database and it seems to be very slow. For inserting 10000 keys
(average 10 bytes/key) its taking 8seconds!! I must be doing something
wrong. The library size is around 660KB. I built the library like this:

prompt$ make realclean
prompt$ env CC=gcc ../dist/configure --enable-smallbuild
prompt$ make

Here is the program to create the database.

main()
{
:
create_db();
:
test_ins()

}

int key_compare(DB *db, const DBT * a, const DBT * b)
{
int v;
unsigned s; /* smaller size */

if ( a->size < b->size ) {
s = a->size;
} else {
s = b->size;
}

v = memcmp(a->data, b->data, s);
if (v == 0) {
/* if first s bytes are same, the longer key is "bigger" */
return (a->size - b->size);
}

return v;
}

int create_db()
{
int flags;
DB_MPOOLFILE *mpf;

err =0;
//err = db_create(&dbp, dbenv, 0);
err = db_create(&dbp, NULL, 0);
if ( err ) return err;

flags = DB_CREATE;//DB_EXCL | DB_CREATE;

err = dbp->set_bt_compare(dbp, key_compare);
if ( err ) {
dbenv->err(dbenv, err, "dbp->set_bt_compare");
dbp->close(dbp, 0);
dbp = NULL;
}

mpf = dbp->mpf;
//mpf->set_flags(mpf, DB_MPOOL_NOFILE, 1);
mpf->set_maxsize(mpf, 0, 20000000);

//err = dbp->open(dbp, NULL, dbfile, NULL, DB_BTREE, flags, 0);
err = dbp->open(dbp, NULL, NULL, NULL, DB_BTREE, flags, 0);
if ( err ) {
dbenv->err(dbenv, err, "dbp->open");
dbp->close(dbp, 0);
dbp = NULL;
}

return err;
}

int test_ins()
{
DB_TXN * tid;
DBT key, data;
int i = 0;

err = 0;
:
if ( err == 0 ) {
while ( i < nr_insert ) {
key.size = strlen(list[i]);
key.data = list[i];
data.size = strlen(list[i]);
data.data = list[i];
if ( logging_enabled ) {
err = dbp->put(dbp, tid, &key, &data, DB_NOOVERWRITE);
}
else { err = dbp->put(dbp, NULL, &key,
&data, DB_NOOVERWRITE)
;
}
if ( err ) {
dbenv->err(dbenv, err, "dbp->put");
break;
}
i++;
}
}

fprintf(stderr, "inserted %d records\n", i);
return err;
}

Please help.
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 4:49 am | All times are GMT
navigation Forum index » Databases » Berkeley DB
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts postfix out of memory error - please help metind Postfix 0 Mon Sep 11, 2006 1:54 am
No new posts Non IBM memory in p630 Ron AIX 0 Fri Jul 21, 2006 2:05 pm
No new posts database Share Memory Limit (2 GB ) in a Instance is tota... sadanjan@gmail.com IBM DB2 0 Fri Jul 21, 2006 12:57 pm
No new posts Bug#379104: ITP: complearn-mpi -- parallel quartet tree s... Rudi Cilibrasi devel 0 Fri Jul 21, 2006 11:30 am
No new posts Where is this code not freeing memory ? jithoosin C++ 2 Fri Jul 21, 2006 9:39 am

Webhosting catalogue | Boston Moving Company | Mobile Phones | Loans | Problem Mortgage
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1492s ][ Queries: 20 (0.0763s) ][ GZIP on - Debug on ]