From 77e48a6725ccc30d33596b4f8c3dcdc956b7d1ba Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 9 Oct 2009 02:49:55 -0700 Subject: Change the backup thread to run on a BackgroundWorker instead of a Thread. I don't have an explanation, but this seems to stop a slow but steady memory leak I was experiencing --- OpenSim/Region/Framework/Scenes/Scene.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/Scene.cs') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index ceff28b..6a550fa 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1186,10 +1186,10 @@ namespace OpenSim.Region.Framework.Scenes if (!m_backingup) { m_backingup = true; - Thread backupthread = new Thread(Backup); - backupthread.Name = "BackupWriter"; - backupthread.IsBackground = true; - backupthread.Start(); + + System.ComponentModel.BackgroundWorker backupWorker = new System.ComponentModel.BackgroundWorker(); + backupWorker.DoWork += delegate(object sender, System.ComponentModel.DoWorkEventArgs e) { Backup(); }; + backupWorker.RunWorkerAsync(); } } -- cgit v1.1 From c893761319f7e61d13b2d2301180d0f227fde1a9 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 13 Oct 2009 12:50:59 -0700 Subject: * Unregister event handlers in LLUDPServer when a client logs out and disconnects * Move ViewerEffect handling to Scene.PacketHandlers * Removing the unused CloseAllAgents function * Trimming ClientManager down. This class needs to be reworked to keep LLUDP circuit codes from intruding into the abstract OpenSim core code --- OpenSim/Region/Framework/Scenes/Scene.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/Scene.cs') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index cffb23c..e81b07b 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2572,6 +2572,7 @@ namespace OpenSim.Region.Framework.Scenes public virtual void SubscribeToClientNetworkEvents(IClientAPI client) { client.OnNetworkStatsUpdate += StatsReporter.AddPacketsStats; + client.OnViewerEffect += ProcessViewerEffect; } protected virtual void UnsubscribeToClientEvents(IClientAPI client) @@ -2726,11 +2727,9 @@ namespace OpenSim.Region.Framework.Scenes public virtual void UnSubscribeToClientNetworkEvents(IClientAPI client) { client.OnNetworkStatsUpdate -= StatsReporter.AddPacketsStats; + client.OnViewerEffect -= ProcessViewerEffect; } - - - /// /// Teleport an avatar to their home region /// @@ -3053,16 +3052,6 @@ namespace OpenSim.Region.Framework.Scenes } /// - /// Closes all endpoints with the circuitcode provided. - /// - /// Circuit Code of the endpoint to close - public override void CloseAllAgents(uint circuitcode) - { - // Called by ClientView to kill all circuit codes - ClientManager.CloseAllAgents(circuitcode); - } - - /// /// Inform all other ScenePresences on this Scene that someone else has changed position on the minimap. /// public void NotifyMyCoarseLocationChange() -- cgit v1.1 From 23a334b9f54a1ef5df3b503c165e7b76b746a2b1 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 13 Oct 2009 14:50:03 -0700 Subject: * Rewrote ClientManager to remove Lindenisms from OpenSim core, improve performance by removing locks, and replace LLUDPClientCollection * Removed the confusing (and LL-specific) shutdowncircuit parameter from IClientAPI.Close() * Updated the LLUDP code to only use ClientManager instead of trying to synchronize ClientManager and m_clients * Remove clients asynchronously since it is a very slow operation (including a 2000ms sleep) --- OpenSim/Region/Framework/Scenes/Scene.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/Scene.cs') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index e81b07b..bb71896 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -867,7 +867,7 @@ namespace OpenSim.Region.Framework.Scenes Thread.Sleep(500); // Stop all client threads. - ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(true); }); + ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(); }); // Stop updating the scene objects and agents. //m_heartbeatTimer.Close(); @@ -3372,7 +3372,7 @@ namespace OpenSim.Region.Framework.Scenes loggingOffUser.ControllingClient.Kick(message); // Give them a second to receive the message! Thread.Sleep(1000); - loggingOffUser.ControllingClient.Close(true); + loggingOffUser.ControllingClient.Close(); } else { @@ -3543,7 +3543,7 @@ namespace OpenSim.Region.Framework.Scenes presence.ControllingClient.SendShutdownConnectionNotice(); } - presence.ControllingClient.Close(true); + presence.ControllingClient.Close(); return true; } -- cgit v1.1 From dc11643c007adf7a640ec4fbabe25995352aaa18 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 13 Oct 2009 17:33:45 -0700 Subject: * Consolidated adding / removing ClientManager IClientAPIs to two places in Scene * Added some missing implementations of IClientAPI.RemoteEndPoint * Added a ClientManager.Remove(UUID) overload * Removed a reference to a missing project from prebuild.xml --- OpenSim/Region/Framework/Scenes/Scene.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'OpenSim/Region/Framework/Scenes/Scene.cs') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index bb71896..7944548 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2363,6 +2363,8 @@ namespace OpenSim.Region.Framework.Scenes /// public override void AddNewClient(IClientAPI client) { + ClientManager.Add(client); + CheckHeartbeat(); SubscribeToClientEvents(client); ScenePresence presence; @@ -3002,7 +3004,9 @@ namespace OpenSim.Region.Framework.Scenes agentTransactions.RemoveAgentAssetTransactions(agentID); } + // Remove the avatar from the scene m_sceneGraph.RemoveScenePresence(agentID); + ClientManager.Remove(agentID); try { -- cgit v1.1 From 31a61bbeec5aae6b679ffa53e2966420e774f301 Mon Sep 17 00:00:00 2001 From: Teravus Ovares (Dan Olivares) Date: Tue, 13 Oct 2009 22:03:00 -0400 Subject: * Fixes some prim crossings on megaregions with regions beyond the 512m mark * There's a slight chance that this could cause a problem with regular prim crossings.. but hopefully not. Revert if it does. --- OpenSim/Region/Framework/Scenes/Scene.cs | 114 +++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 21 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/Scene.cs') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 949cf19..0f351ce 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1780,36 +1780,86 @@ namespace OpenSim.Region.Framework.Scenes Vector3 pos = attemptedPosition; + int changeX = 1; + int changeY = 1; + if (TestBorderCross(attemptedPosition + WestCross, Cardinals.W)) { if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S)) { - //Border crossedBorderx = GetCrossedBorder(attemptedPosition,Cardinals.W); - //Border crossedBordery = GetCrossedBorder(attemptedPosition, Cardinals.S); + + Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W); + + if (crossedBorderx.BorderLine.Z > 0) + { + pos.X = ((pos.X + crossedBorderx.BorderLine.Z)); + changeX = (int)(crossedBorderx.BorderLine.Z /(int) Constants.RegionSize); + } + else + pos.X = ((pos.X + Constants.RegionSize)); + + Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S); //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize) - pos.X = ((pos.X + Constants.RegionSize)); - pos.Y = ((pos.Y + Constants.RegionSize)); + + if (crossedBordery.BorderLine.Z > 0) + { + pos.Y = ((pos.Y + crossedBordery.BorderLine.Z)); + } + else + pos.Y = ((pos.Y + Constants.RegionSize)); + + + newRegionHandle - = Util.UIntsToLong((uint)((thisx - 1) * Constants.RegionSize), - (uint)((thisy - 1) * Constants.RegionSize)); + = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize), + (uint)((thisy - changeY) * Constants.RegionSize)); // x - 1 // y - 1 } else if (TestBorderCross(attemptedPosition + NorthCross, Cardinals.N)) { - pos.X = ((pos.X + Constants.RegionSize)); - pos.Y = ((pos.Y - Constants.RegionSize)); + Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W); + + if (crossedBorderx.BorderLine.Z > 0) + { + pos.X = ((pos.X + crossedBorderx.BorderLine.Z)); + changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize); + } + else + pos.X = ((pos.X + Constants.RegionSize)); + + + Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S); + //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize) + + if (crossedBordery.BorderLine.Z > 0) + { + pos.Y = ((pos.Y + crossedBordery.BorderLine.Z)); + changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize); + } + else + pos.Y = ((pos.Y + Constants.RegionSize)); + newRegionHandle - = Util.UIntsToLong((uint)((thisx - 1) * Constants.RegionSize), - (uint)((thisy + 1) * Constants.RegionSize)); + = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize), + (uint)((thisy + changeY) * Constants.RegionSize)); // x - 1 // y + 1 } else { - pos.X = ((pos.X + Constants.RegionSize)); + Border crossedBorderx = GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W); + + if (crossedBorderx.BorderLine.Z > 0) + { + pos.X = ((pos.X + crossedBorderx.BorderLine.Z)); + changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize); + } + else + pos.X = ((pos.X + Constants.RegionSize)); + newRegionHandle - = Util.UIntsToLong((uint) ((thisx - 1)*Constants.RegionSize), + = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize), (uint) (thisy*Constants.RegionSize)); // x - 1 } @@ -1818,11 +1868,23 @@ namespace OpenSim.Region.Framework.Scenes { if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S)) { + pos.X = ((pos.X - Constants.RegionSize)); - pos.Y = ((pos.Y + Constants.RegionSize)); + Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S); + //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize) + + if (crossedBordery.BorderLine.Z > 0) + { + pos.Y = ((pos.Y + crossedBordery.BorderLine.Z)); + changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize); + } + else + pos.Y = ((pos.Y + Constants.RegionSize)); + + newRegionHandle - = Util.UIntsToLong((uint)((thisx + 1) * Constants.RegionSize), - (uint)((thisy - 1) * Constants.RegionSize)); + = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize), + (uint)((thisy - changeY) * Constants.RegionSize)); // x + 1 // y - 1 } @@ -1831,8 +1893,8 @@ namespace OpenSim.Region.Framework.Scenes pos.X = ((pos.X - Constants.RegionSize)); pos.Y = ((pos.Y - Constants.RegionSize)); newRegionHandle - = Util.UIntsToLong((uint)((thisx + 1) * Constants.RegionSize), - (uint)((thisy + 1) * Constants.RegionSize)); + = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize), + (uint)((thisy + changeY) * Constants.RegionSize)); // x + 1 // y + 1 } @@ -1840,16 +1902,26 @@ namespace OpenSim.Region.Framework.Scenes { pos.X = ((pos.X - Constants.RegionSize)); newRegionHandle - = Util.UIntsToLong((uint) ((thisx + 1)*Constants.RegionSize), + = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize), (uint) (thisy*Constants.RegionSize)); // x + 1 } } else if (TestBorderCross(attemptedPosition + SouthCross, Cardinals.S)) { - pos.Y = ((pos.Y + Constants.RegionSize)); + Border crossedBordery = GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S); + //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize) + + if (crossedBordery.BorderLine.Z > 0) + { + pos.Y = ((pos.Y + crossedBordery.BorderLine.Z)); + changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize); + } + else + pos.Y = ((pos.Y + Constants.RegionSize)); + newRegionHandle - = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy - 1) * Constants.RegionSize)); + = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy - changeY) * Constants.RegionSize)); // y - 1 } else if (TestBorderCross(attemptedPosition + NorthCross, Cardinals.N)) @@ -1857,7 +1929,7 @@ namespace OpenSim.Region.Framework.Scenes pos.Y = ((pos.Y - Constants.RegionSize)); newRegionHandle - = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy + 1) * Constants.RegionSize)); + = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy + changeY) * Constants.RegionSize)); // y + 1 } -- cgit v1.1 From 5976ac16b0eedaeca2360010a3d6f7be4213700a Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Tue, 13 Oct 2009 19:13:06 -0700 Subject: Optimized heartbeat by calling Update() only on updated objects. During the heartbeat loop, Update() is called on every SceneObjectGroup which in turn checks if any SceneObjectPart has changed. For large regions (> 100k prims) this work consumes 20-30% of a CPU even though there are only a few objects updating each frame. There is only one other reason to check every object on every frame, and that is the case where a script has registered the object with an "at target" listener. We can easily track when an object is registered or unregistered with an AtTarget, so this is not a reason to check every object every heartbeat. In the attached patch, I have added a dictionary to the scene which tracks the objects which have At Targets. Each heartbeat, the AtTarget() function will be called on every object registered with a listener for that event. Also, I added a dictionary to SceneGraph which stores references to objects which have been queued for updates during the heartbeat. At each heartbeat, Update() is called only on the objects which have generated updates during that beat. --- OpenSim/Region/Framework/Scenes/Scene.cs | 82 ++++++++++++++------------------ 1 file changed, 37 insertions(+), 45 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/Scene.cs') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 7944548..1ca0267 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -117,6 +117,8 @@ namespace OpenSim.Region.Framework.Scenes private volatile bool m_backingup = false; private Dictionary m_returns = new Dictionary(); + + private Dictionary m_groupsWithTargets = new Dictionary(); protected string m_simulatorVersion = "OpenSimulator Server"; @@ -246,8 +248,7 @@ namespace OpenSim.Region.Framework.Scenes private int m_update_physics = 1; private int m_update_entitymovement = 1; - private int m_update_entities = 1; // Run through all objects checking for updates - private int m_update_entitiesquick = 200; // Run through objects that have scheduled updates checking for updates + private int m_update_objects = 1; // Update objects which have scheduled themselves for updates private int m_update_presences = 1; // Update scene presence movements private int m_update_events = 1; private int m_update_backup = 200; @@ -979,28 +980,7 @@ namespace OpenSim.Region.Framework.Scenes maintc = Environment.TickCount; TimeSpan SinceLastFrame = DateTime.Now - m_lastupdate; - // Aquire a lock so only one update call happens at once - //updateLock.WaitOne(); float physicsFPS = 0; - //m_log.Info("sadfadf" + m_neighbours.Count.ToString()); - int agentsInScene = m_sceneGraph.GetRootAgentCount() + m_sceneGraph.GetChildAgentCount(); - - if (agentsInScene > 21) - { - if (m_update_entities == 1) - { - m_update_entities = 5; - StatsReporter.SetUpdateMS(6000); - } - } - else - { - if (m_update_entities == 5) - { - m_update_entities = 1; - StatsReporter.SetUpdateMS(3000); - } - } frameMS = Environment.TickCount; try @@ -1013,30 +993,17 @@ namespace OpenSim.Region.Framework.Scenes m_frame = 0; otherMS = Environment.TickCount; - // run through all entities looking for updates (slow) - if (m_frame % m_update_entities == 0) - { - /* // Adam Experimental - if (m_updateEntitiesThread == null) - { - m_updateEntitiesThread = new Thread(m_sceneGraph.UpdateEntities); - ThreadTracker.Add(m_updateEntitiesThread); - } - - if (m_updateEntitiesThread.ThreadState == ThreadState.Stopped) - m_updateEntitiesThread.Start(); - */ - - m_sceneGraph.UpdateEntities(); - } + // Check if any objects have reached their targets + CheckAtTargets(); + + // Update SceneObjectGroups that have scheduled themselves for updates + // Objects queue their updates onto all scene presences + if (m_frame % m_update_objects == 0) + m_sceneGraph.UpdateObjectGroups(); - // run through entities that have scheduled themselves for - // updates looking for updates(faster) - if (m_frame % m_update_entitiesquick == 0) - m_sceneGraph.ProcessUpdates(); - - // Run through scenepresences looking for updates + // Run through all ScenePresences looking for updates + // Presence updates and queued object updates for each presence are sent to clients if (m_frame % m_update_presences == 0) m_sceneGraph.UpdatePresences(); @@ -1140,6 +1107,31 @@ namespace OpenSim.Region.Framework.Scenes } } + + public void AddGroupTarget(SceneObjectGroup grp) + { + lock(m_groupsWithTargets) + m_groupsWithTargets[grp.UUID] = grp; + } + + public void RemoveGroupTarget(SceneObjectGroup grp) + { + lock(m_groupsWithTargets) + m_groupsWithTargets.Remove(grp.UUID); + } + + private void CheckAtTargets() + { + lock (m_groupsWithTargets) + { + foreach (KeyValuePair kvp in m_groupsWithTargets) + { + kvp.Value.checkAtTargets(); + } + } + } + + /// /// Send out simstats data to all clients /// -- cgit v1.1 From bea13e37090bd2daa44c2202634c8e2fa81c203b Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 14 Oct 2009 11:01:46 -0700 Subject: Setting changeY in border crossing. --- OpenSim/Region/Framework/Scenes/Scene.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Region/Framework/Scenes/Scene.cs') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 0f351ce..04eb93f 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1804,6 +1804,7 @@ namespace OpenSim.Region.Framework.Scenes if (crossedBordery.BorderLine.Z > 0) { pos.Y = ((pos.Y + crossedBordery.BorderLine.Z)); + changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize); } else pos.Y = ((pos.Y + Constants.RegionSize)); -- cgit v1.1