Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery.common.cpp
/
Microservice
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d547d044
authored
Jul 04, 2018
by
Amir Aharon
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.5.2 fix crash and performance testing
parent
75dc2fb7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
132 additions
and
5 deletions
CMakeLists.txt
README.md
src/impl/clients/MSICommandClientEvppImpl.cpp
src/utils/EvppRequest.cpp
test/Microservice_EvppClientTest.cpp
test/Microservice_Test.cpp
CMakeLists.txt
View file @
d547d044
...
@@ -3,7 +3,7 @@ project(Microservice)
...
@@ -3,7 +3,7 @@ project(Microservice)
# version stuff
# version stuff
set
(
Microservice_VERSION_MAJOR 1
)
set
(
Microservice_VERSION_MAJOR 1
)
set
(
Microservice_VERSION_MINOR 5
)
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
}
)
set
(
Microservice_VERSION_STRING
${
Microservice_VERSION_MAJOR
}
.
${
Microservice_VERSION_MINOR
}
.
${
Microservice_VERSION_PATCH
}
)
# type build flags
# type build flags
...
...
README.md
View file @
d547d044
## C++ Microservice Framework
## C++ Microservice Framework
*
to create microservice docker run script/build_microservice_docker.sh
[
version
]
*
to create microservice docker run script/build_microservice_docker.sh
[
version
]
## VERSIONS:
## VERSIONS:
# 1.5.2
-
Fix for sigegv
-
testing http client performance
# 1.5.1
# 1.5.1
-
Fully functioning evpp rest client , async only
-
Fully functioning evpp rest client , async only
# 1.5.0
# 1.5.0
...
...
src/impl/clients/MSICommandClientEvppImpl.cpp
View file @
d547d044
...
@@ -291,7 +291,8 @@ MSRetStat MSICommandClientEvppImpl::HandleAsyncCommandAndCallback(HandleAsyncCom
...
@@ -291,7 +291,8 @@ MSRetStat MSICommandClientEvppImpl::HandleAsyncCommandAndCallback(HandleAsyncCom
* if we use shared_ptr for requestPtr, we could end up
* if we use shared_ptr for requestPtr, we could end up
* with a case where this call back executed before the enclosing block.
* with a case where this call back executed before the enclosing block.
*/
*/
delete
requestPtr
;
//delete requestPtr;
delete
responsePtr
->
request
();
});
});
}
else
{
}
else
{
retstat
.
SetError
(
"Unsupported method"
);
retstat
.
SetError
(
"Unsupported method"
);
...
...
src/utils/EvppRequest.cpp
View file @
d547d044
...
@@ -15,7 +15,8 @@ EvppRequest::EvppRequest(ConnPool* pool, EventLoop* loop, evhttp_cmd_type req_ty
...
@@ -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
)
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
)
{
:
pool_
(
nullptr
),
loop_
(
loop
),
req_type_
(
req_type
),
body_
(
body
)
{
// Test
//LOG_INFO << "EvppRequest()";
//TODO performance compare
//TODO performance compare
#if LIBEVENT_VERSION_NUMBER >= 0x02001500
#if LIBEVENT_VERSION_NUMBER >= 0x02001500
struct
evhttp_uri
*
evuri
=
evhttp_uri_parse
(
http_url
.
c_str
());
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
...
@@ -48,6 +49,7 @@ EvppRequest::EvppRequest(EventLoop* loop, evhttp_cmd_type req_type, const std::s
}
}
EvppRequest
::~
EvppRequest
()
{
EvppRequest
::~
EvppRequest
()
{
//LOG_INFO << "~EvppRequest()";
assert
(
loop_
->
IsInLoopThread
());
assert
(
loop_
->
IsInLoopThread
());
}
}
...
...
test/Microservice_EvppClientTest.cpp
0 → 100644
View file @
d547d044
#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
test/Microservice_Test.cpp
View file @
d547d044
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include <impl/MsgArchiverJsonImpl.h>
#include <impl/MsgArchiverJsonImpl.h>
#include "Microservice_ZMQTest.cpp"
#include "Microservice_ZMQTest.cpp"
#include "common/json.hpp"
#include "common/json.hpp"
#include "Microservice_EvppClientTest.cpp"
static
const
char
*
const
START
=
"Start"
;
static
const
char
*
const
START
=
"Start"
;
static
const
char
*
const
STOP
=
"Stop"
;
static
const
char
*
const
STOP
=
"Stop"
;
...
@@ -109,10 +110,10 @@ public:
...
@@ -109,10 +110,10 @@ public:
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
it
->
first
.
c_str
()),
rapidjson
::
StringRef
(
dequeIt
->
c_str
()),
rpj_Alloc
);
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);
//ReadSync(pc_reqCtx);
// ReadAsync2(pc_reqCtx);
// ReadAsync2(pc_reqCtx);
//
this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
this
->
WriteObjectToResponse
(
pc_reqCtx
,
rpj_Doc
);
// add metric
// add metric
long
value
=
rand
()
%
1000
+
1
;
long
value
=
rand
()
%
1000
+
1
;
p_histo
->
update
(
value
);
p_histo
->
update
(
value
);
...
@@ -407,6 +408,7 @@ int main(int argc, char *argv[])
...
@@ -407,6 +408,7 @@ int main(int argc, char *argv[])
cMicroservice_BaseClientParams
clientParams
(
"other-service"
,
true
,
10
,
false
,
"localhost"
,
32010
,
"localhost:6379"
);
cMicroservice_BaseClientParams
clientParams
(
"other-service"
,
true
,
10
,
false
,
"localhost"
,
32010
,
"localhost:6379"
);
zmqtest
::
TestZMQ
testZMQ
;
zmqtest
::
TestZMQ
testZMQ
;
evpptest
::
TestEvppClient
testEvppClient
;
Microservice_App
msApp
(
"myCppService"
);
Microservice_App
msApp
(
"myCppService"
);
msApp
msApp
...
@@ -425,6 +427,7 @@ int main(int argc, char *argv[])
...
@@ -425,6 +427,7 @@ int main(int argc, char *argv[])
.
addHandler
(
"/xxx"
,(
Microservice_RestHandler
*
)
new
cMicroserviceHandler
(
"hello"
))
.
addHandler
(
"/xxx"
,(
Microservice_RestHandler
*
)
new
cMicroserviceHandler
(
"hello"
))
.
addHandler
(
"/zmq"
,
new
MSMsgQHandler
())
.
addHandler
(
"/zmq"
,
new
MSMsgQHandler
())
.
addTest
(
&
testZMQ
)
.
addTest
(
&
testZMQ
)
.
addTest
(
&
testEvppClient
)
.
build
()
.
build
()
.
run
();
.
run
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment