diff options
author | Dan Lake | 2009-10-13 19:13:06 -0700 |
---|---|---|
committer | John Hurliman | 2009-10-13 19:32:59 -0700 |
commit | 5976ac16b0eedaeca2360010a3d6f7be4213700a (patch) | |
tree | 8f6a80582a4640b5be0c242fd7cf2f19db39a72a /OpenSim/Region/Framework/Scenes/Scene.cs | |
parent | * Copied LocklessQueue.cs into OpenSim.Framework and added the .Count propert... (diff) | |
download | opensim-SC_OLD-5976ac16b0eedaeca2360010a3d6f7be4213700a.zip opensim-SC_OLD-5976ac16b0eedaeca2360010a3d6f7be4213700a.tar.gz opensim-SC_OLD-5976ac16b0eedaeca2360010a3d6f7be4213700a.tar.bz2 opensim-SC_OLD-5976ac16b0eedaeca2360010a3d6f7be4213700a.tar.xz |
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.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Scene.cs | 82 |
1 files changed, 37 insertions, 45 deletions
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 | |||
117 | private volatile bool m_backingup = false; | 117 | private volatile bool m_backingup = false; |
118 | 118 | ||
119 | private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>(); | 119 | private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>(); |
120 | |||
121 | private Dictionary<UUID, SceneObjectGroup> m_groupsWithTargets = new Dictionary<UUID, SceneObjectGroup>(); | ||
120 | 122 | ||
121 | protected string m_simulatorVersion = "OpenSimulator Server"; | 123 | protected string m_simulatorVersion = "OpenSimulator Server"; |
122 | 124 | ||
@@ -246,8 +248,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
246 | 248 | ||
247 | private int m_update_physics = 1; | 249 | private int m_update_physics = 1; |
248 | private int m_update_entitymovement = 1; | 250 | private int m_update_entitymovement = 1; |
249 | private int m_update_entities = 1; // Run through all objects checking for updates | 251 | private int m_update_objects = 1; // Update objects which have scheduled themselves for updates |
250 | private int m_update_entitiesquick = 200; // Run through objects that have scheduled updates checking for updates | ||
251 | private int m_update_presences = 1; // Update scene presence movements | 252 | private int m_update_presences = 1; // Update scene presence movements |
252 | private int m_update_events = 1; | 253 | private int m_update_events = 1; |
253 | private int m_update_backup = 200; | 254 | private int m_update_backup = 200; |
@@ -979,28 +980,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
979 | maintc = Environment.TickCount; | 980 | maintc = Environment.TickCount; |
980 | 981 | ||
981 | TimeSpan SinceLastFrame = DateTime.Now - m_lastupdate; | 982 | TimeSpan SinceLastFrame = DateTime.Now - m_lastupdate; |
982 | // Aquire a lock so only one update call happens at once | ||
983 | //updateLock.WaitOne(); | ||
984 | float physicsFPS = 0; | 983 | float physicsFPS = 0; |
985 | //m_log.Info("sadfadf" + m_neighbours.Count.ToString()); | ||
986 | int agentsInScene = m_sceneGraph.GetRootAgentCount() + m_sceneGraph.GetChildAgentCount(); | ||
987 | |||
988 | if (agentsInScene > 21) | ||
989 | { | ||
990 | if (m_update_entities == 1) | ||
991 | { | ||
992 | m_update_entities = 5; | ||
993 | StatsReporter.SetUpdateMS(6000); | ||
994 | } | ||
995 | } | ||
996 | else | ||
997 | { | ||
998 | if (m_update_entities == 5) | ||
999 | { | ||
1000 | m_update_entities = 1; | ||
1001 | StatsReporter.SetUpdateMS(3000); | ||
1002 | } | ||
1003 | } | ||
1004 | 984 | ||
1005 | frameMS = Environment.TickCount; | 985 | frameMS = Environment.TickCount; |
1006 | try | 986 | try |
@@ -1013,30 +993,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
1013 | m_frame = 0; | 993 | m_frame = 0; |
1014 | 994 | ||
1015 | otherMS = Environment.TickCount; | 995 | otherMS = Environment.TickCount; |
1016 | // run through all entities looking for updates (slow) | ||
1017 | if (m_frame % m_update_entities == 0) | ||
1018 | { | ||
1019 | /* // Adam Experimental | ||
1020 | if (m_updateEntitiesThread == null) | ||
1021 | { | ||
1022 | m_updateEntitiesThread = new Thread(m_sceneGraph.UpdateEntities); | ||
1023 | 996 | ||
1024 | ThreadTracker.Add(m_updateEntitiesThread); | 997 | // Check if any objects have reached their targets |
1025 | } | 998 | CheckAtTargets(); |
1026 | 999 | ||
1027 | if (m_updateEntitiesThread.ThreadState == ThreadState.Stopped) | 1000 | // Update SceneObjectGroups that have scheduled themselves for updates |
1028 | m_updateEntitiesThread.Start(); | 1001 | // Objects queue their updates onto all scene presences |
1029 | */ | 1002 | if (m_frame % m_update_objects == 0) |
1030 | 1003 | m_sceneGraph.UpdateObjectGroups(); | |
1031 | m_sceneGraph.UpdateEntities(); | ||
1032 | } | ||
1033 | 1004 | ||
1034 | // run through entities that have scheduled themselves for | 1005 | // Run through all ScenePresences looking for updates |
1035 | // updates looking for updates(faster) | 1006 | // Presence updates and queued object updates for each presence are sent to clients |
1036 | if (m_frame % m_update_entitiesquick == 0) | ||
1037 | m_sceneGraph.ProcessUpdates(); | ||
1038 | |||
1039 | // Run through scenepresences looking for updates | ||
1040 | if (m_frame % m_update_presences == 0) | 1007 | if (m_frame % m_update_presences == 0) |
1041 | m_sceneGraph.UpdatePresences(); | 1008 | m_sceneGraph.UpdatePresences(); |
1042 | 1009 | ||
@@ -1140,6 +1107,31 @@ namespace OpenSim.Region.Framework.Scenes | |||
1140 | } | 1107 | } |
1141 | } | 1108 | } |
1142 | 1109 | ||
1110 | |||
1111 | public void AddGroupTarget(SceneObjectGroup grp) | ||
1112 | { | ||
1113 | lock(m_groupsWithTargets) | ||
1114 | m_groupsWithTargets[grp.UUID] = grp; | ||
1115 | } | ||
1116 | |||
1117 | public void RemoveGroupTarget(SceneObjectGroup grp) | ||
1118 | { | ||
1119 | lock(m_groupsWithTargets) | ||
1120 | m_groupsWithTargets.Remove(grp.UUID); | ||
1121 | } | ||
1122 | |||
1123 | private void CheckAtTargets() | ||
1124 | { | ||
1125 | lock (m_groupsWithTargets) | ||
1126 | { | ||
1127 | foreach (KeyValuePair<UUID, SceneObjectGroup> kvp in m_groupsWithTargets) | ||
1128 | { | ||
1129 | kvp.Value.checkAtTargets(); | ||
1130 | } | ||
1131 | } | ||
1132 | } | ||
1133 | |||
1134 | |||
1143 | /// <summary> | 1135 | /// <summary> |
1144 | /// Send out simstats data to all clients | 1136 | /// Send out simstats data to all clients |
1145 | /// </summary> | 1137 | /// </summary> |