/** * * press.h * An Tao * * Copyright 2018, An Tao. All rights reserved. * https://github.com/an-tao/drogon * Use of this source code is governed by the MIT license * that can be found in the License file. * * Drogon * */ #pragma once #include "CommandHandler.h" #include #include #include #include #include #include #include #include #include using namespace drogon; namespace drogon_ctl { struct Statistics { std::atomic_size_t numOfRequestsSent_{0}; std::atomic_size_t bytesRecieved_{0}; std::atomic_size_t numOfGoodResponse_{0}; std::atomic_size_t numOfBadResponse_{0}; std::atomic_size_t totalDelay_{0}; trantor::Date startDate_; trantor::Date endDate_; }; class press : public DrObject, public CommandHandler { public: void handleCommand(std::vector ¶meters) override; std::string script() override { return "Do stress testing(Use 'drogon_ctl help press' for more " "information)"; } bool isTopCommand() override { return true; } std::string detail() override; private: size_t numOfThreads_{1}; size_t numOfRequests_{1}; size_t numOfConnections_{1}; // bool keepAlive_ = false; bool processIndication_{true}; std::string url_; std::string host_; std::string path_; void doTesting(); void createRequestAndClients(); void sendRequest(const HttpClientPtr &client); void outputResults(); std::unique_ptr loopPool_; std::vector clients_; Statistics statistics_; }; } // namespace drogon_ctl