Commit d547d044 by Amir Aharon

1.5.2 fix crash and performance testing

parent 75dc2fb7
......@@ -3,7 +3,7 @@ project(Microservice)
# version stuff
set (Microservice_VERSION_MAJOR 1)
set (Microservice_VERSION_MINOR 5)
set (Microservice_VERSION_PATCH 1)
set (Microservice_VERSION_PATCH 2)
set(Microservice_VERSION_STRING ${Microservice_VERSION_MAJOR}.${Microservice_VERSION_MINOR}.${Microservice_VERSION_PATCH})
# type build flags
......
## C++ Microservice Framework
* to create microservice docker run script/build_microservice_docker.sh [version]
## VERSIONS:
# 1.5.2
- Fix for sigegv
- testing http client performance
# 1.5.1
- Fully functioning evpp rest client , async only
# 1.5.0
......
......@@ -291,7 +291,8 @@ MSRetStat MSICommandClientEvppImpl::HandleAsyncCommandAndCallback(HandleAsyncCom
* if we use shared_ptr for requestPtr, we could end up
* with a case where this call back executed before the enclosing block.
*/
delete requestPtr;
//delete requestPtr;
delete responsePtr->request();
});
} else {
retstat.SetError("Unsupported method");
......
......@@ -15,7 +15,8 @@ EvppRequest::EvppRequest(ConnPool* pool, EventLoop* loop, evhttp_cmd_type req_ty
EvppRequest::EvppRequest(EventLoop* loop, evhttp_cmd_type req_type, const std::string& http_url, const std::string& body, Duration timeout)
: pool_(nullptr), loop_(loop), req_type_(req_type), body_(body) {
// Test
//LOG_INFO << "EvppRequest()";
//TODO performance compare
#if LIBEVENT_VERSION_NUMBER >= 0x02001500
struct evhttp_uri* evuri = evhttp_uri_parse(http_url.c_str());
......@@ -48,6 +49,7 @@ EvppRequest::EvppRequest(EventLoop* loop, evhttp_cmd_type req_type, const std::s
}
EvppRequest::~EvppRequest() {
//LOG_INFO << "~EvppRequest()";
assert(loop_->IsInLoopThread());
}
......
#include <iostream>
#include <common/Microservice_MsgQContext.h>
#include <thread>
#include <utils/CommonUtils.h>
#include <utils/ClientFactory.h>
namespace evpptest {
static const int ITERATIONS = 100;
void testEvppRequestResponse(cMicroservice_Client* p_client,std::string& url,std::string& testPass){
std::atomic_int testPassedNumber(0);
std::map<std::string,std::string> headers;
// headers["Content-Type"] = "application/json";
//std::string uri = "http://echo.jpillora.com";
MSCommandParams msCmndParams;
msCmndParams.WithEntity(url);
// .WithRequestParams("q=base")
// .WithHeadersMap(&headers)
// .WithContent(body);
auto f = [&testPassedNumber,&testPass](cMicroservice_BaseRestResponse* p_baseRestResponse){
if(p_baseRestResponse->IsSuccess()){
//std::cout << __PRETTY_FUNCTION__ << ": Success, Object =>" << std::endl;
testPass = "success";
} else {
//std::cout << __PRETTY_FUNCTION__ << ": Error" << std::endl;
testPass = p_baseRestResponse->GetError();
}
testPassedNumber++;
};
p_client->AsyncRead(&msCmndParams, f);
while (testPassedNumber < 1)
{
usleep(1);
}
}
void testEvppPerformance(cMicroservice_Client* p_client,std::string& url,int& iterations, std::string& testPass){
std::atomic_int testPassedNumber(0);
MSCommandParams msCmndParams;
auto f = [&testPassedNumber,&testPass](cMicroservice_BaseRestResponse* p_baseRestResponse){
if(p_baseRestResponse->IsSuccess()){
//std::cout << __PRETTY_FUNCTION__ << ": Success, Object =>" << std::endl;
testPass = "success";
} else {
//std::cout << __PRETTY_FUNCTION__ << ": Error" << std::endl;
testPass = p_baseRestResponse->GetError();
}
testPassedNumber++;
};
for (int i = 0; i < iterations; i++){
msCmndParams.WithEntity(url);
p_client->AsyncRead(&msCmndParams, f);
}
while (testPassedNumber < iterations)
{
usleep(1);
}
}
class TestEvppClient : public nsMicroservice_Iface::ITest {
private:
cMicroservice_Client* p_client_;
int getIterations(DequeStringMap& queryParams){
int iterations = ITERATIONS;
auto iterator = queryParams.find("iterations");
if (iterator != queryParams.end()){
iterations = std::atoi(iterator->second.begin()->c_str());
}
return iterations;
}
std::string getUrl(DequeStringMap& queryParams){
auto iterator = queryParams.find("url");
if (iterator != queryParams.end()){
return iterator->second.begin()->c_str();
}
return std::string("");
}
public:
TestEvppClient(){
p_client_ = ClientFactory::createEvppCommandImpl("evpp-test");
}
virtual void getAllTests(TestsMap &testsMap) override {
testsMap["testEvppRequestResponse"] = [this](std::stringstream& output,DequeStringMap& queryParams) -> MSRetStat {
std::string url = getUrl(queryParams);
std::string testPass;
if (url.size() > 0){
auto testDuration = CommonUtils::measureFunc<>(testEvppRequestResponse,p_client_,url,testPass);
output << "test success/fail: " << testPass.c_str() << " for url: " << url.c_str() << ", took: " << testDuration << " msec";
}
else
output << "Empty url param!";
return MSRetStat();
};
testsMap["testEvppPerformance"] = [this](std::stringstream& output,DequeStringMap& queryParams) -> MSRetStat {
int iterations = getIterations(queryParams);
std::string url = getUrl(queryParams);
std::string testPass;
if (url.size() > 0){
auto testDuration = CommonUtils::measureFunc<>(testEvppPerformance,p_client_,url,iterations,testPass);
output << "test of " << iterations << ", success/fail: " << testPass.c_str() << " for url: " << url.c_str() << ", took: " << testDuration << " msec";
}
else
output << "Empty url param!";
return MSRetStat();
};
}
};
}
\ No newline at end of file
......@@ -30,6 +30,7 @@
#include <impl/MsgArchiverJsonImpl.h>
#include "Microservice_ZMQTest.cpp"
#include "common/json.hpp"
#include "Microservice_EvppClientTest.cpp"
static const char *const START = "Start";
static const char *const STOP = "Stop";
......@@ -109,10 +110,10 @@ public:
rpj_Doc.AddMember(rapidjson::StringRef(it->first.c_str()),rapidjson::StringRef(dequeIt->c_str()),rpj_Alloc);
}
}
ReadAsyncEvpp(pc_reqCtx);
//ReadAsyncEvpp(pc_reqCtx);
//ReadSync(pc_reqCtx);
// ReadAsync2(pc_reqCtx);
// this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
// add metric
long value = rand() % 1000 + 1;
p_histo->update(value);
......@@ -407,6 +408,7 @@ int main(int argc, char *argv[])
cMicroservice_BaseClientParams clientParams("other-service", true, 10, false,"localhost",32010,"localhost:6379");
zmqtest::TestZMQ testZMQ;
evpptest::TestEvppClient testEvppClient;
Microservice_App msApp("myCppService");
msApp
......@@ -425,6 +427,7 @@ int main(int argc, char *argv[])
.addHandler("/xxx",(Microservice_RestHandler*)new cMicroserviceHandler("hello"))
.addHandler("/zmq",new MSMsgQHandler())
.addTest(&testZMQ)
.addTest(&testEvppClient)
.build()
.run();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment