You are here: Tuning > Main Operations Performance > Query Performance > Hardware Resources

Hardware Resources

Effective querying requires enough operating memory and quick hard drive access. Hard drive access time is important as the object will be read from the physical location into the operating memory. However, hard drive speed is not so critical for querying as it is for inserting.

The following test uses a RAM drive to compare test results with the hard drive:

QueryPerformanceBenchmark.cs: RunRamDiskTest
private void RunRamDiskTest()
         {

            InitForHardDriveTest();
            Clean();
            System.Console.WriteLine("Storing " + _count + 
" objects of depth " + _depth
                    + " on a hard drive:");
            Open(ConfigureRamDrive());
            Store();
            Close();
            Open(ConfigureRamDrive());
            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: " + item._name);
            Close();

            InitForRamDriveTest();
            Clean();
            System.Console.WriteLine("Storing " + _count + 
" objects of depth " + _depth
                    + " on a RAM disk:");
            Open(ConfigureRamDrive());
            Store();
            Close();
            Open(ConfigureRamDrive());
            StartTimer();
            query = objectContainer.Query();
            query.Constrain(typeof(Item));
            query.Descend("_name").Constrain("level1/1");
            item = (Item)query.Execute().Next();
            StopTimer("Select 1 object: " + item._name);
            Close();
        }
QueryPerformanceBenchmark.cs: InitForHardDriveTest
private void InitForHardDriveTest()
         {
            _count = 10000;
            _depth = 3;
            _filePath = "performance.db4o";
            _isClientServer = false;

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

Test results:

Storing 30000 objects of depth 3 on a hard drive:

Store 90000 objects: 6019ms

Select 1 object: level1/1: 1515ms

Storing 30000 objects of depth 3 on a RAM disk:

Store 90000 objects: 5264ms

Select 1 object: level1/1: 1518ms

You can see that the difference in query performance is negligible.

Download example code:

c#