Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 2e9c43658e374d290a2de15d25134ac8 > files > 913

db4o-doc-8.0-1.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="Tuning|Main Operations Performance|Update Performance" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>Configuration	</title>
        <script type="text/javascript">/* <![CDATA[ */
window.onload = function(){
	var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf';
	ZeroClipboard.setMoviePath(pathToFlash);
			
	function bindToClipBord(element,content){
		var clip = new ZeroClipboard.Client();
		clip.setText(content);
		clip.glue(element);
	};
		
	if(location.protocol==='file:'){
		$('.copylink-marker').remove();
	} else{
			$('.copylink-marker').each(function(){
				var text = $(this).parent().parent().children('.prettyprint').html();
				$(this).hover(function(){
					bindToClipBord(this,text);
				},
				function(){});
			});	
	}		
	prettyPrint();	
};
                /* ]]> */</script>
        <link href="../../../SkinSupport/MadCap.css" rel="stylesheet" />
        <link href="../../../Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" />
        <script src="../../../Resources/Code/prettify.js">
        </script>
        <script src="../../../Resources/Code/lang-vb.js">
        </script>
        <script src="../../../Resources/Code/jquery.min.js">
        </script>
        <script src="../../../Resources/Code/ZeroClipboard.js">
        </script>
        <script src="../../../SkinSupport/MadCapAll.js" type="text/javascript">
        </script>
    </head>
    <body>
        <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../../../index_CSH.html#tuning/main_operations_performance/update_performance/configuration.htm" style="">Open topic with navigation</a>
        </p>
        <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../../../tuning.htm">Tuning</a><span class="MCBreadcrumbsDivider"> &gt; </span><a class="MCBreadcrumbsLink" href="../../main_operations_performance.htm">Main Operations Performance</a><span class="MCBreadcrumbsDivider"> &gt; </span><a class="MCBreadcrumbsLink" href="../update_performance.htm">Update Performance</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">Configuration</span>
        </div>
        <p>
            <script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">');
				document.write("Direct Link");
			document.write('</a>');/*]]>*/</script>
        </p>
        <p>
        </p>
        <h1>Configuration</h1>
        <P>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:</P>
        <p MadCap:conditions="Global.Primary:java" />
        <p MadCap:conditions="Primary..NET">
            <pre class="prettyprint" xml:space="preserve">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();

        }</pre>
            <pre class="prettyprint" xml:space="preserve">UpdatePerformanceBenchmark.cs: UpdateItems
private void UpdateItems(int count)
         {
            StartTimer();
            IObjectSet result = objectContainer.QueryByExample(null);

            for (int i = 0; i &lt; count; i++)
             {
                if (result.HasNext())
                 {
                    Item item = (Item)result.Next();
                    item._name = "Updated";
                    Update(item);
                }
                else
                 {
                    count = i;
                    break;
                }
            }
            StopTimer("Updated " + count + " items");
        }</pre>
            <pre class="prettyprint" xml:space="preserve">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 &lt; count; i++)
             {
                if (result.HasNext())
                 {
                    Item item = (Item)result.Next();
                    item._name = "Updated";
                    Update(item);
                }
                else
                 {
                    count = i;
                    break;
                }
            }
            StopTimer("Updated " + count + " items");
        }</pre>
            <pre class="prettyprint" xml:space="preserve">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 &lt; count; i++)
             {
                if (result.HasNext())
                 {
                    ActivatableItem item = (ActivatableItem)result.Next();
                    item.Name = "Updated";
                    Update(item);
                }
                else
                 {
                    count = i;
                    break;
                }
            }
            StopTimer("Updated " + count + " items");
        }</pre>
            <pre class="prettyprint" xml:space="preserve">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;
        }</pre>
            <pre class="prettyprint" xml:space="preserve">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;
        }</pre>
            <pre class="prettyprint" xml:space="preserve">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;
        }</pre>
            <pre class="prettyprint" xml:space="preserve">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 &amp;&amp; _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;
                }
            }


        }</pre>
        </p>
        <p MadCap:conditions="Global.Primary:net" />
        <P>The results:</P>
        <P>
            <I>Update test with different configurations</I>
        </P>
        <P>
            <I>Update test: default configurations</I>
        </P>
        <P>
            <I>Store 90000 objects: 7869ms</I>
        </P>
        <P>
            <I>Updated 90 items: 471ms</I>
        </P>
        <P>
            <I>Update test: memory IO adapter</I>
        </P>
        <P>
            <I>Store 90000 objects: 6622ms</I>
        </P>
        <P>
            <I>Updated 90 items: 289ms</I>
        </P>
        <P>
            <I>Update test: cascade on update</I>
        </P>
        <P>
            <I>Store 90000 objects: 6848ms</I>
        </P>
        <P>
            <I>Updated 90 items: 1531ms</I>
        </P>
        <P>
            <I>Update test: Transparent Persistence</I>
        </P>
        <P>
            <I>Store 90000 objects: 6604ms</I>
        </P>
        <P>
            <I>Updated 90 items: 1297ms</I>
        </P>
        <P>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.</P>
        <p MadCap:conditions="Primary.Online">Download example code:</p>
        <p MadCap:conditions="Primary.Online">
            <MadCap:conditionalText MadCap:conditions="Primary..NET,Primary.c#,Primary.All languages"><a href="updateperformancecs.zip">c# </a>
            </MadCap:conditionalText>
        </p>
        <script type="text/javascript" src="../../../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>