2019-06-14 01:04:59 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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_;
|
2019-06-14 01:04:59 +00:00
|
|
|
};
|
2023-08-23 03:33:30 +00:00
|
|
|
|
2019-06-14 01:04:59 +00:00
|
|
|
class press : public DrObject<press>, public CommandHandler
|
|
|
|
{
|
|
|
|
public:
|
2022-07-26 04:19:54 +00:00
|
|
|
void handleCommand(std::vector<std::string> ¶meters) override;
|
2023-08-23 03:33:30 +00:00
|
|
|
|
2022-07-26 04:19:54 +00:00
|
|
|
std::string script() override
|
2019-06-14 01:04:59 +00:00
|
|
|
{
|
|
|
|
return "Do stress testing(Use 'drogon_ctl help press' for more "
|
|
|
|
"information)";
|
|
|
|
}
|
2023-08-23 03:33:30 +00:00
|
|
|
|
2022-07-26 04:19:54 +00:00
|
|
|
bool isTopCommand() override
|
2019-06-14 01:04:59 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2023-08-23 03:33:30 +00:00
|
|
|
|
2022-07-26 04:19:54 +00:00
|
|
|
std::string detail() override;
|
2019-06-14 01:04:59 +00:00
|
|
|
|
|
|
|
private:
|
2019-11-21 03:27:47 +00:00
|
|
|
size_t numOfThreads_{1};
|
|
|
|
size_t numOfRequests_{1};
|
|
|
|
size_t numOfConnections_{1};
|
2023-12-25 01:39:16 +00:00
|
|
|
bool certValidation_{true};
|
2019-11-21 03:27:47 +00:00
|
|
|
bool processIndication_{true};
|
|
|
|
std::string url_;
|
|
|
|
std::string host_;
|
|
|
|
std::string path_;
|
2019-06-14 01:04:59 +00:00
|
|
|
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_;
|
2019-06-14 01:04:59 +00:00
|
|
|
};
|
|
|
|
} // namespace drogon_ctl
|