codemod 2010-2016 to 2010-present
[hiphop-php.git] / hphp / runtime / server / warmup-request-handler.h
blob3fb4a5738ff0adf49a08034ee82145abf2770f5f
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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_
20 #include <memory>
22 #include "hphp/runtime/server/server.h"
23 #include "hphp/runtime/server/http-request-handler.h"
25 namespace HPHP {
26 ///////////////////////////////////////////////////////////////////////////////
28 struct WarmupRequestHandlerFactory;
30 /**
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(
37 int timeout,
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;
47 private:
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,
57 uint32_t reqCount,
58 int timeout)
59 : m_additionalThreads(additionalThreads),
60 m_reqNumber(0),
61 m_warmupReqThreshold(reqCount),
62 m_timeout(timeout),
63 m_server(server) {}
65 std::unique_ptr<RequestHandler> createHandler();
67 void bumpReqCount();
69 private:
70 std::atomic<uint32_t> m_additionalThreads;
71 std::atomic<uint32_t> m_reqNumber;
72 uint32_t const m_warmupReqThreshold;
73 int m_timeout;
74 // The server owns this object so will by definition outlive us
75 Server *m_server;
78 ///////////////////////////////////////////////////////////////////////////////
81 #endif // incl_HPHP_WARMUP_REQUEST_HANDLER_H_