for (int i = 0; i < 2; i++)
SpawnWorker();
- boost::thread reportThread(boost::bind(&EventQueue::ReportThreadProc, this));
- reportThread.detach();
+ boost::thread managerThread(boost::bind(&EventQueue::ManagerThreadProc, this));
+ managerThread.detach();
}
EventQueue::~EventQueue(void)
m_ThreadStates[tid] = ThreadBusy;
- m_Latency += Utility::GetTime() - event.Timestamp;
+ double latency = Utility::GetTime() - event.Timestamp;
+
+ m_Latency += latency;
m_LatencyCount++;
+
+ if (latency > m_MaxLatency)
+ m_MaxLatency = latency;
}
#ifdef _DEBUG
m_CV.notify_one();
}
-void EventQueue::ReportThreadProc(void)
+void EventQueue::ManagerThreadProc(void)
{
for (;;) {
Utility::Sleep(5);
double now = Utility::GetTime();
int pending, alive, busy;
- double avg_latency;
+ double avg_latency, max_latency;
{
boost::mutex::scoped_lock lock(m_Mutex);
m_Latency = 0;
m_LatencyCount = 0;
- if (pending > alive - busy) {
+ max_latency = m_MaxLatency;
+ m_MaxLatency = 0;
+
+ if (max_latency > 0.1) {
/* Spawn a few additional workers. */
for (int i = 0; i < 8; i++)
SpawnWorker();
}
std::ostringstream msgbuf;
- msgbuf << "Pending tasks: " << pending << "; Busy threads: " << busy << "; Idle threads: " << alive - busy << "; Average latency: " << (long)(avg_latency * 1000) << "ms";
+ msgbuf << "Pending tasks: " << pending << "; Busy threads: " << busy
+ << "; Idle threads: " << alive - busy << "; Average latency: " << (long)(avg_latency * 1000) << "ms"
+ << "; Max latency: " << (long)(max_latency * 1000) << "ms";
Log(LogInformation, "base", msgbuf.str());
}
}
{
for (int i = 0; i < sizeof(m_ThreadStates) / sizeof(m_ThreadStates[0]); i++) {
if (m_ThreadStates[i] == ThreadDead) {
- Log(LogInformation, "debug", "Spawning worker thread.");
+ Log(LogDebug, "debug", "Spawning worker thread.");
m_ThreadStates[i] = ThreadIdle;
boost::thread worker(boost::bind(&EventQueue::QueueThreadProc, this, i));
*/
void EventQueue::KillWorker(void)
{
- Log(LogInformation, "base", "Killing worker thread.");
+ Log(LogDebug, "base", "Killing worker thread.");
m_ThreadDeaths++;
}