2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_WARMUP_REQUEST_HANDLER_H_
18 #define incl_HPHP_WARMUP_REQUEST_HANDLER_H_
22 #include "hphp/runtime/server/server.h"
23 #include "hphp/runtime/server/http-request-handler.h"
26 ///////////////////////////////////////////////////////////////////////////////
28 struct WarmupRequestHandlerFactory
;
31 * WarmupRequestHandler is a small shim on top of HttpRequestHandler.
32 * It counts the number of requests, and adds additional worker threads to the
33 * server after a specified threshold.
35 struct WarmupRequestHandler
: RequestHandler
{
36 explicit WarmupRequestHandler(
38 const std::shared_ptr
<WarmupRequestHandlerFactory
>& factory
)
39 : RequestHandler(timeout
), m_factory(factory
), m_reqHandler(timeout
) {}
41 void setupRequest(Transport
* transport
) override
;
42 void teardownRequest(Transport
* transport
) noexcept override
;
43 void handleRequest(Transport
* transport
) override
;
44 void abortRequest(Transport
* transport
) override
;
45 void logToAccessLog(Transport
* transport
) override
;
48 std::shared_ptr
<WarmupRequestHandlerFactory
> m_factory
;
49 HttpRequestHandler m_reqHandler
;
52 struct WarmupRequestHandlerFactory
53 : std::enable_shared_from_this
<WarmupRequestHandlerFactory
>
55 WarmupRequestHandlerFactory(Server
*server
,
56 uint32_t additionalThreads
,
59 : m_additionalThreads(additionalThreads
),
61 m_warmupReqThreshold(reqCount
),
65 std::unique_ptr
<RequestHandler
> createHandler();
70 std::atomic
<uint32_t> m_additionalThreads
;
71 std::atomic
<uint32_t> m_reqNumber
;
72 uint32_t const m_warmupReqThreshold
;
74 // The server owns this object so will by definition outlive us
78 ///////////////////////////////////////////////////////////////////////////////
81 #endif // incl_HPHP_WARMUP_REQUEST_HANDLER_H_