drogon/drogon_ctl/press.h

79 lines
1.8 KiB
C
Raw Normal View History

/**
*
* 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 <drogon/DrObject.h>
#include <drogon/HttpAppFramework.h>
#include <drogon/HttpClient.h>
#include <trantor/utils/Date.h>
#include <trantor/net/EventLoopThreadPool.h>
#include <string>
#include <atomic>
#include <memory>
#include <vector>
using namespace drogon;
namespace drogon_ctl
{
struct Statistics
{
2019-11-21 03:27:47 +00:00
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<press>, public CommandHandler
{
public:
void handleCommand(std::vector<std::string> &parameters) 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:
2019-11-21 03:27:47 +00:00
size_t numOfThreads_{1};
size_t numOfRequests_{1};
size_t numOfConnections_{1};
bool certValidation_{true};
2019-11-21 03:27:47 +00:00
bool processIndication_{true};
std::string url_;
std::string host_;
std::string path_;
void doTesting();
void createRequestAndClients();
void sendRequest(const HttpClientPtr &client);
void outputResults();
2019-11-21 03:27:47 +00:00
std::unique_ptr<trantor::EventLoopThreadPool> loopPool_;
std::vector<HttpClientPtr> clients_;
Statistics statistics_;
};
} // namespace drogon_ctl