Arquivos
hhvm/hphp/runtime/server/warmup_request_handler.cpp
T
mwilliams a946a8eb35 Get rid of TimeoutThread(s)
Use timer events instead. A side effect is that we now
support timeout in client mode. We also get much more
accurate timeouts. Previously starting a server with
a timeout of 4s, and GETing an endpoint that just looped,
would timeout somewhere between 3.5(!) and 8 seconds. Now
it times out between 4.0001 and 4.02s.

This will also make fixing pagelet timeouts much easier.
2013-07-24 10:35:43 -07:00

64 linhas
2.4 KiB
C++

/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2013 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/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>(m_timeout, 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);
}
///////////////////////////////////////////////////////////////////////////////
}