ObjectPerformanceTests.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Diagnostics;
  29. using System.Reflection;
  30. using log4net;
  31. using NUnit.Framework;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Framework.Scenes;
  35. using OpenSim.Tests.Common;
  36. using OpenSim.Tests.Common.Mock;
  37. namespace OpenSim.Tests.Performance
  38. {
  39. /// <summary>
  40. /// Object performance tests
  41. /// </summary>
  42. /// <remarks>
  43. /// Don't rely on the numbers given by these tests - they will vary a lot depending on what is already cached,
  44. /// how much memory is free, etc. In some cases, later larger tests will apparently take less time than smaller
  45. /// earlier tests.
  46. /// </remarks>
  47. [TestFixture]
  48. public class ObjectPerformanceTests
  49. {
  50. [TearDown]
  51. public void TearDown()
  52. {
  53. GC.Collect();
  54. GC.WaitForPendingFinalizers();
  55. }
  56. // [Test]
  57. // public void Test0000Clean()
  58. // {
  59. // TestHelpers.InMethod();
  60. //// log4net.Config.XmlConfigurator.Configure();
  61. //
  62. // TestAddObjects(200000);
  63. // }
  64. [Test]
  65. public void Test_0001_10K_1PrimObjects()
  66. {
  67. TestHelpers.InMethod();
  68. // log4net.Config.XmlConfigurator.Configure();
  69. TestAddObjects(1, 10000);
  70. }
  71. [Test]
  72. public void Test_0002_100K_1PrimObjects()
  73. {
  74. TestHelpers.InMethod();
  75. // log4net.Config.XmlConfigurator.Configure();
  76. TestAddObjects(1, 100000);
  77. }
  78. [Test]
  79. public void Test_0003_200K_1PrimObjects()
  80. {
  81. TestHelpers.InMethod();
  82. // log4net.Config.XmlConfigurator.Configure();
  83. TestAddObjects(1, 200000);
  84. }
  85. [Test]
  86. public void Test_0011_100_100PrimObjects()
  87. {
  88. TestHelpers.InMethod();
  89. // log4net.Config.XmlConfigurator.Configure();
  90. TestAddObjects(100, 100);
  91. }
  92. [Test]
  93. public void Test_0012_1K_100PrimObjects()
  94. {
  95. TestHelpers.InMethod();
  96. // log4net.Config.XmlConfigurator.Configure();
  97. TestAddObjects(100, 1000);
  98. }
  99. [Test]
  100. public void Test_0013_2K_100PrimObjects()
  101. {
  102. TestHelpers.InMethod();
  103. // log4net.Config.XmlConfigurator.Configure();
  104. TestAddObjects(100, 2000);
  105. }
  106. private void TestAddObjects(int primsInEachObject, int objectsToAdd)
  107. {
  108. UUID ownerId = new UUID("F0000000-0000-0000-0000-000000000000");
  109. // Using a local variable for scene, at least on mono 2.6.7, means that it's much more likely to be garbage
  110. // collected when we teardown this test. If it's done in a member variable, even if that is subsequently
  111. // nulled out, the garbage collect can be delayed.
  112. TestScene scene = new SceneHelpers().SetupScene();
  113. // Process process = Process.GetCurrentProcess();
  114. // long startProcessMemory = process.PrivateMemorySize64;
  115. long startGcMemory = GC.GetTotalMemory(true);
  116. DateTime start = DateTime.Now;
  117. for (int i = 1; i <= objectsToAdd; i++)
  118. {
  119. SceneObjectGroup so = SceneHelpers.CreateSceneObject(primsInEachObject, ownerId, "part_", i);
  120. Assert.That(scene.AddNewSceneObject(so, false), Is.True, string.Format("Object {0} was not created", i));
  121. }
  122. TimeSpan elapsed = DateTime.Now - start;
  123. // long processMemoryAlloc = process.PrivateMemorySize64 - startProcessMemory;
  124. long endGcMemory = GC.GetTotalMemory(false);
  125. for (int i = 1; i <= objectsToAdd; i++)
  126. {
  127. Assert.That(
  128. scene.GetSceneObjectGroup(TestHelpers.ParseTail(i)),
  129. Is.Not.Null,
  130. string.Format("Object {0} could not be retrieved", i));
  131. }
  132. // When a scene object is added to a scene, it is placed in the update list for sending to viewers
  133. // (though in this case we have none). When it is deleted, it is not removed from the update which is
  134. // fine since it will later be ignored.
  135. //
  136. // However, that means that we need to manually run an update here to clear out that list so that deleted
  137. // objects will be clean up by the garbage collector before the next stress test is run.
  138. scene.Update(1);
  139. Console.WriteLine(
  140. "Took {0}ms, {1}MB ({2} - {3}) to create {4} objects each containing {5} prim(s)",
  141. Math.Round(elapsed.TotalMilliseconds),
  142. (endGcMemory - startGcMemory) / 1024 / 1024,
  143. endGcMemory / 1024 / 1024,
  144. startGcMemory / 1024 / 1024,
  145. objectsToAdd,
  146. primsInEachObject);
  147. scene.Close();
  148. // scene = null;
  149. }
  150. }
  151. }