kay jean
2004-Dec-15 07:28 UTC
[Xapian-devel] btree function question ?? ( prev charset error , send again )
Hi I just want to study the core of btree function. So I hava a small test program. I try to add different items 1000000 times. (test1 , test1) (test2 , test2) (test3 , test3) .....(test1000000 , test1000000) after that I run the program again and again step 1 , db file size is 54099968 , get_entry_count is 1000000 step 2 , db file size is 108208128 , get_entry_count is 1000255 step 3 , db file size is 108240896 , get_entry_count is 1000868 file size and get_entry_count grows slowly , Is that ok ?? Thanks Hao Kuang , Ku kayjean@gmail.com --------------------------test code is ------------------------ #include "btree.h" using namespace std; int main() { Btree table( "test", false ); if( !table.exists() ) table.create(8192); table.open(); int revision = table.get_open_revision_number(); printf( " revision is %d\n " , revision ); printf( "entry count %d \n" , table.get_entry_count() ); string tag; char temp[1000]; for( int i = 0 ; i < 1000000 ; i++ ) { sprintf( temp , "%i" , i ); tag = "test"; tag.append( temp ); table.add(tag, tag); if( i % 10000 == 0 ) { printf( "%s\n" , tag.c_str() ); printf( "%d\n" , i ); } } table.commit( table.get_open_revision_number() + 1 ); return 0;
Olly Betts
2004-Dec-15 14:03 UTC
[Xapian-devel] btree function question ?? ( prev charset error , send again )
On Wed, Dec 15, 2004 at 03:28:13PM +0800, kay jean wrote:> after that I run the program again and again > > step 1 , db file size is 54099968 , get_entry_count is 1000000 > > step 2 , db file size is 108208128 , get_entry_count is 1000255 > > step 3 , db file size is 108240896 , get_entry_count is 1000868 > > file size and get_entry_count grows slowly , Is that ok ??I don't get the same results at all. If I comment out the two calls to printf in the loop, I get: olly@ixion:~/cvs/xapian/xapian-core/tests $ ./btreet;ls -l testDB revision is 0 entry count 0 -rw-r--r-- 1 olly olly 54099968 Dec 15 11:55 testDB olly@ixion:~/cvs/xapian/xapian-core/tests $ ./btreet;ls -l testDB revision is 1 entry count 1000000 -rw-r--r-- 1 olly olly 108199936 Dec 15 11:55 testDB olly@ixion:~/cvs/xapian/xapian-core/tests $ ./btreet;ls -l testDB revision is 2 entry count 1000000 -rw-r--r-- 1 olly olly 108199936 Dec 15 11:55 testDB Which is what I'd expect. The file size increases after the first revision because the Btree manager needs enough blocks to hold 2 copies of the tree (the old and the new) so it can switch from one to the other atomically. After that it has enough blocks spare to update. So the file size stabilises after 2 updates and the number of entries is always 1000000. I'm using CVS HEAD, but nothing significant has changed in the Btree code since 0.8.4. Cheers, Olly