opensim-development – Blame information for rev 1

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