1
0

ObjectPerformanceTests.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. namespace OpenSim.Tests.Performance
  37. {
  38. /// <summary>
  39. /// Object performance tests
  40. /// </summary>
  41. /// <remarks>
  42. /// Don't rely on the numbers given by these tests - they will vary a lot depending on what is already cached,
  43. /// how much memory is free, etc. In some cases, later larger tests will apparently take less time than smaller
  44. /// earlier tests.
  45. /// </remarks>
  46. [TestFixture]
  47. public class ObjectPerformanceTests : OpenSimTestCase
  48. {
  49. [TearDown]
  50. public void TearDown()
  51. {
  52. GC.Collect();
  53. GC.WaitForPendingFinalizers();
  54. }
  55. // [Test]
  56. // public void Test0000Clean()
  57. // {
  58. // TestHelpers.InMethod();
  59. //// log4net.Config.XmlConfigurator.Configure();
  60. //
  61. // TestAddObjects(200000);
  62. // }
  63. [Test]
  64. public void Test_0001_10K_1PrimObjects()
  65. {
  66. TestHelpers.InMethod();
  67. // log4net.Config.XmlConfigurator.Configure();
  68. TestAddObjects(1, 10000);
  69. }
  70. [Test]
  71. public void Test_0002_100K_1PrimObjects()
  72. {
  73. TestHelpers.InMethod();
  74. // log4net.Config.XmlConfigurator.Configure();
  75. TestAddObjects(1, 100000);
  76. }
  77. [Test]
  78. public void Test_0003_200K_1PrimObjects()
  79. {
  80. TestHelpers.InMethod();
  81. // log4net.Config.XmlConfigurator.Configure();
  82. TestAddObjects(1, 200000);
  83. }
  84. [Test]
  85. public void Test_0011_100_100PrimObjects()
  86. {
  87. TestHelpers.InMethod();
  88. // log4net.Config.XmlConfigurator.Configure();
  89. TestAddObjects(100, 100);
  90. }
  91. [Test]
  92. public void Test_0012_1K_100PrimObjects()
  93. {
  94. TestHelpers.InMethod();
  95. // log4net.Config.XmlConfigurator.Configure();
  96. TestAddObjects(100, 1000);
  97. }
  98. [Test]
  99. public void Test_0013_2K_100PrimObjects()
  100. {
  101. TestHelpers.InMethod();
  102. // log4net.Config.XmlConfigurator.Configure();
  103. TestAddObjects(100, 2000);
  104. }
  105. private void TestAddObjects(int primsInEachObject, int objectsToAdd)
  106. {
  107. UUID ownerId = new UUID("F0000000-0000-0000-0000-000000000000");
  108. // Using a local variable for scene, at least on mono 2.6.7, means that it's much more likely to be garbage
  109. // collected when we teardown this test. If it's done in a member variable, even if that is subsequently
  110. // nulled out, the garbage collect can be delayed.
  111. TestScene scene = new SceneHelpers().SetupScene();
  112. // Process process = Process.GetCurrentProcess();
  113. // long startProcessMemory = process.PrivateMemorySize64;
  114. long startGcMemory = GC.GetTotalMemory(true);
  115. DateTime start = DateTime.Now;
  116. for (int i = 1; i <= objectsToAdd; i++)
  117. {
  118. SceneObjectGroup so = SceneHelpers.CreateSceneObject(primsInEachObject, ownerId, "part_", i);
  119. Assert.That(scene.AddNewSceneObject(so, false), Is.True, string.Format("Object {0} was not created", i));
  120. }
  121. TimeSpan elapsed = DateTime.Now - start;
  122. // long processMemoryAlloc = process.PrivateMemorySize64 - startProcessMemory;
  123. long endGcMemory = GC.GetTotalMemory(false);
  124. for (int i = 1; i <= objectsToAdd; i++)
  125. {
  126. Assert.That(
  127. scene.GetSceneObjectGroup(TestHelpers.ParseTail(i)),
  128. Is.Not.Null,
  129. string.Format("Object {0} could not be retrieved", i));
  130. }
  131. // When a scene object is added to a scene, it is placed in the update list for sending to viewers
  132. // (though in this case we have none). When it is deleted, it is not removed from the update which is
  133. // fine since it will later be ignored.
  134. //
  135. // However, that means that we need to manually run an update here to clear out that list so that deleted
  136. // objects will be clean up by the garbage collector before the next stress test is run.
  137. scene.Update(1);
  138. Console.WriteLine(
  139. "Took {0}ms, {1}MB ({2} - {3}) to create {4} objects each containing {5} prim(s)",
  140. Math.Round(elapsed.TotalMilliseconds),
  141. (endGcMemory - startGcMemory) / 1024 / 1024,
  142. endGcMemory / 1024 / 1024,
  143. startGcMemory / 1024 / 1024,
  144. objectsToAdd,
  145. primsInEachObject);
  146. scene.Close();
  147. // scene = null;
  148. }
  149. }
  150. }