HPHP: Drop the request when it's been sitting on the select queue longer than the virtual host timeout allows for.

Drop the request when it's been sitting on the select queue longer than the
virtual host timeout allows for. This is orthogonal to the expiration timeout on
the queue itself.

This can be useful if we ever allow select queue timeout to be configured to be
higher than the virtual host request timeout.
Esse commit está contido em:
Stephen Chen
2013-07-01 19:39:17 -07:00
commit de Sara Golemon
commit fd5d218e8e
4 arquivos alterados com 34 adições e 1 exclusões
@@ -32,6 +32,7 @@
#include "hphp/runtime/base/time/datetime.h"
#include "hphp/runtime/debugger/debugger.h"
#include "hphp/util/alloc.h"
#include "hphp/util/service_data.h"
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
@@ -43,7 +44,10 @@ AccessLog HttpRequestHandler::s_accessLog(
&(HttpRequestHandler::getAccessLogThreadData));
HttpRequestHandler::HttpRequestHandler()
: m_pathTranslation(true) {
: m_pathTranslation(true),
m_requestTimedOutOnQueue(ServiceData::createTimeseries(
"requests_timed_out_on_queue",
{ServiceData::StatsType::COUNT})) {
}
void HttpRequestHandler::sendStaticContent(Transport *transport,
@@ -129,6 +133,24 @@ void HttpRequestHandler::handleRequest(Transport *transport) {
transport->sendString("Not Found", 404);
return;
}
// don't serve the request if it's been sitting in queue for longer than our
// allowed request timeout.
int requestTimeoutSeconds = (vhost->getRequestTimeoutSeconds() > 0 ?
vhost->getRequestTimeoutSeconds() :
RuntimeOption::RequestTimeoutSeconds);
if (requestTimeoutSeconds > 0) {
timespec now;
gettime(CLOCK_MONOTONIC, &now);
const timespec& queueTime = transport->getQueueTime();
if (gettime_diff_us(queueTime, now) > requestTimeoutSeconds * 1000000) {
transport->sendString("Service Unavailable", 503);
m_requestTimedOutOnQueue->addValue(1);
return;
}
}
ServerStats::StartRequest(transport->getCommand().c_str(),
transport->getRemoteHost(),
vhost->getName().c_str());
@@ -26,6 +26,11 @@ namespace HPHP {
class SourceRootInfo;
class RequestURI;
namespace ServiceData {
class ExportedTimeSeries;
}
///////////////////////////////////////////////////////////////////////////////
class HttpRequestHandler : public RequestHandler {
@@ -43,6 +48,7 @@ public:
private:
bool m_pathTranslation;
ServiceData::ExportedTimeSeries* m_requestTimedOutOnQueue;
bool handleProxyRequest(Transport *transport, bool force);
void sendStaticContent(Transport *transport, const char *data, int len,
+4
Ver Arquivo
@@ -136,6 +136,10 @@ void VirtualHost::setRequestTimeoutSeconds() const {
}
}
int VirtualHost::getRequestTimeoutSeconds() const {
return m_runtimeOption.requestTimeoutSeconds;
}
VirtualHost::VirtualHost() : m_disabled(false) {
Hdf empty;
initRuntimeOption(empty);
+1
Ver Arquivo
@@ -42,6 +42,7 @@ public:
void init(Hdf vh);
void addAllowedDirectories(const std::vector<std::string>& dirs);
void setRequestTimeoutSeconds() const;
int getRequestTimeoutSeconds() const;
const std::string &getName() const { return m_name;}
const std::string &getPathTranslation() const { return m_pathTranslation;}