Sophie

Sophie

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

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" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>Update Performance	</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.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><span class="MCBreadcrumbs">Update Performance	</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><a name="kanchor116"></a>Update Performance</h1>
        <p>Update performance is influenced by the similar factors as
<a href="insert_performance.htm">Insert Performance</a>. The main factors include: configuration, disk access
times, complexity of objects. </p>
        <p>The following chapters provide some simple tests showing the
influence of the above-mentioned factors. The test results are provided for
Toshiba Sattelite Pro A120 notebook with 1,5Gb RAM 120GB ATA drive running on Vista and may be different on a different environment.</p>
        <p>The following Item class is used in most of the tests:</p>
        <p MadCap:conditions="Global.Primary:java" />
        <p MadCap:conditions="Primary..NET">
            <pre class="prettyprint" xml:space="preserve">UpdatePerformanceBenchmark.cs: Item
private void Update(Object item)
         {
            objectContainer.Store(item);
        }
        // end Update


        private void RunDifferentObjectsTest()
         {
            System.Console.WriteLine("Update test with different objects");
            int objectsToUpdate = 90;
            int updated = objectsToUpdate;

            InitDifferentObjectsTest();

            Clean();
            System.Console.WriteLine(" - primitive object with int field");
            Open(Configure());
            StoreSimplest();

            IObjectSet result = objectContainer.QueryByExample(null);
            StartTimer();
            for (int i = 0; i &lt; objectsToUpdate; i++)
             {
                if (result.HasNext())
                 {
                    SimplestItem item = (SimplestItem)result.Next();
                    item._id = 1;
                    Update(item);
                }
                else
                 {
                    updated = i;
                    break;
                }
            }
            StopTimer("Updated " + updated + " items");
            Close();

            Clean();
            Open(Configure());
            System.Console.WriteLine(" - object with string field");
            Store();
            updated = objectsToUpdate;
            result = objectContainer.QueryByExample(null);
            StartTimer();
            for (int i = 0; i &lt; objectsToUpdate; i++)
             {
                if (result.HasNext())
                 {
                    Item item = (Item)result.Next();
                    item._name = "Updated";
                    Update(item);
                }
                else
                 {
                    updated = i;
                    break;
                }
            }
            StopTimer("Updated " + updated + " items");
            Close();

            Clean();
            Open(Configure());
            System.Console.WriteLine(" - object with StringBuilder field");
            StoreWithStringBuilder();

            updated = objectsToUpdate;
            result = objectContainer.QueryByExample(null);
            StartTimer();
            for (int i = 0; i &lt; objectsToUpdate; i++)
             {
                if (result.HasNext())
                 {
                    ItemWithStringBuilder item = (ItemWithStringBuilder)result.Next();
                    item._name = new StringBuilder("Updated");
                    Update(item);
                }
                else
                 {
                    updated = i;
                    break;
                }
            }
            StopTimer("Updated " + updated + " items");
            Close();

            Clean();
            Open(Configure());
            System.Console.WriteLine(" - object with int array field");
            StoreWithArray();
            updated = objectsToUpdate;
            result = objectContainer.QueryByExample(null);
            StartTimer();
            for (int i = 0; i &lt; objectsToUpdate; i++)
             {
                if (result.HasNext())
                 {
                    ItemWithArray item = (ItemWithArray)result.Next();
                    item._id = new int[]  { 1, 2, 3 };
                    Update(item);
                }
                else
                 {
                    updated = i;
                    break;
                }
            }
            StopTimer("Updated " + updated + " items");
            Close();

            Clean();
            Open(Configure());
            System.Console.WriteLine(" - object with ArrayList field");
            StoreWithArrayList();
            updated = objectsToUpdate;
            result = objectContainer.QueryByExample(null);
            StartTimer();
            for (int i = 0; i &lt; objectsToUpdate; i++)
             {
                if (result.HasNext())
                 {
                    ItemWithArrayList item = (ItemWithArrayList)result.Next();
                    item._ids = new ArrayList();
                    Update(item);
                }
                else
                 {
                    updated = i;
                    break;
                }
            }
            StopTimer("Updated " + updated + " items");
            Close();
        }
        // end RunDifferentObjectsTest


        private void RunIndexTest()
         {
            System.Console.WriteLine("Update test for objects with and without indexed fields");

            int objectsToUpdate = 100;
            Init();
            System.Console.WriteLine("Updating " + objectsToUpdate + " of " + _count + " objects");
            Clean();
            Open(Configure());
            Store();
            UpdateItems(objectsToUpdate);
            Close();

            Clean();
            Init();
            System.Console.WriteLine("Updating " + objectsToUpdate + " of " + _count + " objects with indexed field");
            Open(ConfigureIndexTest());
            Store();
            UpdateItems(objectsToUpdate);
            Close();
        }
        // end RunIndexTest


        private void Init()
         {
            _count = 1000;
            _depth = 90;
            _isClientServer = false;

        }
        // end Init

        private void InitDifferentObjectsTest()
         {
            _count = 1000;
            _depth = 1;
            _isClientServer = false;

        }
        // end InitDifferentObjectsTest


        private void InitForClientServer()
         {
            _count = 1000;
            _depth = 90;
            _isClientServer = true;
            _host = "localhost";
        }
        // end InitForClientServer

        private void InitForRamDriveTest()
         {
            _count = 30000;
            _depth = 1;
            _filePath = "r:\\performance.db4o";
            _isClientServer = false;

        }
        // end InitForRamDriveTest

        private void InitForHardDriveTest()
         {
            _count = 10000;
            _depth = 3;
            _filePath = "performance.db4o";
            _isClientServer = false;
        }
        // end InitForHardDriveTest

        private void InitForCommitTest()
         {
            _count = 10000;
            _commitInterval = 1000;
            _depth = 3;
            _isClientServer = false;
        }
        // end InitForCommitTest

        private void Clean()
         {
            File.Delete(_filePath);
        }
        // end Clean

        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;
        }
        // end Configure

        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;
        }
        // end ConfigureTP

        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;
        }
        // end ConfigureCascade

        private IConfiguration ConfigureIndexTest()
         {
            IConfiguration config = Db4oFactory.NewConfiguration();
            config.Io(new MemoryIoAdapter());
            config.ObjectClass(typeof(Item)).ObjectField("_name").Indexed(true);
            return config;
        }
        // end ConfigureIndexTest

        private IConfiguration ConfigureForCommitTest()
         {
            IConfiguration config = Db4oFactory.NewConfiguration();
            // the Commit information is physically written 
            // and in the correct order
            config.FlushFileBuffers(true);
            return config;
        }
        // end ConfigureForCommitTest

        private IConfiguration ConfigureClientServer()
         {
            IConfiguration config = Db4oFactory.NewConfiguration();
            config.ClientServer().SingleThreadedClient(true);
            return config;
        }
        // end ConfigureClientServer

        private IConfiguration ConfigureDriveTest()
         {
            IConfiguration config = Db4oFactory.NewConfiguration();
            config.FlushFileBuffers(true);
            return config;
        }
        // end ConfigureDriveTest

        private void Store()
         {
            StartTimer();
            for (int i = 0; i &lt; _count; i++)
             {
                Item item = new Item("level" + i, null);
                for (int j = 1; j &lt; _depth; j++)
                 {
                    item = new Item("level" + i + "/" + j, item);
                }
                objectContainer.Store(item);
            }
            objectContainer.Commit();
            StopTimer("Store " + TotalObjects() + " objects");
        }
        // end Store

        private void StoreActivatableItems()
         {
            StartTimer();
            for (int i = 0; i &lt; _count; i++)
             {
                ActivatableItem item = new ActivatableItem("level" + i, null);
                for (int j = 1; j &lt; _depth; j++)
                 {
                    item = new ActivatableItem("level" + i + "/" + j, item);
                }
                objectContainer.Store(item);
            }
            objectContainer.Commit();
            StopTimer("Store " + TotalObjects() + " objects");
        }
        // end StoreActivatableItems

        private void StoreInherited()
         {
            StartTimer();
            for (int i = 0; i &lt; _count; i++)
             {
                ItemDerived item = new ItemDerived("level" + i, null);
                for (int j = 1; j &lt; _depth; j++)
                 {
                    item = new ItemDerived("level" + i + "/" + j, item);
                }
                objectContainer.Store(item);
            }
            objectContainer.Commit();
            StopTimer("Store " + TotalObjects() + " objects");
        }
        // end StoreInherited


        private void StoreWithStringBuilder()
         {
            StartTimer();
            for (int i = 0; i &lt; _count; i++)
             {
                ItemWithStringBuilder item = new ItemWithStringBuilder(new StringBuilder("level" + i), null);
                for (int j = 1; j &lt; _depth; j++)
                 {
                    item = new ItemWithStringBuilder(new StringBuilder("level" + i + "/" + j), item);
                }
                objectContainer.Store(item);
            }
            objectContainer.Commit();
            StopTimer("Store " + TotalObjects() + " objects");
        }
        // end StoreWithStringBuilder

        private void StoreSimplest()
         {
            StartTimer();
            for (int i = 0; i &lt; _count; i++)
             {
                SimplestItem item = new SimplestItem(i, null);
                for (int j = 1; j &lt; _depth; j++)
                 {
                    item = new SimplestItem(i, item);
                }
                objectContainer.Store(item);
            }
            objectContainer.Commit();
            StopTimer("Store " + TotalObjects() + " objects");
        }
        // end StoreSimplest

        private void StoreWithArray()
         {
            StartTimer();
            int[] array = new int[]  { 1, 2, 3, 4 };
            for (int i = 0; i &lt; _count; i++)
             {
                int[] id = new int[]  { 1, 2, 3, 4 };
                ItemWithArray item = new ItemWithArray(id, null);
                for (int j = 1; j &lt; _depth; j++)
                 {
                    int[] id1 = new int[]  { 1, 2, 3, 4 };
                    item = new ItemWithArray(id1, item);
                }
                objectContainer.Store(item);
            }
            objectContainer.Commit();
            StopTimer("Store " + TotalObjects() + " objects");
        }
        // end StoreWithArray

        private void StoreWithArrayList()
         {
            StartTimer();
            ArrayList idList = new ArrayList();
            idList.Add(1);
            idList.Add(2);
            idList.Add(3);
            idList.Add(4);
            for (int i = 0; i &lt; _count; i++)
             {
                ArrayList ids = new ArrayList();
                ids.AddRange(idList);
                ItemWithArrayList item = new ItemWithArrayList(ids, null);
                for (int j = 1; j &lt; _depth; j++)
                 {
                    ArrayList ids1 = new ArrayList();
                    ids1.AddRange(idList);
                    item = new ItemWithArrayList(ids1, item);
                }
                objectContainer.Store(item);
            }
            objectContainer.Commit();
            StopTimer("Store " + TotalObjects() + " objects");
        }
        // end StoreWithArrayList

        private int TotalObjects()
         {
            return _count * _depth;
        }
        // end TotalObjects

        private void Open(IConfiguration config)
         {
            if (_isClientServer)
             {
                int port = TCP ? PORT : 0;
                string user = "db4o";
                string password = user;
                objectServer = Db4oFactory.OpenServer(_filePath, port);
                objectServer.GrantAccess(user, password);
                objectContainer = TCP ? Db4oFactory.OpenClient(_host, port, user,
                        password) : objectServer.OpenClient();
            }
            else
             {
                objectContainer = Db4oFactory.OpenFile(config, _filePath);
            }
        }
        // end Open

        private void Close()
         {
            objectContainer.Close();
            if (_isClientServer)
             {
                objectServer.Close();
            }
        }
        //end Close

        private void StartTimer()
         {
            _startTime = DateTime.Now.Ticks;
        }
        // end StartTimer

        private void StopTimer(string message)
         {
            long stop = DateTime.Now.Ticks;
            long duration = stop - _startTime;
            System.Console.WriteLine(message + ": " + duration + " ticks");
        }
        // end StopTimer

        public class Item
         {

            public string _name;
            public Item _child;

            public Item()
             {

            }

            public Item(string name, Item child)
             {
                _name = name;
                _child = child;
            }
        }</pre>
        </p>
        <p MadCap:conditions="Global.Primary:net" />
        <p> More Reading:<ul><li value="1"><p><a href="update_performance/configuration.htm">Configuration</a></p></li><li value="2"><p><a href="update_performance/object_structure.htm">Object Structure</a></p></li><li value="3"><p><a href="update_performance/commit_frequency.htm">Commit Frequency</a></p></li><li value="4"><p><a href="update_performance/hard_drive_speed.htm">Hard Drive Speed</a></p></li><li value="5"><p><a href="update_performance/client-server.htm">Client-Server</a></p></li><li value="6"><p><a href="update_performance/indexes.htm">Indexes</a></p></li><li value="7"><p><a href="update_performance/inheritance.htm">Inheritance</a></p></li></ul></p>
        <script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>