You are here: Tuning > Main Operations Performance > Update Performance > Commit Frequency

Commit Frequency

Commit frequency has a direct impact on db4o performance. Commit is an expensive operation due to physical disk access. However, commit is also the only way to ensure that the whole transaction is stored safely on the disk and no data loss will occur in case of unexpected system failure.

The following test shows how commit frequency influences the performance on update:

UpdatePerformanceBenchmark.cs: RunCommitTest
private void RunCommitTest()
         {
            System.Console.WriteLine(
"Update test with different Commit frequency");

            InitForCommitTest();

            Clean();
            System.Console.WriteLine("Test Update all:");
            Open(ConfigureForCommitTest());
            Store();
            UpdateItems(_count);
            Close();



            Clean();
            System.Console.WriteLine(
"Test Update all with Commit after each " + _commitInterval + " objects:");
            Open(ConfigureForCommitTest());
            Store();
            UpdateWithCommit(_count);
            Close();


        }
UpdatePerformanceBenchmark.cs: ConfigureForCommitTest
private IConfiguration ConfigureForCommitTest()
         {
            IConfiguration config = Db4oFactory.NewConfiguration();
            // the Commit information is physically written 
            // and in the correct order
            config.FlushFileBuffers(true);
            return config;
        }
UpdatePerformanceBenchmark.cs: UpdateItems
private void UpdateItems(int count)
         {
            StartTimer();
            IObjectSet result = objectContainer.QueryByExample(null);

            for (int i = 0; i < count; i++)
             {
                if (result.HasNext())
                 {
                    Item item = (Item)result.Next();
                    item._name = "Updated";
                    Update(item);
                }
                else
                 {
                    count = i;
                    break;
                }
            }
            StopTimer("Updated " + count + " items");
        }
UpdatePerformanceBenchmark.cs: UpdateWithCommit
private void UpdateWithCommit(int count)
         {
            StartTimer();
            IObjectSet result = objectContainer.QueryByExample(null);
            int j = 0;
            for (int i = 0; i < count; i++)
             {
                if (result.HasNext())
                 {
                    Item item = (Item)result.Next();
                    item._name = "Updated";
                    Update(item);
                    if (j >= _commitInterval)
                     {
                        j = 0;
                        objectContainer.Commit();
                    }
                    else
                     {
                        j++;
                    }
                }
                else
                 {
                    count = i;
                    break;
                }
            }
            StopTimer("Updated " + count + " items ");
        }

The results:

Update test with different commit frequency

Test update all:

Store 30000 objects: 2661ms

Updated 10000 items: 1402ms

Test update all with commit after each 1000 objects:

Store 30000 objects: 2250ms

Updated 10000 items : 2812ms

Download example code:

c#