Reverting the reverts I did yesterday. cpu-branch has now been

successfully tested, and I'm merging back those changes, which proved to
be good.
Revert "Revert "Cleared up much confusion in PollServiceRequestManager. Here's the history:""

This reverts commit fa2370b32e.
This commit is contained in:
Diva Canto
2013-07-18 12:23:27 -07:00
parent ae997fffee
commit 9e35b069a4
4 changed files with 41 additions and 52 deletions

View File

@@ -47,12 +47,11 @@ namespace OpenSim.Framework.Servers.HttpServer
private readonly BaseHttpServer m_server;
private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>();
private static Queue<PollServiceHttpRequest> m_slowRequests = new Queue<PollServiceHttpRequest>();
private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>();
private static Queue<PollServiceHttpRequest> m_longPollRequests = new Queue<PollServiceHttpRequest>();
private uint m_WorkerThreadCount = 0;
private Thread[] m_workerThreads;
private Thread m_retrysThread;
private Thread m_longPollThread;
private bool m_running = true;
private int slowCount = 0;
@@ -84,9 +83,9 @@ namespace OpenSim.Framework.Servers.HttpServer
int.MaxValue);
}
m_retrysThread = Watchdog.StartThread(
this.CheckRetries,
string.Format("PollServiceWatcherThread:{0}", m_server.Port),
m_longPollThread = Watchdog.StartThread(
this.CheckLongPollThreads,
string.Format("LongPollServiceWatcherThread:{0}", m_server.Port),
ThreadPriority.Normal,
false,
true,
@@ -97,48 +96,47 @@ namespace OpenSim.Framework.Servers.HttpServer
private void ReQueueEvent(PollServiceHttpRequest req)
{
if (m_running)
{
lock (m_retryRequests)
m_retryRequests.Enqueue(req);
}
m_requests.Enqueue(req);
}
public void Enqueue(PollServiceHttpRequest req)
{
if (m_running)
{
if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.Normal)
if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll)
{
m_requests.Enqueue(req);
lock (m_longPollRequests)
m_longPollRequests.Enqueue(req);
}
else
{
lock (m_slowRequests)
m_slowRequests.Enqueue(req);
}
m_requests.Enqueue(req);
}
}
private void CheckRetries()
private void CheckLongPollThreads()
{
// The only purpose of this thread is to check the EQs for events.
// If there are events, that thread will be placed in the "ready-to-serve" queue, m_requests.
// If there are no events, that thread will be back to its "waiting" queue, m_longPollRequests.
// All other types of tasks (Inventory handlers) don't have the long-poll nature,
// so if they aren't ready to be served by a worker thread (no events), they are placed
// directly back in the "ready-to-serve" queue by the worker thread.
while (m_running)
{
Thread.Sleep(100); // let the world move .. back to faster rate
Thread.Sleep(1000);
Watchdog.UpdateThread();
lock (m_retryRequests)
{
while (m_retryRequests.Count > 0 && m_running)
m_requests.Enqueue(m_retryRequests.Dequeue());
}
slowCount++;
if (slowCount >= 10)
{
slowCount = 0;
lock (m_slowRequests)
PollServiceHttpRequest req;
lock (m_longPollRequests)
{
while (m_longPollRequests.Count > 0 && m_running)
{
while (m_slowRequests.Count > 0 && m_running)
m_requests.Enqueue(m_slowRequests.Dequeue());
req = m_longPollRequests.Dequeue();
if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id) || // there are events in this EQ
(Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) // no events, but timeout
m_requests.Enqueue(req);
else
m_longPollRequests.Enqueue(req);
}
}
}
@@ -153,24 +151,12 @@ namespace OpenSim.Framework.Servers.HttpServer
foreach (Thread t in m_workerThreads)
Watchdog.AbortThread(t.ManagedThreadId);
try
{
foreach (PollServiceHttpRequest req in m_retryRequests)
{
req.DoHTTPGruntWork(m_server, req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
}
}
catch
{
}
PollServiceHttpRequest wreq;
m_retryRequests.Clear();
lock (m_slowRequests)
lock (m_longPollRequests)
{
while (m_slowRequests.Count > 0 && m_running)
m_requests.Enqueue(m_slowRequests.Dequeue());
while (m_longPollRequests.Count > 0 && m_running)
m_requests.Enqueue(m_longPollRequests.Dequeue());
}
while (m_requests.Count() > 0)
@@ -196,6 +182,7 @@ namespace OpenSim.Framework.Servers.HttpServer
while (m_running)
{
PollServiceHttpRequest req = m_requests.Dequeue(5000);
//m_log.WarnFormat("[YYY]: Dequeued {0}", (req == null ? "null" : req.PollServiceArgs.Type.ToString()));
Watchdog.UpdateThread();
if (req != null)
@@ -209,7 +196,7 @@ namespace OpenSim.Framework.Servers.HttpServer
if (responsedata == null)
continue;
if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.Normal) // This is the event queue
if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll) // This is the event queue
{
try
{