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
54e16ee5
Commit
54e16ee5
authored
10 years ago
by
Vijay Pai
Browse files
Options
Downloads
Patches
Plain Diff
Put in calls to profiling
parent
49673133
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/worker.cc
+56
-40
56 additions, 40 deletions
test/cpp/qps/worker.cc
with
56 additions
and
40 deletions
test/cpp/qps/worker.cc
+
56
−
40
View file @
54e16ee5
...
@@ -109,6 +109,60 @@ class WorkerImpl GRPC_FINAL : public Worker::Service {
...
@@ -109,6 +109,60 @@ class WorkerImpl GRPC_FINAL : public Worker::Service {
return
Status
(
RESOURCE_EXHAUSTED
);
return
Status
(
RESOURCE_EXHAUSTED
);
}
}
grpc_profiler_start
(
"qps_client.prof"
);
Status
ret
=
RunTestBody
(
ctx
,
stream
);
grpc_profiler_stop
();
return
ret
;
}
Status
RunServer
(
ServerContext
*
ctx
,
ServerReaderWriter
<
ServerStatus
,
ServerArgs
>*
stream
)
GRPC_OVERRIDE
{
InstanceGuard
g
(
this
);
if
(
!
g
.
Acquired
())
{
return
Status
(
RESOURCE_EXHAUSTED
);
}
grpc_profiler_start
(
"qps_server.prof"
);
Status
ret
=
RunServerBody
(
ctx
,
stream
);
grpc_profiler_stop
();
return
ret
;
}
private
:
// Protect against multiple clients using this worker at once.
class
InstanceGuard
{
public:
InstanceGuard
(
WorkerImpl
*
impl
)
:
impl_
(
impl
),
acquired_
(
impl
->
TryAcquireInstance
())
{}
~
InstanceGuard
()
{
if
(
acquired_
)
{
impl_
->
ReleaseInstance
();
}
}
bool
Acquired
()
const
{
return
acquired_
;
}
private
:
WorkerImpl
*
const
impl_
;
const
bool
acquired_
;
};
bool
TryAcquireInstance
()
{
std
::
lock_guard
<
std
::
mutex
>
g
(
mu_
);
if
(
acquired_
)
return
false
;
acquired_
=
true
;
return
true
;
}
void
ReleaseInstance
()
{
std
::
lock_guard
<
std
::
mutex
>
g
(
mu_
);
GPR_ASSERT
(
acquired_
);
acquired_
=
false
;
}
Status
RunTestBody
(
ServerContext
*
ctx
,
ServerReaderWriter
<
ClientStatus
,
ClientArgs
>*
stream
)
{
ClientArgs
args
;
ClientArgs
args
;
if
(
!
stream
->
Read
(
&
args
))
{
if
(
!
stream
->
Read
(
&
args
))
{
return
Status
(
INVALID_ARGUMENT
);
return
Status
(
INVALID_ARGUMENT
);
...
@@ -135,14 +189,8 @@ class WorkerImpl GRPC_FINAL : public Worker::Service {
...
@@ -135,14 +189,8 @@ class WorkerImpl GRPC_FINAL : public Worker::Service {
return
Status
::
OK
;
return
Status
::
OK
;
}
}
Status
RunServer
(
ServerContext
*
ctx
,
Status
RunServerBody
(
ServerContext
*
ctx
,
ServerReaderWriter
<
ServerStatus
,
ServerArgs
>*
stream
)
ServerReaderWriter
<
ServerStatus
,
ServerArgs
>*
stream
)
{
GRPC_OVERRIDE
{
InstanceGuard
g
(
this
);
if
(
!
g
.
Acquired
())
{
return
Status
(
RESOURCE_EXHAUSTED
);
}
ServerArgs
args
;
ServerArgs
args
;
if
(
!
stream
->
Read
(
&
args
))
{
if
(
!
stream
->
Read
(
&
args
))
{
return
Status
(
INVALID_ARGUMENT
);
return
Status
(
INVALID_ARGUMENT
);
...
@@ -170,38 +218,6 @@ class WorkerImpl GRPC_FINAL : public Worker::Service {
...
@@ -170,38 +218,6 @@ class WorkerImpl GRPC_FINAL : public Worker::Service {
return
Status
::
OK
;
return
Status
::
OK
;
}
}
private
:
// Protect against multiple clients using this worker at once.
class
InstanceGuard
{
public:
InstanceGuard
(
WorkerImpl
*
impl
)
:
impl_
(
impl
),
acquired_
(
impl
->
TryAcquireInstance
())
{}
~
InstanceGuard
()
{
if
(
acquired_
)
{
impl_
->
ReleaseInstance
();
}
}
bool
Acquired
()
const
{
return
acquired_
;
}
private
:
WorkerImpl
*
const
impl_
;
const
bool
acquired_
;
};
bool
TryAcquireInstance
()
{
std
::
lock_guard
<
std
::
mutex
>
g
(
mu_
);
if
(
acquired_
)
return
false
;
acquired_
=
true
;
return
true
;
}
void
ReleaseInstance
()
{
std
::
lock_guard
<
std
::
mutex
>
g
(
mu_
);
GPR_ASSERT
(
acquired_
);
acquired_
=
false
;
}
std
::
mutex
mu_
;
std
::
mutex
mu_
;
bool
acquired_
;
bool
acquired_
;
};
};
...
...
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