You are here: Tuning > Main Operations Performance > Query Performance > Database Size

Database Size

Query performance can degrade with the amount of objects of the queried type:

QueryPerformanceBenchmark.cs: RunQueryAmountOfObjectsTest
private void RunQueryAmountOfObjectsTest()
         {
            Init();
            Clean();
            System.Console.WriteLine("Storing " + _count + 
" of  objects of depth " + _depth);
            Open(Configure());
            Store();
            Close();

            //
            Open(Configure());
            StartTimer();
            IQuery query = objectContainer.Query();
            query.Constrain(typeof(Item));
            query.Descend("_name").Constrain("level1/1");
            Item item = (Item)query.Execute().Next();
            StopTimer("Select 1 object SODA: " + item._name);
            System.Console.WriteLine(
"Add some objects of another type and check the query time again:");
        StoreWithArray();
        Close();
        //
        Open(Configure());
        StartTimer();
        query = objectContainer.Query();
        query.Constrain(typeof(Item));
        query.Descend("_name").Constrain("level1/1");
        item = (Item) query.Execute().Next();
        StopTimer("Select 1 object SODA: " + item._name);
        Close();
    
    
        // Add many objects of the same type
            InitLargeDb();
            Clean();
            System.Console.WriteLine("Storing " + _count + 
" of  objects of depth " + _depth);
            Open(Configure());
            Store();
            Close();

            //
            Open(Configure());
            StartTimer();
            query = objectContainer.Query();
            query.Constrain(typeof(Item));
            query.Descend("_name").Constrain("level1/1");
            item = (Item)query.Execute().Next();
            StopTimer("Select 1 object SODA: " + item._name);
            Close();
        }
QueryPerformanceBenchmark.cs: Init
private void Init()
         {
            _filePath = "performance.db4o";
            // amount of objects
            _count = 10000;
            // depth of objects
            _depth = 3;
            _isClientServer = false;

        }
QueryPerformanceBenchmark.cs: InitLargeDb
private void InitLargeDb()
         {
            _filePath = "performance.db4o";
            _count = 100000;
            _depth = 3;
            _isClientServer = false;

        }
QueryPerformanceBenchmark.cs: Configure
private IConfiguration Configure()
         {
            IConfiguration config = Db4oFactory.NewConfiguration();
            return config;
        }

However, the general size of the database, i.e. amount of other type of objects in the database should not have any impact on the query performance.

Results from the test machine:

Storing 10000 of objects of depth 3

Store 30000 objects: 3305ms

Select 1 object SODA: level1/1: 464ms

Storing 100000 of objects of depth 3

Store 300000 objects: 21338ms

Select 1 object SODA: level1/1: 5316ms

Download example code:

c#