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
a840de43
Commit
a840de43
authored
9 years ago
by
Vijay Pai
Browse files
Options
Downloads
Plain Diff
Merge pull request #2283 from ctiller/make-it-a-bit-less-locky
Pluck some low hanging concurrency fruit
parents
7510e58b
27df2cf6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/cpp/qps/server_async.cc
+26
-9
26 additions, 9 deletions
test/cpp/qps/server_async.cc
with
26 additions
and
9 deletions
test/cpp/qps/server_async.cc
+
26
−
9
View file @
a840de43
...
@@ -64,7 +64,7 @@ namespace testing {
...
@@ -64,7 +64,7 @@ namespace testing {
class
AsyncQpsServerTest
:
public
Server
{
class
AsyncQpsServerTest
:
public
Server
{
public:
public:
AsyncQpsServerTest
(
const
ServerConfig
&
config
,
int
port
)
:
shutdown_
(
false
)
{
AsyncQpsServerTest
(
const
ServerConfig
&
config
,
int
port
)
{
char
*
server_address
=
NULL
;
char
*
server_address
=
NULL
;
gpr_join_host_port
(
&
server_address
,
"::"
,
port
);
gpr_join_host_port
(
&
server_address
,
"::"
,
port
);
...
@@ -96,6 +96,9 @@ class AsyncQpsServerTest : public Server {
...
@@ -96,6 +96,9 @@ class AsyncQpsServerTest : public Server {
request_streaming
,
ProcessRPC
));
request_streaming
,
ProcessRPC
));
}
}
}
}
for
(
int
i
=
0
;
i
<
config
.
threads
();
i
++
)
{
shutdown_state_
.
emplace_back
(
new
PerThreadShutdownState
());
}
for
(
int
i
=
0
;
i
<
config
.
threads
();
i
++
)
{
for
(
int
i
=
0
;
i
<
config
.
threads
();
i
++
)
{
threads_
.
push_back
(
std
::
thread
([
=
]()
{
threads_
.
push_back
(
std
::
thread
([
=
]()
{
// Wait until work is available or we are shutting down
// Wait until work is available or we are shutting down
...
@@ -105,11 +108,9 @@ class AsyncQpsServerTest : public Server {
...
@@ -105,11 +108,9 @@ class AsyncQpsServerTest : public Server {
ServerRpcContext
*
ctx
=
detag
(
got_tag
);
ServerRpcContext
*
ctx
=
detag
(
got_tag
);
// The tag is a pointer to an RPC context to invoke
// The tag is a pointer to an RPC context to invoke
bool
still_going
=
ctx
->
RunNextState
(
ok
);
bool
still_going
=
ctx
->
RunNextState
(
ok
);
std
::
unique_lock
<
std
::
mutex
>
g
(
shutdown_mutex_
);
if
(
!
shutdown_state_
[
i
]
->
shutdown
())
{
if
(
!
shutdown_
)
{
// this RPC context is done, so refresh it
// this RPC context is done, so refresh it
if
(
!
still_going
)
{
if
(
!
still_going
)
{
g
.
unlock
();
ctx
->
Reset
();
ctx
->
Reset
();
}
}
}
else
{
}
else
{
...
@@ -122,9 +123,8 @@ class AsyncQpsServerTest : public Server {
...
@@ -122,9 +123,8 @@ class AsyncQpsServerTest : public Server {
}
}
~
AsyncQpsServerTest
()
{
~
AsyncQpsServerTest
()
{
server_
->
Shutdown
();
server_
->
Shutdown
();
{
for
(
auto
ss
=
shutdown_state_
.
begin
();
ss
!=
shutdown_state_
.
end
();
++
ss
)
{
std
::
lock_guard
<
std
::
mutex
>
g
(
shutdown_mutex_
);
(
*
ss
)
->
set_shutdown
();
shutdown_
=
true
;
}
}
for
(
auto
thr
=
threads_
.
begin
();
thr
!=
threads_
.
end
();
thr
++
)
{
for
(
auto
thr
=
threads_
.
begin
();
thr
!=
threads_
.
end
();
thr
++
)
{
thr
->
join
();
thr
->
join
();
...
@@ -316,8 +316,25 @@ class AsyncQpsServerTest : public Server {
...
@@ -316,8 +316,25 @@ class AsyncQpsServerTest : public Server {
TestService
::
AsyncService
async_service_
;
TestService
::
AsyncService
async_service_
;
std
::
forward_list
<
ServerRpcContext
*>
contexts_
;
std
::
forward_list
<
ServerRpcContext
*>
contexts_
;
std
::
mutex
shutdown_mutex_
;
class
PerThreadShutdownState
{
bool
shutdown_
;
public:
PerThreadShutdownState
()
:
shutdown_
(
false
)
{}
bool
shutdown
()
const
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
return
shutdown_
;
}
void
set_shutdown
()
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
shutdown_
=
true
;
}
private
:
mutable
std
::
mutex
mutex_
;
bool
shutdown_
;
};
std
::
vector
<
std
::
unique_ptr
<
PerThreadShutdownState
>>
shutdown_state_
;
};
};
std
::
unique_ptr
<
Server
>
CreateAsyncServer
(
const
ServerConfig
&
config
,
std
::
unique_ptr
<
Server
>
CreateAsyncServer
(
const
ServerConfig
&
config
,
...
...
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