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"
24 #include "hphp/util/job-queue.h"
27 ///////////////////////////////////////////////////////////////////////////////
29 struct WarmupRequestHandlerFactory
;
32 * WarmupRequestHandler is a small shim on top of HttpRequestHandler.
33 * It counts the number of requests, and adds additional worker threads to the
34 * server after a specified threshold.
36 struct WarmupRequestHandler
: RequestHandler
{
37 explicit WarmupRequestHandler(
39 const std::shared_ptr
<WarmupRequestHandlerFactory
>& factory
)
40 : RequestHandler(timeout
), m_factory(factory
), m_reqHandler(timeout
) {}
42 void setupRequest(Transport
* transport
) override
;
43 void teardownRequest(Transport
* transport
) noexcept override
;
44 void handleRequest(Transport
* transport
) override
;
45 void abortRequest(Transport
* transport
) override
;
46 void logToAccessLog(Transport
* transport
) override
;
49 std::shared_ptr
<WarmupRequestHandlerFactory
> m_factory
;
50 HttpRequestHandler m_reqHandler
;
53 struct WarmupRequestHandlerFactory
54 : std::enable_shared_from_this
<WarmupRequestHandlerFactory
>
56 WarmupRequestHandlerFactory(Server
*server
,
60 m_warmupReqThreshold(reqCount
),
64 std::unique_ptr
<RequestHandler
> createHandler();
69 std::atomic
<uint32_t> m_reqNumber
;
70 uint32_t const m_warmupReqThreshold
;
72 // The server owns this object so will by definition outlive us
77 const std::string hdfFile
;
81 struct InternalWarmupWorker
: JobQueueWorker
<WarmupJob
> {
82 void doJob(WarmupJob job
) override
;
85 struct InternalWarmupRequestPlayer
: JobQueueDispatcher
<InternalWarmupWorker
> {
86 // Don't inline into header file without testing performance on MacOS:
87 // https://github.com/facebook/hhvm/issues/8515
88 // Problem tested on 2019-06-11 on MacOS High Sierra and Mojave
89 // Apple LLVM version 10.0.1 (clang-1001.0.46.4)
90 // Target: x86_64-apple-darwin18.5.0
91 explicit InternalWarmupRequestPlayer(int threadCount
);
92 ~InternalWarmupRequestPlayer();
94 // Start running after an optional delay.
95 void runAfterDelay(const std::vector
<std::string
>& files
,
97 unsigned delaySeconds
= 0);
100 ///////////////////////////////////////////////////////////////////////////////
103 #endif // incl_HPHP_WARMUP_REQUEST_HANDLER_H_