From e67705ed6348675b7bae405ebeb37bb69b53a96d Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Wed, 4 Nov 2015 15:12:18 -0800 Subject: do not grow dbsize agressively Only grow the database size when the high watermark increases. We also grows the database size a little bit aggressively to save a few ftruncates. I have tested this on various environments. The performance impact is ignorable with 16MB over allocation. Without over allocation, the performance might decrease 100% when each Tx.Commit needs a new page on a very slow disk (seek time dominates the total write). --- db_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'db_test.go') diff --git a/db_test.go b/db_test.go index ae21938..0f89c33 100644 --- a/db_test.go +++ b/db_test.go @@ -100,6 +100,8 @@ func TestOpen_Size(t *testing.T) { path := db.Path() defer db.Close() + pagesize := db.Info().PageSize + // Insert until we get above the minimum 4MB size. ok(t, db.Update(func(tx *bolt.Tx) error { b, _ := tx.CreateBucketIfNotExists([]byte("data")) @@ -127,7 +129,8 @@ func TestOpen_Size(t *testing.T) { } // Compare the original size with the new size. - if sz != newSz { + // db size might increase by a few page sizes due to the new small update. + if sz < newSz-5*int64(pagesize) { t.Fatalf("unexpected file growth: %d => %d", sz, newSz) } } @@ -144,6 +147,8 @@ func TestOpen_Size_Large(t *testing.T) { path := db.Path() defer db.Close() + pagesize := db.Info().PageSize + // Insert until we get above the minimum 4MB size. var index uint64 for i := 0; i < 10000; i++ { @@ -177,7 +182,8 @@ func TestOpen_Size_Large(t *testing.T) { } // Compare the original size with the new size. - if sz != newSz { + // db size might increase by a few page sizes due to the new small update. + if sz < newSz-5*int64(pagesize) { t.Fatalf("unexpected file growth: %d => %d", sz, newSz) } } -- cgit v1.2.3