Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
31c0c794
Commit
31c0c794
authored
9 years ago
by
Vijay Pai
Browse files
Options
Downloads
Patches
Plain Diff
clang-format
parent
de332dfc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/cpp/qps/server_async.cc
+65
-41
65 additions, 41 deletions
test/cpp/qps/server_async.cc
with
65 additions
and
41 deletions
test/cpp/qps/server_async.cc
+
65
−
41
View file @
31c0c794
...
@@ -38,16 +38,16 @@
...
@@ -38,16 +38,16 @@
#include
<thread>
#include
<thread>
#include
<gflags/gflags.h>
#include
<gflags/gflags.h>
#include
<grpc/grpc.h>
#include
<grpc/support/alloc.h>
#include
<grpc/support/host_port.h>
#include
<grpc/support/log.h>
#include
<grpc++/generic/async_generic_service.h>
#include
<grpc++/generic/async_generic_service.h>
#include
<grpc++/s
upport/config
.h>
#include
<grpc++/s
ecurity/server_credentials
.h>
#include
<grpc++/server.h>
#include
<grpc++/server.h>
#include
<grpc++/server_builder.h>
#include
<grpc++/server_builder.h>
#include
<grpc++/server_context.h>
#include
<grpc++/server_context.h>
#include
<grpc++/security/server_credentials.h>
#include
<grpc++/support/config.h>
#include
<grpc/grpc.h>
#include
<grpc/support/alloc.h>
#include
<grpc/support/host_port.h>
#include
<grpc/support/log.h>
#include
<gtest/gtest.h>
#include
<gtest/gtest.h>
#include
"test/cpp/qps/server.h"
#include
"test/cpp/qps/server.h"
...
@@ -56,15 +56,25 @@
...
@@ -56,15 +56,25 @@
namespace
grpc
{
namespace
grpc
{
namespace
testing
{
namespace
testing
{
template
<
class
RequestType
,
class
ResponseType
,
class
ServiceType
,
class
ServerContextType
>
template
<
class
RequestType
,
class
ResponseType
,
class
ServiceType
,
class
ServerContextType
>
class
AsyncQpsServerTest
:
public
Server
{
class
AsyncQpsServerTest
:
public
Server
{
public:
public:
AsyncQpsServerTest
(
const
ServerConfig
&
config
,
AsyncQpsServerTest
(
std
::
function
<
void
(
ServerBuilder
*
,
ServiceType
*
)
>
register_service
,
const
ServerConfig
&
config
,
std
::
function
<
void
(
ServiceType
*
,
ServerContextType
*
,
RequestType
*
,
ServerAsyncResponseWriter
<
ResponseType
>*
,
CompletionQueue
*
,
ServerCompletionQueue
*
,
void
*
)
>
request_unary_function
,
std
::
function
<
void
(
ServerBuilder
*
,
ServiceType
*
)
>
register_service
,
std
::
function
<
void
(
ServiceType
*
,
ServerContextType
*
,
ServerAsyncReaderWriter
<
ResponseType
,
RequestType
>*
,
CompletionQueue
*
,
ServerCompletionQueue
*
,
void
*
)
>
request_streaming_function
,
std
::
function
<
void
(
ServiceType
*
,
ServerContextType
*
,
RequestType
*
,
std
::
function
<
grpc
::
Status
(
const
ServerConfig
&
,
const
RequestType
*
,
ResponseType
*
)
>
process_rpc
)
ServerAsyncResponseWriter
<
ResponseType
>
*
,
:
Server
(
config
)
{
CompletionQueue
*
,
ServerCompletionQueue
*
,
void
*
)
>
request_unary_function
,
std
::
function
<
void
(
ServiceType
*
,
ServerContextType
*
,
ServerAsyncReaderWriter
<
ResponseType
,
RequestType
>
*
,
CompletionQueue
*
,
ServerCompletionQueue
*
,
void
*
)
>
request_streaming_function
,
std
::
function
<
grpc
::
Status
(
const
ServerConfig
&
,
const
RequestType
*
,
ResponseType
*
)
>
process_rpc
)
:
Server
(
config
)
{
char
*
server_address
=
NULL
;
char
*
server_address
=
NULL
;
gpr_join_host_port
(
&
server_address
,
config
.
host
().
c_str
(),
port
());
gpr_join_host_port
(
&
server_address
,
config
.
host
().
c_str
(),
port
());
...
@@ -85,22 +95,23 @@ class AsyncQpsServerTest : public Server {
...
@@ -85,22 +95,23 @@ class AsyncQpsServerTest : public Server {
using
namespace
std
::
placeholders
;
using
namespace
std
::
placeholders
;
auto
process_rpc_bound
=
std
::
bind
(
process_rpc
,
config
,
_1
,
_2
);
auto
process_rpc_bound
=
std
::
bind
(
process_rpc
,
config
,
_1
,
_2
);
for
(
int
i
=
0
;
i
<
10000
/
config
.
async_server_threads
();
i
++
)
{
for
(
int
i
=
0
;
i
<
10000
/
config
.
async_server_threads
();
i
++
)
{
for
(
int
j
=
0
;
j
<
config
.
async_server_threads
();
j
++
)
{
for
(
int
j
=
0
;
j
<
config
.
async_server_threads
();
j
++
)
{
if
(
request_unary_function
)
{
if
(
request_unary_function
)
{
auto
request_unary
=
std
::
bind
(
auto
request_unary
=
request_unary_function
,
&
async_service_
,
std
::
bind
(
request_unary_function
,
&
async_service_
,
_1
,
_2
,
_3
,
_1
,
_2
,
_3
,
srv_cqs_
[
j
].
get
(),
srv_cqs_
[
j
].
get
(),
_4
);
srv_cqs_
[
j
].
get
(),
srv_cqs_
[
j
].
get
(),
_4
);
contexts_
.
push_front
(
new
ServerRpcContextUnaryImpl
(
request_unary
,
process_rpc_bound
));
contexts_
.
push_front
(
}
new
ServerRpcContextUnaryImpl
(
request_unary
,
process_rpc_bound
));
if
(
request_streaming_function
)
{
}
auto
request_streaming
=
std
::
bind
(
if
(
request_streaming_function
)
{
request_streaming_function
,
auto
request_streaming
=
&
async_service_
,
_1
,
_2
,
srv_cqs_
[
j
].
get
(),
srv_cqs_
[
j
].
get
(),
_3
);
std
::
bind
(
request_streaming_function
,
&
async_service_
,
_1
,
_2
,
contexts_
.
push_front
(
new
ServerRpcContextStreamingImpl
(
srv_cqs_
[
j
].
get
(),
srv_cqs_
[
j
].
get
(),
_3
);
request_streaming
,
process_rpc_bound
));
contexts_
.
push_front
(
new
ServerRpcContextStreamingImpl
(
}
request_streaming
,
process_rpc_bound
));
}
}
}
}
}
...
@@ -173,7 +184,8 @@ class AsyncQpsServerTest : public Server {
...
@@ -173,7 +184,8 @@ class AsyncQpsServerTest : public Server {
ServerRpcContextUnaryImpl
(
ServerRpcContextUnaryImpl
(
std
::
function
<
void
(
ServerContextType
*
,
RequestType
*
,
std
::
function
<
void
(
ServerContextType
*
,
RequestType
*
,
grpc
::
ServerAsyncResponseWriter
<
ResponseType
>
*
,
grpc
::
ServerAsyncResponseWriter
<
ResponseType
>
*
,
void
*
)
>
request_method
,
void
*
)
>
request_method
,
std
::
function
<
grpc
::
Status
(
const
RequestType
*
,
ResponseType
*
)
>
std
::
function
<
grpc
::
Status
(
const
RequestType
*
,
ResponseType
*
)
>
invoke_method
)
invoke_method
)
:
srv_ctx_
(
new
ServerContextType
),
:
srv_ctx_
(
new
ServerContextType
),
...
@@ -231,9 +243,10 @@ class AsyncQpsServerTest : public Server {
...
@@ -231,9 +243,10 @@ class AsyncQpsServerTest : public Server {
class
ServerRpcContextStreamingImpl
GRPC_FINAL
:
public
ServerRpcContext
{
class
ServerRpcContextStreamingImpl
GRPC_FINAL
:
public
ServerRpcContext
{
public:
public:
ServerRpcContextStreamingImpl
(
ServerRpcContextStreamingImpl
(
std
::
function
<
void
(
ServerContextType
*
,
grpc
::
ServerAsyncReaderWriter
<
std
::
function
<
void
(
ResponseType
,
RequestType
>
*
,
ServerContextType
*
,
void
*
)
>
request_method
,
grpc
::
ServerAsyncReaderWriter
<
ResponseType
,
RequestType
>
*
,
void
*
)
>
request_method
,
std
::
function
<
grpc
::
Status
(
const
RequestType
*
,
ResponseType
*
)
>
std
::
function
<
grpc
::
Status
(
const
RequestType
*
,
ResponseType
*
)
>
invoke_method
)
invoke_method
)
:
srv_ctx_
(
new
ServerContextType
),
:
srv_ctx_
(
new
ServerContextType
),
...
@@ -337,38 +350,49 @@ class AsyncQpsServerTest : public Server {
...
@@ -337,38 +350,49 @@ class AsyncQpsServerTest : public Server {
};
};
static
void
RegisterBenchmarkService
(
ServerBuilder
*
builder
,
static
void
RegisterBenchmarkService
(
ServerBuilder
*
builder
,
BenchmarkService
::
AsyncService
*
service
)
{
BenchmarkService
::
AsyncService
*
service
)
{
builder
->
RegisterAsyncService
(
service
);
builder
->
RegisterAsyncService
(
service
);
}
}
static
void
RegisterGenericService
(
ServerBuilder
*
builder
,
static
void
RegisterGenericService
(
ServerBuilder
*
builder
,
grpc
::
AsyncGenericService
*
service
)
{
grpc
::
AsyncGenericService
*
service
)
{
builder
->
RegisterAsyncGenericService
(
service
);
builder
->
RegisterAsyncGenericService
(
service
);
}
}
template
<
class
RequestType
,
class
ResponseType
>
template
<
class
RequestType
,
class
ResponseType
>
Status
ProcessRPC
(
const
ServerConfig
&
config
,
const
RequestType
*
request
,
Status
ProcessRPC
(
const
ServerConfig
&
config
,
const
RequestType
*
request
,
ResponseType
*
response
)
{
ResponseType
*
response
)
{
if
(
request
->
response_size
()
>
0
)
{
if
(
request
->
response_size
()
>
0
)
{
if
(
!
Server
::
SetPayload
(
request
->
response_type
(),
request
->
response_size
(),
if
(
!
Server
::
SetPayload
(
request
->
response_type
(),
request
->
response_size
(),
response
->
mutable_payload
()))
{
response
->
mutable_payload
()))
{
return
Status
(
grpc
::
StatusCode
::
INTERNAL
,
"Error creating payload."
);
return
Status
(
grpc
::
StatusCode
::
INTERNAL
,
"Error creating payload."
);
}
}
}
}
return
Status
::
OK
;
return
Status
::
OK
;
}
}
template
<
>
template
<
>
Status
ProcessRPC
(
const
ServerConfig
&
config
,
const
ByteBuffer
*
request
,
Status
ProcessRPC
(
const
ServerConfig
&
config
,
const
ByteBuffer
*
request
,
ByteBuffer
*
response
)
{
ByteBuffer
*
response
)
{
return
Status
::
OK
;
return
Status
::
OK
;
}
}
std
::
unique_ptr
<
Server
>
CreateAsyncServer
(
const
ServerConfig
&
config
)
{
std
::
unique_ptr
<
Server
>
CreateAsyncServer
(
const
ServerConfig
&
config
)
{
return
std
::
unique_ptr
<
Server
>
(
new
AsyncQpsServerTest
<
SimpleRequest
,
SimpleResponse
,
BenchmarkService
::
AsyncService
,
grpc
::
ServerContext
>
(
config
,
RegisterBenchmarkService
,
&
BenchmarkService
::
AsyncService
::
RequestUnaryCall
,
&
BenchmarkService
::
AsyncService
::
RequestStreamingCall
,
ProcessRPC
<
SimpleRequest
,
SimpleResponse
>
));
return
std
::
unique_ptr
<
Server
>
(
new
AsyncQpsServerTest
<
SimpleRequest
,
SimpleResponse
,
BenchmarkService
::
AsyncService
,
grpc
::
ServerContext
>
(
config
,
RegisterBenchmarkService
,
&
BenchmarkService
::
AsyncService
::
RequestUnaryCall
,
&
BenchmarkService
::
AsyncService
::
RequestStreamingCall
,
ProcessRPC
<
SimpleRequest
,
SimpleResponse
>
));
}
}
std
::
unique_ptr
<
Server
>
CreateAsyncGenericServer
(
const
ServerConfig
&
config
)
{
std
::
unique_ptr
<
Server
>
CreateAsyncGenericServer
(
const
ServerConfig
&
config
)
{
return
std
::
unique_ptr
<
Server
>
(
new
AsyncQpsServerTest
<
ByteBuffer
,
ByteBuffer
,
grpc
::
AsyncGenericService
,
grpc
::
GenericServerContext
>
(
config
,
RegisterGenericService
,
nullptr
,
&
grpc
::
AsyncGenericService
::
RequestCall
,
ProcessRPC
<
ByteBuffer
,
ByteBuffer
>
));
return
std
::
unique_ptr
<
Server
>
(
new
AsyncQpsServerTest
<
ByteBuffer
,
ByteBuffer
,
grpc
::
AsyncGenericService
,
grpc
::
GenericServerContext
>
(
config
,
RegisterGenericService
,
nullptr
,
&
grpc
::
AsyncGenericService
::
RequestCall
,
ProcessRPC
<
ByteBuffer
,
ByteBuffer
>
));
}
}
}
// namespace testing
}
// namespace testing
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment