Merge branch 'master' into careminster

Conflicts:
	OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
	OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
	OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
This commit is contained in:
Melanie
2013-07-24 03:50:09 +01:00
31 changed files with 656 additions and 277 deletions

View File

@@ -80,7 +80,7 @@ namespace OpenSim.Region.CoreModules.Framework
MainConsole.Instance.Commands.AddCommand(
"Comms", false, "show caps stats by user",
"show caps stats [<first-name> <last-name>]",
"show caps stats by user [<first-name> <last-name>]",
"Shows statistics on capabilities use by user.",
"If a user name is given, then prints a detailed breakdown of caps use ordered by number of requests received.",
HandleShowCapsStatsByUserCommand);
@@ -296,27 +296,31 @@ namespace OpenSim.Region.CoreModules.Framework
if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_scene)
return;
StringBuilder caps = new StringBuilder();
caps.AppendFormat("Region {0}:\n", m_scene.RegionInfo.RegionName);
StringBuilder capsReport = new StringBuilder();
capsReport.AppendFormat("Region {0}:\n", m_scene.RegionInfo.RegionName);
lock (m_capsObjects)
{
foreach (KeyValuePair<uint, Caps> kvp in m_capsObjects)
{
caps.AppendFormat("** Circuit {0}:\n", kvp.Key);
capsReport.AppendFormat("** Circuit {0}:\n", kvp.Key);
Caps caps = kvp.Value;
for (IDictionaryEnumerator kvp2 = kvp.Value.CapsHandlers.GetCapsDetails(false, null).GetEnumerator(); kvp2.MoveNext(); )
for (IDictionaryEnumerator kvp2 = caps.CapsHandlers.GetCapsDetails(false, null).GetEnumerator(); kvp2.MoveNext(); )
{
Uri uri = new Uri(kvp2.Value.ToString());
caps.AppendFormat(m_showCapsCommandFormat, kvp2.Key, uri.PathAndQuery);
capsReport.AppendFormat(m_showCapsCommandFormat, kvp2.Key, uri.PathAndQuery);
}
foreach (KeyValuePair<string, string> kvp3 in kvp.Value.ExternalCapsHandlers)
caps.AppendFormat(m_showCapsCommandFormat, kvp3.Key, kvp3.Value);
foreach (KeyValuePair<string, PollServiceEventArgs> kvp2 in caps.GetPollHandlers())
capsReport.AppendFormat(m_showCapsCommandFormat, kvp2.Key, kvp2.Value.Url);
foreach (KeyValuePair<string, string> kvp3 in caps.ExternalCapsHandlers)
capsReport.AppendFormat(m_showCapsCommandFormat, kvp3.Key, kvp3.Value);
}
}
MainConsole.Instance.Output(caps.ToString());
MainConsole.Instance.Output(capsReport.ToString());
}
private void HandleShowCapsStatsByCapCommand(string module, string[] cmdParams)
@@ -374,7 +378,16 @@ namespace OpenSim.Region.CoreModules.Framework
{
receivedStats[sp.Name] = reqHandler.RequestsReceived;
handledStats[sp.Name] = reqHandler.RequestsHandled;
}
}
else
{
PollServiceEventArgs pollHandler = null;
if (caps.TryGetPollHandler(capName, out pollHandler))
{
receivedStats[sp.Name] = pollHandler.RequestsReceived;
handledStats[sp.Name] = pollHandler.RequestsHandled;
}
}
}
);
@@ -405,11 +418,9 @@ namespace OpenSim.Region.CoreModules.Framework
Caps caps = m_scene.CapsModule.GetCapsForUser(sp.UUID);
if (caps == null)
return;
return;
Dictionary<string, IRequestHandler> capsHandlers = caps.CapsHandlers.GetCapsHandlers();
foreach (IRequestHandler reqHandler in capsHandlers.Values)
foreach (IRequestHandler reqHandler in caps.CapsHandlers.GetCapsHandlers().Values)
{
string reqName = reqHandler.Name ?? "";
@@ -424,6 +435,23 @@ namespace OpenSim.Region.CoreModules.Framework
handledStats[reqName] += reqHandler.RequestsHandled;
}
}
foreach (KeyValuePair<string, PollServiceEventArgs> kvp in caps.GetPollHandlers())
{
string name = kvp.Key;
PollServiceEventArgs pollHandler = kvp.Value;
if (!receivedStats.ContainsKey(name))
{
receivedStats[name] = pollHandler.RequestsReceived;
handledStats[name] = pollHandler.RequestsHandled;
}
else
{
receivedStats[name] += pollHandler.RequestsReceived;
handledStats[name] += pollHandler.RequestsHandled;
}
}
}
);
@@ -486,12 +514,16 @@ namespace OpenSim.Region.CoreModules.Framework
if (caps == null)
return;
Dictionary<string, IRequestHandler> capsHandlers = caps.CapsHandlers.GetCapsHandlers();
List<CapTableRow> capRows = new List<CapTableRow>();
foreach (IRequestHandler reqHandler in capsHandlers.Values.OrderByDescending(rh => rh.RequestsReceived))
{
cdt.AddRow(reqHandler.Name, reqHandler.RequestsReceived, reqHandler.RequestsHandled);
}
foreach (IRequestHandler reqHandler in caps.CapsHandlers.GetCapsHandlers().Values)
capRows.Add(new CapTableRow(reqHandler.Name, reqHandler.RequestsReceived, reqHandler.RequestsHandled));
foreach (KeyValuePair<string, PollServiceEventArgs> kvp in caps.GetPollHandlers())
capRows.Add(new CapTableRow(kvp.Key, kvp.Value.RequestsReceived, kvp.Value.RequestsHandled));
foreach (CapTableRow ctr in capRows.OrderByDescending(ctr => ctr.RequestsReceived))
cdt.AddRow(ctr.Name, ctr.RequestsReceived, ctr.RequestsHandled);
sb.Append(cdt.ToString());
*/
@@ -525,6 +557,14 @@ namespace OpenSim.Region.CoreModules.Framework
totalRequestsReceived += reqHandler.RequestsReceived;
totalRequestsHandled += reqHandler.RequestsHandled;
}
Dictionary<string, PollServiceEventArgs> capsPollHandlers = caps.GetPollHandlers();
foreach (PollServiceEventArgs handler in capsPollHandlers.Values)
{
totalRequestsReceived += handler.RequestsReceived;
totalRequestsHandled += handler.RequestsHandled;
}
cdt.AddRow(sp.Name, sp.IsChildAgent ? "child" : "root", totalRequestsReceived, totalRequestsHandled);
}
@@ -533,5 +573,19 @@ namespace OpenSim.Region.CoreModules.Framework
sb.Append(cdt.ToString());
*/
}
private class CapTableRow
{
public string Name { get; set; }
public int RequestsReceived { get; set; }
public int RequestsHandled { get; set; }
public CapTableRow(string name, int requestsReceived, int requestsHandled)
{
Name = name;
RequestsReceived = requestsReceived;
RequestsHandled = requestsHandled;
}
}
}
}

View File

@@ -42,23 +42,37 @@ using GridRegion = OpenSim.Services.Interfaces.GridRegion;
namespace OpenSim.Region.CoreModules.Framework
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GridServiceThrottleModule")]
public class GridServiceThrottleModule : ISharedRegionModule
public class ServiceThrottleModule : ISharedRegionModule, IServiceThrottleModule
{
private static readonly ILog m_log = LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private readonly List<Scene> m_scenes = new List<Scene>();
private System.Timers.Timer m_timer = new System.Timers.Timer();
private OpenSim.Framework.BlockingQueue<GridRegionRequest> m_RequestQueue = new OpenSim.Framework.BlockingQueue<GridRegionRequest>();
private Queue<Action> m_RequestQueue = new Queue<Action>();
private Dictionary<string, List<string>> m_Pending = new Dictionary<string, List<string>>();
private int m_Interval;
#region ISharedRegionModule
public void Initialise(IConfigSource config)
{
Watchdog.StartThread(
ProcessQueue,
"GridServiceRequestThread",
ThreadPriority.BelowNormal,
true,
false);
m_Interval = Util.GetConfigVarFromSections<int>(config, "Interval", new string[] { "ServiceThrottle" }, 5000);
m_timer = new System.Timers.Timer();
m_timer.AutoReset = false;
m_timer.Enabled = true;
m_timer.Interval = 15000; // 15 secs at first
m_timer.Elapsed += ProcessQueue;
m_timer.Start();
//Watchdog.StartThread(
// ProcessQueue,
// "GridServiceRequestThread",
// ThreadPriority.BelowNormal,
// true,
// false);
}
public void AddRegion(Scene scene)
@@ -66,7 +80,9 @@ namespace OpenSim.Region.CoreModules.Framework
lock (m_scenes)
{
m_scenes.Add(scene);
scene.RegisterModuleInterface<IServiceThrottleModule>(this);
scene.EventManager.OnNewClient += OnNewClient;
scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
}
}
@@ -83,11 +99,6 @@ namespace OpenSim.Region.CoreModules.Framework
}
}
void OnNewClient(IClientAPI client)
{
client.OnRegionHandleRequest += OnRegionHandleRequest;
}
public void PostInitialise()
{
}
@@ -98,7 +109,7 @@ namespace OpenSim.Region.CoreModules.Framework
public string Name
{
get { return "GridServiceThrottleModule"; }
get { return "ServiceThrottleModule"; }
}
public Type ReplaceableInterface
@@ -106,9 +117,31 @@ namespace OpenSim.Region.CoreModules.Framework
get { return null; }
}
#endregion ISharedRegionMOdule
#region Events
void OnNewClient(IClientAPI client)
{
client.OnRegionHandleRequest += OnRegionHandleRequest;
}
void OnMakeRootAgent(ScenePresence obj)
{
lock (m_timer)
{
if (!m_timer.Enabled)
{
m_timer.Interval = m_Interval;
m_timer.Enabled = true;
m_timer.Start();
}
}
}
public void OnRegionHandleRequest(IClientAPI client, UUID regionID)
{
//m_log.DebugFormat("[GRIDSERVICE THROTTLE]: RegionHandleRequest {0}", regionID);
//m_log.DebugFormat("[SERVICE THROTTLE]: RegionHandleRequest {0}", regionID);
ulong handle = 0;
if (IsLocalRegionHandle(regionID, out handle))
{
@@ -116,11 +149,83 @@ namespace OpenSim.Region.CoreModules.Framework
return;
}
GridRegionRequest request = new GridRegionRequest(client, regionID);
m_RequestQueue.Enqueue(request);
Action action = delegate
{
GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, regionID);
if (r != null && r.RegionHandle != 0)
client.SendRegionHandle(regionID, r.RegionHandle);
};
Enqueue("region", regionID.ToString(), action);
}
#endregion Events
#region IServiceThrottleModule
public void Enqueue(string category, string itemid, Action continuation)
{
lock (m_RequestQueue)
{
if (m_Pending.ContainsKey(category))
{
if (m_Pending[category].Contains(itemid))
// Don't enqueue, it's already pending
return;
}
else
m_Pending.Add(category, new List<string>());
m_Pending[category].Add(itemid);
m_RequestQueue.Enqueue(delegate
{
lock (m_RequestQueue)
m_Pending[category].Remove(itemid);
continuation();
});
}
}
#endregion IServiceThrottleModule
#region Process Continuation Queue
private void ProcessQueue(object sender, System.Timers.ElapsedEventArgs e)
{
//m_log.DebugFormat("[YYY]: Process queue with {0} continuations", m_RequestQueue.Count);
while (m_RequestQueue.Count > 0)
{
Action continuation = null;
lock (m_RequestQueue)
continuation = m_RequestQueue.Dequeue();
if (continuation != null)
continuation();
}
if (AreThereRootAgents())
{
lock (m_timer)
{
m_timer.Interval = 1000; // 1 sec
m_timer.Enabled = true;
m_timer.Start();
}
}
else
lock (m_timer)
m_timer.Enabled = false;
}
#endregion Process Continuation Queue
#region Misc
private bool IsLocalRegionHandle(UUID regionID, out ulong regionHandle)
{
regionHandle = 0;
@@ -133,31 +238,19 @@ namespace OpenSim.Region.CoreModules.Framework
return false;
}
private void ProcessQueue()
private bool AreThereRootAgents()
{
while (true)
foreach (Scene s in m_scenes)
{
Watchdog.UpdateThread();
GridRegionRequest request = m_RequestQueue.Dequeue();
GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, request.regionID);
if (r != null && r.RegionHandle != 0)
request.client.SendRegionHandle(request.regionID, r.RegionHandle);
foreach (ScenePresence sp in s.GetScenePresences())
if (!sp.IsChildAgent)
return true;
}
return false;
}
#endregion Misc
}
class GridRegionRequest
{
public IClientAPI client;
public UUID regionID;
public GridRegionRequest(IClientAPI c, UUID r)
{
client = c;
regionID = r;
}
}
}

View File

@@ -56,13 +56,10 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
protected bool m_Enabled;
protected List<Scene> m_Scenes = new List<Scene>();
protected IServiceThrottleModule m_ServiceThrottle;
// The cache
protected Dictionary<UUID, UserData> m_UserCache = new Dictionary<UUID, UserData>();
// Throttle the name requests
private OpenSim.Framework.BlockingQueue<NameRequest> m_RequestQueue = new OpenSim.Framework.BlockingQueue<NameRequest>();
#region ISharedRegionModule
public void Initialise(IConfigSource config)
@@ -115,6 +112,8 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
public void RegionLoaded(Scene s)
{
if (m_Enabled && m_ServiceThrottle == null)
m_ServiceThrottle = s.RequestModuleInterface<IServiceThrottleModule>();
}
public void PostInitialise()
@@ -154,7 +153,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
client.OnAvatarPickerRequest -= new AvatarPickerRequest(HandleAvatarPickerRequest);
}
void HandleUUIDNameRequest(UUID uuid, IClientAPI remote_client)
void HandleUUIDNameRequest(UUID uuid, IClientAPI client)
{
// m_log.DebugFormat(
// "[USER MANAGEMENT MODULE]: Handling request for name binding of UUID {0} from {1}",
@@ -162,12 +161,31 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
if (m_Scenes[0].LibraryService != null && (m_Scenes[0].LibraryService.LibraryRootFolder.Owner == uuid))
{
remote_client.SendNameReply(uuid, "Mr", "OpenSim");
client.SendNameReply(uuid, "Mr", "OpenSim");
}
else
{
NameRequest request = new NameRequest(remote_client, uuid);
m_RequestQueue.Enqueue(request);
string[] names = new string[2];
if (TryGetUserNamesFromCache(uuid, names))
{
client.SendNameReply(uuid, names[0], names[1]);
return;
}
// Not found in cache, queue continuation
m_ServiceThrottle.Enqueue("name", uuid.ToString(), delegate
{
//m_log.DebugFormat("[YYY]: Name request {0}", uuid);
bool foundRealName = TryGetUserNames(uuid, names);
if (names.Length == 2)
{
if (!foundRealName)
m_log.DebugFormat("[USER MANAGEMENT MODULE]: Sending {0} {1} for {2} to {3} since no bound name found", names[0], names[1], uuid, client.Name);
client.SendNameReply(uuid, names[0], names[1]);
}
});
}
}
@@ -283,15 +301,27 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
}
/// <summary>
/// Try to get the names bound to the given uuid.
///
/// </summary>
/// <returns>True if the name was found, false if not.</returns>
/// <param name='uuid'></param>
/// <param name='names'>The array of names if found. If not found, then names[0] = "Unknown" and names[1] = "User"</param>
private bool TryGetUserNames(UUID uuid, out string[] names)
/// <param name="uuid"></param>
/// <param name="names">Caller please provide a properly instantiated array for names, string[2]</param>
/// <returns></returns>
private bool TryGetUserNames(UUID uuid, string[] names)
{
names = new string[2];
if (names == null)
names = new string[2];
if (TryGetUserNamesFromCache(uuid, names))
return true;
if (TryGetUserNamesFromServices(uuid, names))
return true;
return false;
}
private bool TryGetUserNamesFromCache(UUID uuid, string[] names)
{
lock (m_UserCache)
{
if (m_UserCache.ContainsKey(uuid))
@@ -303,6 +333,17 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
}
}
return false;
}
/// <summary>
/// Try to get the names bound to the given uuid, from the services.
/// </summary>
/// <returns>True if the name was found, false if not.</returns>
/// <param name='uuid'></param>
/// <param name='names'>The array of names if found. If not found, then names[0] = "Unknown" and names[1] = "User"</param>
private bool TryGetUserNamesFromServices(UUID uuid, string[] names)
{
UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(UUID.Zero, uuid);
if (account != null)
@@ -387,18 +428,11 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
public string GetUserName(UUID uuid)
{
string[] names;
TryGetUserNames(uuid, out names);
string[] names = new string[2];
TryGetUserNames(uuid, names);
if (names.Length == 2)
{
string firstname = names[0];
string lastname = names[1];
return names[0] + " " + names[1];
return firstname + " " + lastname;
}
return "(hippos)";
}
public string GetUserHomeURL(UUID userID)
@@ -598,13 +632,6 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
protected void Init()
{
RegisterConsoleCmds();
Watchdog.StartThread(
ProcessQueue,
"NameRequestThread",
ThreadPriority.BelowNormal,
true,
false);
}
protected void RegisterConsoleCmds()
@@ -674,39 +701,6 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
MainConsole.Instance.Output(cdt.ToString());
}
private void ProcessQueue()
{
while (true)
{
Watchdog.UpdateThread();
NameRequest request = m_RequestQueue.Dequeue();
string[] names;
bool foundRealName = TryGetUserNames(request.uuid, out names);
if (names.Length == 2)
{
if (!foundRealName)
m_log.DebugFormat("[USER MANAGEMENT MODULE]: Sending {0} {1} for {2} to {3} since no bound name found", names[0], names[1], request.uuid, request.client.Name);
request.client.SendNameReply(request.uuid, names[0], names[1]);
}
}
}
}
class NameRequest
{
public IClientAPI client;
public UUID uuid;
public NameRequest(IClientAPI c, UUID n)
{
client = c;
uuid = n;
}
}
}