In the pursuit of using less CPU: now trying to avoid blocking queues altogether. Instead, this uses a timer. No sure if it's better or worse, but worth the try.

cpu-performance
Diva Canto 2013-07-16 13:01:39 -07:00
parent 6da50d34df
commit e0f0b88dec
2 changed files with 120 additions and 15 deletions

View File

@ -48,18 +48,26 @@ namespace OpenSim.Region.CoreModules.Framework
MethodBase.GetCurrentMethod().DeclaringType); MethodBase.GetCurrentMethod().DeclaringType);
private readonly List<Scene> m_scenes = new List<Scene>(); 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 OpenSim.Framework.BlockingQueue<GridRegionRequest> m_RequestQueue = new OpenSim.Framework.BlockingQueue<GridRegionRequest>();
private OpenSim.Framework.DoubleQueue<GridRegionRequest> m_RequestQueue = new OpenSim.Framework.DoubleQueue<GridRegionRequest>(); // private OpenSim.Framework.DoubleQueue<GridRegionRequest> m_RequestQueue = new OpenSim.Framework.DoubleQueue<GridRegionRequest>();
private Queue<GridRegionRequest> m_RequestQueue = new Queue<GridRegionRequest>();
public void Initialise(IConfigSource config) public void Initialise(IConfigSource config)
{ {
Watchdog.StartThread( m_timer = new System.Timers.Timer();
ProcessQueue, m_timer.AutoReset = false;
"GridServiceRequestThread", m_timer.Interval = 15000; // 15 secs at first
ThreadPriority.BelowNormal, m_timer.Elapsed += ProcessQueue;
true, m_timer.Start();
false);
//Watchdog.StartThread(
// ProcessQueue,
// "GridServiceRequestThread",
// ThreadPriority.BelowNormal,
// true,
// false);
} }
public void AddRegion(Scene scene) public void AddRegion(Scene scene)
@ -89,6 +97,16 @@ namespace OpenSim.Region.CoreModules.Framework
client.OnRegionHandleRequest += OnRegionHandleRequest; client.OnRegionHandleRequest += OnRegionHandleRequest;
} }
//void OnMakeRootAgent(ScenePresence obj)
//{
// lock (m_timer)
// {
// m_timer.Stop();
// m_timer.Interval = 1000;
// m_timer.Start();
// }
//}
public void PostInitialise() public void PostInitialise()
{ {
} }
@ -118,7 +136,8 @@ namespace OpenSim.Region.CoreModules.Framework
} }
GridRegionRequest request = new GridRegionRequest(client, regionID); GridRegionRequest request = new GridRegionRequest(client, regionID);
m_RequestQueue.Enqueue(request); lock (m_RequestQueue)
m_RequestQueue.Enqueue(request);
} }
@ -134,6 +153,41 @@ namespace OpenSim.Region.CoreModules.Framework
return false; return false;
} }
private bool AreThereRootAgents()
{
foreach (Scene s in m_scenes)
{
if (s.GetRootAgentCount() > 0)
return true;
}
return false;
}
private void ProcessQueue(object sender, System.Timers.ElapsedEventArgs e)
{
while (m_RequestQueue.Count > 0)
{
GridRegionRequest request = null;
lock (m_RequestQueue)
request = m_RequestQueue.Dequeue();
if (request != null)
{
GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, request.regionID);
if (r != null && r.RegionHandle != 0)
request.client.SendRegionHandle(request.regionID, r.RegionHandle);
}
}
if (AreThereRootAgents())
m_timer.Interval = 1000; // 1 sec
else
m_timer.Interval = 10000; // 10 secs
m_timer.Start();
}
private void ProcessQueue() private void ProcessQueue()
{ {
while (true) while (true)
@ -150,6 +204,7 @@ namespace OpenSim.Region.CoreModules.Framework
} }
} }
} }
} }
class GridRegionRequest class GridRegionRequest

View File

@ -61,8 +61,10 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
// Throttle the name requests // Throttle the name requests
//private OpenSim.Framework.BlockingQueue<NameRequest> m_RequestQueue = new OpenSim.Framework.BlockingQueue<NameRequest>(); //private OpenSim.Framework.BlockingQueue<NameRequest> m_RequestQueue = new OpenSim.Framework.BlockingQueue<NameRequest>();
private OpenSim.Framework.DoubleQueue<NameRequest> m_RequestQueue = new OpenSim.Framework.DoubleQueue<NameRequest>(); //private OpenSim.Framework.DoubleQueue<NameRequest> m_RequestQueue = new OpenSim.Framework.DoubleQueue<NameRequest>();
private Queue<NameRequest> m_RequestQueue = new Queue<NameRequest>();
private System.Timers.Timer m_timer;
#region ISharedRegionModule #region ISharedRegionModule
@ -599,12 +601,18 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
protected void Init() protected void Init()
{ {
RegisterConsoleCmds(); RegisterConsoleCmds();
Watchdog.StartThread( //Watchdog.StartThread(
ProcessQueue, // ProcessQueue,
"NameRequestThread", // "NameRequestThread",
ThreadPriority.BelowNormal, // ThreadPriority.BelowNormal,
true, // true,
false); // false);
m_timer = new System.Timers.Timer();
m_timer.AutoReset = false;
m_timer.Interval = 15000; // 15 secs at first
m_timer.Elapsed += ProcessQueue;
m_timer.Start();
} }
@ -698,6 +706,48 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
} }
} }
private bool AreThereRootAgents()
{
foreach (Scene s in m_Scenes)
{
if (s.GetRootAgentCount() > 0)
return true;
}
return false;
}
private void ProcessQueue(object sender, System.Timers.ElapsedEventArgs e)
{
while (m_RequestQueue.Count > 0)
{
NameRequest request = null;
lock (m_RequestQueue)
request = m_RequestQueue.Dequeue();
if (request != null)
{
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]);
}
}
}
if (AreThereRootAgents())
m_timer.Interval = 1000; // 1 sec
else
m_timer.Interval = 10000; // 10 secs
m_timer.Start();
}
} }
class NameRequest class NameRequest