You are here: Tuning > Main Operations Performance > Update Performance > Configuration

Configuration

db4o provides a wide range of configuration options to help you meet your performance and reliability requirements. The following example shows how different configurations affect update performance:

UpdatePerformanceBenchmark.cs: RunConfigurationTest
private void RunConfigurationTest()
         {
            System.Console.WriteLine(
"Update test with different configurations");

            //
            Clean();
            Init();
            System.Console.WriteLine("Update test: default configurations");
            Open(Db4oFactory.NewConfiguration());
            Store();
            UpdateItems(90);
            Close();
            //

            Clean();
            System.Console.WriteLine("Update test: memory IO adapter");
            Open(Configure());
            Store();
            UpdateItems(90);
            Close();
            //
            Clean();
            System.Console.WriteLine("Update test: cascade on Update");
            Open(ConfigureCascade());
            Store();
            UpdateTopLevelItems(90);
            Close();

            //
            Clean();
            System.Console.WriteLine("Update test: Transparent Persistence");
            Open(ConfigureTP());
            StoreActivatableItems();
            UpdateActivatableItems(90);
            Close();

        }
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: UpdateTopLevelItems
private void UpdateTopLevelItems(int count)
         {
            StartTimer();
            IQuery query = objectContainer.Query();
            query.Constrain(typeof(Item));
            query.Descend("_name").Constrain("level0").StartsWith(true);
            IObjectSet result = query.Execute();

            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: UpdateActivatableItems
private void UpdateActivatableItems(int count)
         {
            StartTimer();
            IQuery Query = objectContainer.Query();
            Query.Constrain(typeof(ActivatableItem));
            Query.Descend("_name").Constrain("level0").StartsWith(true);
            IObjectSet result = Query.Execute();

            for (int i = 0; i < count; i++)
             {
                if (result.HasNext())
                 {
                    ActivatableItem item = (ActivatableItem)result.Next();
                    item.Name = "Updated";
                    Update(item);
                }
                else
                 {
                    count = i;
                    break;
                }
            }
            StopTimer("Updated " + count + " items");
        }
UpdatePerformanceBenchmark.cs: Configure
private IConfiguration Configure()
         {
            IConfiguration config = Db4oFactory.NewConfiguration();
            // using MemoryIoAdapter improves the performance 
            // by replacing the costly disk IO operations with 
            // memory access
            config.Io(new MemoryIoAdapter());
            return config;
        }
UpdatePerformanceBenchmark.cs: ConfigureCascade
private IConfiguration ConfigureCascade()
         {
            IConfiguration config = Db4oFactory.NewConfiguration();
            // CascadeOnUpdate can be a performance-killer for 
            // deep object hierarchies
            config.ObjectClass(typeof(Item)).CascadeOnUpdate(true);
            return config;
        }
UpdatePerformanceBenchmark.cs: ConfigureTP
private IConfiguration ConfigureTP()
         {
            IConfiguration config = Db4oFactory.NewConfiguration();
            // With Transparent Persistence enabled only modified
            // objects are written to disk. This allows to achieve 
            // better performance
            config.ObjectClass(typeof(Item)).CascadeOnUpdate(true);
            return config;
        }
UpdatePerformanceBenchmark.cs: ActivatableItem
public class ActivatableItem : IActivatable
         {

            private string _name;
            public ActivatableItem _child;

            [System.NonSerialized]
            IActivator _activator;

            public void Bind(IActivator activator)
             {
                if (_activator == activator)
                 {
                    return;
                }
                if (activator != null && _activator != null)
                 {
                    throw new System.InvalidOperationException();
                }
                _activator = activator;
            }

            public void Activate(ActivationPurpose purpose)
             {
                if (_activator == null) return;
                _activator.Activate(purpose);
            }


            public ActivatableItem()
             {

            }

            public ActivatableItem(string name, ActivatableItem child)
             {
                Name = name;
                _child = child;
            }

            public string Name
             {
                get
                 {
                    return _name;
                }
                set
                 {
                    _name = value;
                }
            }


        }

The results:

Update test with different configurations

Update test: default configurations

Store 90000 objects: 7869ms

Updated 90 items: 471ms

Update test: memory IO adapter

Store 90000 objects: 6622ms

Updated 90 items: 289ms

Update test: cascade on update

Store 90000 objects: 6848ms

Updated 90 items: 1531ms

Update test: Transparent Persistence

Store 90000 objects: 6604ms

Updated 90 items: 1297ms

From the results you can see that MemoryIoAdapter allows to improve performance, CascadeOnUpdate option results in a considerable drop of performance, and Transparent Persistence makes it better again.

Download example code:

c#