Refactor SendCoarseLocations for better performance. Instead of computing list of all locations fresh for every scene presence on every frame, we will instead compute the list once every 50 frames and send to all connected presences at that time. Also, we only add 60 items to the list when there are more than 60 presences in the scene. For 1000 users, this change yields a 99.8% reduction in list processing and a 98% reduction in network bandwidth for coarse locations.

soprefactor
Dan Lake 2010-06-08 16:30:51 -07:00 committed by John Hurliman
parent 0520b62955
commit ca2abc43ad
6 changed files with 59 additions and 67 deletions

View File

@ -3426,7 +3426,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
CoarseLocationUpdatePacket loc = (CoarseLocationUpdatePacket)PacketPool.Instance.GetPacket(PacketType.CoarseLocationUpdate); CoarseLocationUpdatePacket loc = (CoarseLocationUpdatePacket)PacketPool.Instance.GetPacket(PacketType.CoarseLocationUpdate);
loc.Header.Reliable = false; loc.Header.Reliable = false;
// Each packet can only hold around 62 avatar positions and the client clears the mini-map each time // Each packet can only hold around 60 avatar positions and the client clears the mini-map each time
// a CoarseLocationUpdate packet is received. Oh well. // a CoarseLocationUpdate packet is received. Oh well.
int total = Math.Min(CoarseLocations.Count, 60); int total = Math.Min(CoarseLocations.Count, 60);

View File

@ -865,9 +865,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
CrossAttachmentsIntoNewRegion(neighbourRegion, agent, true); CrossAttachmentsIntoNewRegion(neighbourRegion, agent, true);
// m_scene.SendKillObject(m_localId);
agent.Scene.NotifyMyCoarseLocationChange();
// the user may change their profile information in other region, // the user may change their profile information in other region,
// so the userinfo in UserProfileCache is not reliable any more, delete it // so the userinfo in UserProfileCache is not reliable any more, delete it
// REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE! // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE!

View File

@ -348,6 +348,7 @@ namespace OpenSim.Region.Framework.Scenes
private int m_update_backup = 200; private int m_update_backup = 200;
private int m_update_terrain = 50; private int m_update_terrain = 50;
private int m_update_land = 1; private int m_update_land = 1;
private int m_update_coarse_locations = 50;
private int frameMS; private int frameMS;
private int physicsMS2; private int physicsMS2;
@ -1417,6 +1418,18 @@ namespace OpenSim.Region.Framework.Scenes
if (m_frame % m_update_presences == 0) if (m_frame % m_update_presences == 0)
m_sceneGraph.UpdatePresences(); m_sceneGraph.UpdatePresences();
if (m_frame % m_update_coarse_locations == 0)
{
List<Vector3> coarseLocations;
List<UUID> avatarUUIDs;
SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60);
// Send coarse locations to clients
ForEachScenePresence(delegate(ScenePresence presence)
{
presence.SendCoarseLocations(coarseLocations, avatarUUIDs);
});
}
int tmpPhysicsMS2 = Util.EnvironmentTickCount(); int tmpPhysicsMS2 = Util.EnvironmentTickCount();
if ((m_frame % m_update_physics == 0) && m_physics_enabled) if ((m_frame % m_update_physics == 0) && m_physics_enabled)
m_sceneGraph.UpdatePreparePhysics(); m_sceneGraph.UpdatePreparePhysics();
@ -3301,9 +3314,6 @@ namespace OpenSim.Region.Framework.Scenes
catch (NullReferenceException) { } catch (NullReferenceException) { }
}); });
ForEachScenePresence(
delegate(ScenePresence presence) { presence.CoarseLocationChange(); });
IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>(); IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
if (agentTransactions != null) if (agentTransactions != null)
{ {
@ -3355,14 +3365,6 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
/// <summary>
/// Inform all other ScenePresences on this Scene that someone else has changed position on the minimap.
/// </summary>
public void NotifyMyCoarseLocationChange()
{
ForEachScenePresence(delegate(ScenePresence presence) { presence.CoarseLocationChange(); });
}
#endregion #endregion
#region Entities #region Entities

View File

@ -206,6 +206,43 @@ namespace OpenSim.Region.Framework.Scenes
}); });
} }
public void GetCoarseLocations(out List<Vector3> coarseLocations, out List<UUID> avatarUUIDs, uint maxLocations)
{
coarseLocations = new List<Vector3>();
avatarUUIDs = new List<UUID>();
List<ScenePresence> presences = GetScenePresences();
for (int i = 0; i < Math.Min(presences.Count, maxLocations); ++i)
{
ScenePresence sp = presences[i];
// If this presence is a child agent, we don't want its coarse locations
if (sp.IsChildAgent)
return;
if (sp.ParentID != 0)
{
// sitting avatar
SceneObjectPart sop = m_parentScene.GetSceneObjectPart(sp.ParentID);
if (sop != null)
{
coarseLocations.Add(sop.AbsolutePosition + sp.AbsolutePosition);
avatarUUIDs.Add(sp.UUID);
}
else
{
// we can't find the parent.. ! arg!
coarseLocations.Add(sp.AbsolutePosition);
avatarUUIDs.Add(sp.UUID);
}
}
else
{
coarseLocations.Add(sp.AbsolutePosition);
avatarUUIDs.Add(sp.UUID);
}
}
}
#endregion #endregion
#region Entity Methods #region Entity Methods

View File

@ -65,7 +65,7 @@ namespace OpenSim.Region.Framework.Scenes
public ScriptControlled eventControls; public ScriptControlled eventControls;
} }
public delegate void SendCourseLocationsMethod(UUID scene, ScenePresence presence); public delegate void SendCourseLocationsMethod(UUID scene, ScenePresence presence, List<Vector3> coarseLocations, List<UUID> avatarUUIDs);
public class ScenePresence : EntityBase, ISceneEntity public class ScenePresence : EntityBase, ISceneEntity
{ {
@ -173,8 +173,6 @@ namespace OpenSim.Region.Framework.Scenes
public string JID = String.Empty; public string JID = String.Empty;
// Agent moves with a PID controller causing a force to be exerted.
private bool m_newCoarseLocations = true;
private float m_health = 100f; private float m_health = 100f;
// Default AV Height // Default AV Height
@ -2296,12 +2294,6 @@ namespace OpenSim.Region.Framework.Scenes
SendPrimUpdates(); SendPrimUpdates();
if (m_newCoarseLocations)
{
SendCoarseLocations();
m_newCoarseLocations = false;
}
if (m_isChildAgent == false) if (m_isChildAgent == false)
{ {
// PhysicsActor actor = m_physicsActor; // PhysicsActor actor = m_physicsActor;
@ -2375,12 +2367,12 @@ namespace OpenSim.Region.Framework.Scenes
m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
} }
public void SendCoarseLocations() public void SendCoarseLocations(List<Vector3> coarseLocations, List<UUID> avatarUUIDs)
{ {
SendCourseLocationsMethod d = m_sendCourseLocationsMethod; SendCourseLocationsMethod d = m_sendCourseLocationsMethod;
if (d != null) if (d != null)
{ {
d.Invoke(m_scene.RegionInfo.originRegionID, this); d.Invoke(m_scene.RegionInfo.originRegionID, this, coarseLocations, avatarUUIDs);
} }
} }
@ -2390,50 +2382,13 @@ namespace OpenSim.Region.Framework.Scenes
m_sendCourseLocationsMethod = d; m_sendCourseLocationsMethod = d;
} }
public void SendCoarseLocationsDefault(UUID sceneId, ScenePresence p) public void SendCoarseLocationsDefault(UUID sceneId, ScenePresence p, List<Vector3> coarseLocations, List<UUID> avatarUUIDs)
{ {
m_perfMonMS = Util.EnvironmentTickCount(); m_perfMonMS = Util.EnvironmentTickCount();
m_controllingClient.SendCoarseLocationUpdate(avatarUUIDs, coarseLocations);
List<Vector3> CoarseLocations = new List<Vector3>();
List<UUID> AvatarUUIDs = new List<UUID>();
m_scene.ForEachScenePresence(delegate(ScenePresence sp)
{
if (sp.IsChildAgent)
return;
if (sp.ParentID != 0)
{
// sitting avatar
SceneObjectPart sop = m_scene.GetSceneObjectPart(sp.ParentID);
if (sop != null)
{
CoarseLocations.Add(sop.AbsolutePosition + sp.m_pos);
AvatarUUIDs.Add(sp.UUID);
}
else
{
// we can't find the parent.. ! arg!
CoarseLocations.Add(sp.m_pos);
AvatarUUIDs.Add(sp.UUID);
}
}
else
{
CoarseLocations.Add(sp.m_pos);
AvatarUUIDs.Add(sp.UUID);
}
});
m_controllingClient.SendCoarseLocationUpdate(AvatarUUIDs, CoarseLocations);
m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
} }
public void CoarseLocationChange()
{
m_newCoarseLocations = true;
}
/// <summary> /// <summary>
/// Tell other client about this avatar (The client previously didn't know or had outdated details about this avatar) /// Tell other client about this avatar (The client previously didn't know or had outdated details about this avatar)
/// </summary> /// </summary>
@ -2668,7 +2623,6 @@ namespace OpenSim.Region.Framework.Scenes
{ {
posLastSignificantMove = AbsolutePosition; posLastSignificantMove = AbsolutePosition;
m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient); m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient);
m_scene.NotifyMyCoarseLocationChange();
} }
// Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m

View File

@ -696,7 +696,9 @@ namespace OpenSim.Region.RegionCombinerModule
presence.SetSendCourseLocationMethod(SendCourseLocationUpdates); presence.SetSendCourseLocationMethod(SendCourseLocationUpdates);
} }
private void SendCourseLocationUpdates(UUID sceneId, ScenePresence presence) // This delegate was refactored for non-combined regions.
// This combined region version will not use the pre-compiled lists of locations and ids
private void SendCourseLocationUpdates(UUID sceneId, ScenePresence presence, List<Vector3> coarseLocations, List<UUID> avatarUUIDs)
{ {
RegionConnections connectiondata = null; RegionConnections connectiondata = null;
lock (m_regions) lock (m_regions)