mirror of
https://github.com/opensim/opensim.git
synced 2026-07-31 13:55:35 +08:00
Experimental test to rate limit the incoming packet handler and try to always leave a worker thread available for other tasks
This commit is contained in:
@@ -1330,6 +1330,27 @@ namespace OpenSim.Framework
|
||||
m_ThreadPool = new SmartThreadPool(2000, maxThreads, 2);
|
||||
}
|
||||
|
||||
public static int FireAndForgetCount()
|
||||
{
|
||||
const int MAX_SYSTEM_THREADS = 200;
|
||||
|
||||
switch (FireAndForgetMethod)
|
||||
{
|
||||
case FireAndForgetMethod.UnsafeQueueUserWorkItem:
|
||||
case FireAndForgetMethod.QueueUserWorkItem:
|
||||
case FireAndForgetMethod.BeginInvoke:
|
||||
int workerThreads, iocpThreads;
|
||||
ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads);
|
||||
return workerThreads;
|
||||
case FireAndForgetMethod.SmartThreadPool:
|
||||
return m_ThreadPool.MaxThreads - m_ThreadPool.InUseThreads;
|
||||
case FireAndForgetMethod.Thread:
|
||||
return MAX_SYSTEM_THREADS - System.Diagnostics.Process.GetCurrentProcess().Threads.Count;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void FireAndForget(System.Threading.WaitCallback callback, object obj)
|
||||
{
|
||||
switch (FireAndForgetMethod)
|
||||
|
||||
@@ -801,6 +801,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
{
|
||||
IncomingPacket incomingPacket = null;
|
||||
|
||||
// HACK: This is a test to try and rate limit packet handling on Mono.
|
||||
// If it works, a more elegant solution can be devised
|
||||
if (Util.FireAndForgetCount() < 2)
|
||||
{
|
||||
//m_log.Debug("[LLUDPSERVER]: Incoming packet handler is sleeping");
|
||||
Thread.Sleep(30);
|
||||
}
|
||||
|
||||
if (packetInbox.Dequeue(100, ref incomingPacket))
|
||||
Util.FireAndForget(ProcessInPacket, incomingPacket);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user