aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Performance/NPCPerformanceTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests/Performance/NPCPerformanceTests.cs')
-rw-r--r--OpenSim/Tests/Performance/NPCPerformanceTests.cs191
1 files changed, 191 insertions, 0 deletions
diff --git a/OpenSim/Tests/Performance/NPCPerformanceTests.cs b/OpenSim/Tests/Performance/NPCPerformanceTests.cs
new file mode 100644
index 0000000..e222dc2
--- /dev/null
+++ b/OpenSim/Tests/Performance/NPCPerformanceTests.cs
@@ -0,0 +1,191 @@
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
28using System;
29using System.Collections.Generic;
30using System.Diagnostics;
31using System.Reflection;
32using log4net;
33using Nini.Config;
34using NUnit.Framework;
35using OpenMetaverse;
36using OpenSim.Framework;
37using OpenSim.Framework.Communications;
38using OpenSim.Region.CoreModules.Avatar.Attachments;
39using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
40using OpenSim.Region.CoreModules.Framework.InventoryAccess;
41using OpenSim.Region.CoreModules.Framework.UserManagement;
42using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar;
43using OpenSim.Region.Framework.Interfaces;
44using OpenSim.Region.Framework.Scenes;
45using OpenSim.Region.OptionalModules.World.NPC;
46using OpenSim.Services.AvatarService;
47using OpenSim.Tests.Common;
48
49namespace OpenSim.Tests.Performance
50{
51 /// <summary>
52 /// NPC performance tests
53 /// </summary>
54 /// <remarks>
55 /// Don't rely on the numbers given by these tests - they will vary a lot depending on what is already cached,
56 /// how much memory is free, etc. In some cases, later larger tests will apparently take less time than smaller
57 /// earlier tests.
58 /// </remarks>
59 [TestFixture]
60 public class NPCPerformanceTests : OpenSimTestCase
61 {
62 private TestScene scene;
63 private AvatarFactoryModule afm;
64 private UserManagementModule umm;
65 private AttachmentsModule am;
66
67 [TestFixtureSetUp]
68 public void FixtureInit()
69 {
70 // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
71 Util.FireAndForgetMethod = FireAndForgetMethod.None;
72 }
73
74 [TestFixtureTearDown]
75 public void TearDown()
76 {
77 scene.Close();
78 scene = null;
79 GC.Collect();
80 GC.WaitForPendingFinalizers();
81
82 // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
83 // threads. Possibly, later tests should be rewritten not to worry about such things.
84 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
85 }
86
87 [SetUp]
88 public void Init()
89 {
90 IConfigSource config = new IniConfigSource();
91 config.AddConfig("NPC");
92 config.Configs["NPC"].Set("Enabled", "true");
93 config.AddConfig("Modules");
94 config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
95
96 afm = new AvatarFactoryModule();
97 umm = new UserManagementModule();
98 am = new AttachmentsModule();
99
100 scene = new SceneHelpers().SetupScene();
101 SceneHelpers.SetupSceneModules(scene, config, afm, umm, am, new BasicInventoryAccessModule(), new NPCModule());
102 }
103
104 [Test]
105 public void Test_0001_AddRemove100NPCs()
106 {
107 TestHelpers.InMethod();
108// log4net.Config.XmlConfigurator.Configure();
109
110 TestAddRemoveNPCs(100);
111 }
112
113 [Test]
114 public void Test_0002_AddRemove1000NPCs()
115 {
116 TestHelpers.InMethod();
117// log4net.Config.XmlConfigurator.Configure();
118
119 TestAddRemoveNPCs(1000);
120 }
121
122 [Test]
123 public void Test_0003_AddRemove2000NPCs()
124 {
125 TestHelpers.InMethod();
126// log4net.Config.XmlConfigurator.Configure();
127
128 TestAddRemoveNPCs(2000);
129 }
130
131 private void TestAddRemoveNPCs(int numberOfNpcs)
132 {
133 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
134// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
135
136 // 8 is the index of the first baked texture in AvatarAppearance
137 UUID originalFace8TextureId = TestHelpers.ParseTail(0x10);
138 Primitive.TextureEntry originalTe = new Primitive.TextureEntry(UUID.Zero);
139 Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8);
140 originalTef.TextureID = originalFace8TextureId;
141
142 // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell
143 // ScenePresence.SendInitialData() to reset our entire appearance.
144 scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId));
145
146/*
147 afm.SetAppearance(sp, originalTe, null);
148
149 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
150
151 List<UUID> npcs = new List<UUID>();
152
153 long startGcMemory = GC.GetTotalMemory(true);
154 Stopwatch sw = new Stopwatch();
155 sw.Start();
156
157 for (int i = 0; i < numberOfNpcs; i++)
158 {
159 npcs.Add(
160 npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance));
161 }
162
163 for (int i = 0; i < numberOfNpcs; i++)
164 {
165 Assert.That(npcs[i], Is.Not.Null);
166
167 ScenePresence npc = scene.GetScenePresence(npcs[i]);
168 Assert.That(npc, Is.Not.Null);
169 }
170
171 for (int i = 0; i < numberOfNpcs; i++)
172 {
173 Assert.That(npcModule.DeleteNPC(npcs[i], scene), Is.True);
174 ScenePresence npc = scene.GetScenePresence(npcs[i]);
175 Assert.That(npc, Is.Null);
176 }
177
178 sw.Stop();
179
180 long endGcMemory = GC.GetTotalMemory(true);
181
182 Console.WriteLine("Took {0} ms", sw.ElapsedMilliseconds);
183 Console.WriteLine(
184 "End {0} MB, Start {1} MB, Diff {2} MB",
185 endGcMemory / 1024 / 1024,
186 startGcMemory / 1024 / 1024,
187 (endGcMemory - startGcMemory) / 1024 / 1024);
188*/
189 }
190 }
191}