Skip to content

Commit

Permalink
Add -k option to the drogon_ctl when running the press command (#1887)
Browse files Browse the repository at this point in the history
* Add -k option to the drogon_ctl when running the press command

* Fix some warnings

* Fix a bug of bytes statistics in HttpClient
  • Loading branch information
an-tao authored Dec 25, 2023
1 parent 125dd0e commit 021c89e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
27 changes: 14 additions & 13 deletions drogon_ctl/press.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <iostream>
#include <memory>
#include <iomanip>
#include <stdlib.h>
#include <cstdlib>
#ifndef _WIN32
#include <unistd.h>
#endif
Expand All @@ -32,8 +32,8 @@ std::string press::detail()
" -n num number of requests(default : 1)\n"
" -t num number of threads(default : 1)\n"
" -c num concurrent connections(default : 1)\n"
// " -k keep alive(default: no)\n"
" -q no progress indication(default: no)\n\n"
" -k disable SSL certificate validation(default: enable)\n"
" -q no progress indication(default: show)\n\n"
"example: drogon_ctl press -n 10000 -c 100 -t 4 -q "
"http://localhost:8080/index.html\n";
}
Expand Down Expand Up @@ -151,11 +151,11 @@ void press::handleCommand(std::vector<std::string> &parameters)
continue;
}
}
// else if (param == "-k")
// {
// keepAlive_ = true;
// continue;
// }
else if (param == "-k")
{
certValidation_ = false;
continue;
}
else if (param == "-q")
{
processIndication_ = false;
Expand All @@ -178,7 +178,7 @@ void press::handleCommand(std::vector<std::string> &parameters)
else
{
auto pos = url_.find("://");
auto posOfPath = url_.find("/", pos + 3);
auto posOfPath = url_.find('/', pos + 3);
if (posOfPath == std::string::npos)
{
host_ = url_;
Expand Down Expand Up @@ -216,8 +216,10 @@ void press::createRequestAndClients()
loopPool_->start();
for (size_t i = 0; i < numOfConnections_; ++i)
{
auto client =
HttpClient::newHttpClient(host_, loopPool_->getNextLoop());
auto client = HttpClient::newHttpClient(host_,
loopPool_->getNextLoop(),
false,
certValidation_);
client->enableCookies();
clients_.push_back(client);
}
Expand Down Expand Up @@ -284,7 +286,6 @@ void press::sendRequest(const HttpClientPtr &client)

void press::outputResults()
{
static std::mutex mtx;
size_t totalSent = 0;
size_t totalRecv = 0;
for (auto &client : clients_)
Expand All @@ -296,7 +297,7 @@ void press::outputResults()
auto microSecs = now.microSecondsSinceEpoch() -
statistics_.startDate_.microSecondsSinceEpoch();
double seconds = (double)microSecs / 1000000.0;
size_t rps = static_cast<size_t>(statistics_.numOfGoodResponse_ / seconds);
auto rps = static_cast<size_t>(statistics_.numOfGoodResponse_ / seconds);
std::cout << std::endl;
std::cout << "TOTALS: " << numOfConnections_ << " connect, "
<< numOfRequests_ << " requests, "
Expand Down
2 changes: 1 addition & 1 deletion drogon_ctl/press.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class press : public DrObject<press>, public CommandHandler
size_t numOfThreads_{1};
size_t numOfRequests_{1};
size_t numOfConnections_{1};
// bool keepAlive_ = false;
bool certValidation_{true};
bool processIndication_{true};
std::string url_;
std::string host_;
Expand Down
1 change: 1 addition & 0 deletions lib/src/HttpClientImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ void HttpClientImpl::onRecvMessage(const trantor::TcpConnectionPtr &connPtr,
}
else
{
bytesReceived_ += (msgSize - msg->readableBytes());
break;
}
}
Expand Down

0 comments on commit 021c89e

Please sign in to comment.