31d042061c
This moves the warmup thread logic from LibEventServer to a new WarmupRequestHandler class. This will allow the logic to work with any server implementation, since it isn't really specific to LibEventServer. (Eventually it would perhaps be nice to decouple the worker thread behavior from the server I/O implementation entirely.)
64 linhas
2.4 KiB
C++
64 linhas
2.4 KiB
C++
/*
|
|
+----------------------------------------------------------------------+
|
|
| HipHop for PHP |
|
|
+----------------------------------------------------------------------+
|
|
| Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
|
|
+----------------------------------------------------------------------+
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
| available through the world-wide-web at the following url: |
|
|
| http://www.php.net/license/3_01.txt |
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
+----------------------------------------------------------------------+
|
|
*/
|
|
|
|
#include "hphp/runtime/base/server/warmup_request_handler.h"
|
|
|
|
#include "folly/Memory.h"
|
|
|
|
using folly::make_unique;
|
|
|
|
namespace HPHP {
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void WarmupRequestHandler::handleRequest(Transport *transport) {
|
|
// There is one WarmupRequestHandler per-thread, but we want to track request
|
|
// count across all threads. Therefore we let WarmupRequestHandlerFactory
|
|
// track the global request count.
|
|
m_factory->bumpReqCount();
|
|
m_reqHandler.handleRequest(transport);
|
|
}
|
|
|
|
std::unique_ptr<RequestHandler> WarmupRequestHandlerFactory::createHandler() {
|
|
return make_unique<WarmupRequestHandler>(shared_from_this());
|
|
}
|
|
|
|
void WarmupRequestHandlerFactory::bumpReqCount() {
|
|
// Bump the request count. When we hit m_warmupReqThreshold,
|
|
// add additional threads to the server.
|
|
auto const oldReqNum = m_reqNumber.fetch_add(1, std::memory_order_relaxed);
|
|
if (oldReqNum != m_warmupReqThreshold) {
|
|
return;
|
|
}
|
|
|
|
auto const num = m_additionalThreads.load();
|
|
if (!num) {
|
|
return;
|
|
}
|
|
ServerPtr server = m_server.lock();
|
|
if (!server) {
|
|
return;
|
|
}
|
|
|
|
Logger::Info("Finished warmup; adding %d new worker threads", num);
|
|
server->addWorkers(num);
|
|
|
|
// Set to zero so we can't do it if the req counter wraps.
|
|
m_additionalThreads.store(0);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
}
|