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
e26e2e5a
Commit
e26e2e5a
authored
9 years ago
by
Jan Tattermusch
Browse files
Options
Downloads
Patches
Plain Diff
support streaming and async client
parent
c848502f
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
src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
+92
-22
92 additions, 22 deletions
src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
with
92 additions
and
22 deletions
src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
+
92
−
22
View file @
e26e2e5a
...
...
@@ -64,8 +64,6 @@ namespace Grpc.IntegrationTesting
string
target
=
config
.
ServerTargets
.
Single
();
GrpcPreconditions
.
CheckArgument
(
config
.
LoadParams
.
LoadCase
==
LoadParams
.
LoadOneofCase
.
ClosedLoop
,
"Only closed loop scenario supported for C#"
);
GrpcPreconditions
.
CheckArgument
(
config
.
ClientType
==
ClientType
.
SYNC_CLIENT
,
"Only sync client support for C#"
);
GrpcPreconditions
.
CheckArgument
(
config
.
ClientChannels
==
1
,
"ClientConfig.ClientChannels needs to be 1"
);
if
(
config
.
OutstandingRpcsPerChannel
!=
0
)
...
...
@@ -96,28 +94,24 @@ namespace Grpc.IntegrationTesting
}
var
channel
=
new
Channel
(
target
,
credentials
,
channelOptions
);
switch
(
config
.
RpcType
)
{
case
RpcType
.
UNARY
:
return
new
SyncUnaryClientRunner
(
channel
,
config
.
PayloadConfig
.
SimpleParams
,
config
.
HistogramParams
);
case
RpcType
.
STREAMING
:
default
:
throw
new
ArgumentException
(
"Unsupported RpcType."
);
}
return
new
SimpleClientRunner
(
channel
,
config
.
ClientType
,
config
.
RpcType
,
config
.
PayloadConfig
.
SimpleParams
,
config
.
HistogramParams
);
}
}
/// <summary>
/// Client that starts synchronous unary calls in a closed loop.
/// </summary>
public
class
S
yncUnary
ClientRunner
:
IClientRunner
public
class
S
imple
ClientRunner
:
IClientRunner
{
const
double
SecondsToNanos
=
1e9
;
readonly
Channel
channel
;
readonly
ClientType
clientType
;
readonly
RpcType
rpcType
;
readonly
SimpleProtoParams
payloadParams
;
readonly
Histogram
histogram
;
...
...
@@ -126,14 +120,19 @@ namespace Grpc.IntegrationTesting
readonly
CancellationTokenSource
stoppedCts
;
readonly
WallClockStopwatch
wallClockStopwatch
=
new
WallClockStopwatch
();
public
S
yncUnary
ClientRunner
(
Channel
channel
,
SimpleProtoParams
payloadParams
,
HistogramParams
histogramParams
)
public
S
imple
ClientRunner
(
Channel
channel
,
ClientType
clientType
,
RpcType
rpcType
,
SimpleProtoParams
payloadParams
,
HistogramParams
histogramParams
)
{
this
.
channel
=
GrpcPreconditions
.
CheckNotNull
(
channel
);
this
.
clientType
=
clientType
;
this
.
rpcType
=
rpcType
;
this
.
payloadParams
=
payloadParams
;
this
.
histogram
=
new
Histogram
(
histogramParams
.
Resolution
,
histogramParams
.
MaxPossible
);
this
.
stoppedCts
=
new
CancellationTokenSource
();
this
.
client
=
BenchmarkService
.
NewClient
(
channel
);
this
.
runnerTask
=
Task
.
Factory
.
StartNew
(
Run
,
TaskCreationOptions
.
LongRunning
);
var
threadBody
=
GetThreadBody
();
this
.
runnerTask
=
Task
.
Factory
.
StartNew
(
threadBody
,
TaskCreationOptions
.
LongRunning
);
}
public
ClientStats
GetStats
(
bool
reset
)
...
...
@@ -158,13 +157,9 @@ namespace Grpc.IntegrationTesting
await
channel
.
ShutdownAsync
();
}
private
void
Run
()
private
void
Run
ClosedLoopUnary
()
{
var
request
=
new
SimpleRequest
{
Payload
=
CreateZerosPayload
(
payloadParams
.
ReqSize
),
ResponseSize
=
payloadParams
.
RespSize
};
var
request
=
CreateSimpleRequest
();
var
stopwatch
=
new
Stopwatch
();
while
(!
stoppedCts
.
Token
.
IsCancellationRequested
)
...
...
@@ -178,6 +173,81 @@ namespace Grpc.IntegrationTesting
}
}
private
async
Task
RunClosedLoopUnaryAsync
()
{
var
request
=
CreateSimpleRequest
();
var
stopwatch
=
new
Stopwatch
();
while
(!
stoppedCts
.
Token
.
IsCancellationRequested
)
{
stopwatch
.
Restart
();
await
client
.
UnaryCallAsync
(
request
);
stopwatch
.
Stop
();
// spec requires data point in nanoseconds.
histogram
.
AddObservation
(
stopwatch
.
Elapsed
.
TotalSeconds
*
SecondsToNanos
);
}
}
private
async
Task
RunClosedLoopStreamingAsync
()
{
var
request
=
CreateSimpleRequest
();
var
stopwatch
=
new
Stopwatch
();
using
(
var
call
=
client
.
StreamingCall
())
{
while
(!
stoppedCts
.
Token
.
IsCancellationRequested
)
{
stopwatch
.
Restart
();
await
call
.
RequestStream
.
WriteAsync
(
request
);
await
call
.
ResponseStream
.
MoveNext
();
stopwatch
.
Stop
();
// spec requires data point in nanoseconds.
histogram
.
AddObservation
(
stopwatch
.
Elapsed
.
TotalSeconds
*
SecondsToNanos
);
}
// finish the streaming call
await
call
.
RequestStream
.
CompleteAsync
();
Assert
.
IsFalse
(
await
call
.
ResponseStream
.
MoveNext
());
}
}
private
Action
GetThreadBody
()
{
if
(
clientType
==
ClientType
.
SYNC_CLIENT
)
{
GrpcPreconditions
.
CheckArgument
(
rpcType
==
RpcType
.
UNARY
,
"Sync client can only be used for Unary calls in C#"
);
return
RunClosedLoopUnary
;
}
else
if
(
clientType
==
ClientType
.
ASYNC_CLIENT
)
{
switch
(
rpcType
)
{
case
RpcType
.
UNARY
:
return
()
=>
{
RunClosedLoopUnaryAsync
().
Wait
();
};
case
RpcType
.
STREAMING
:
return
()
=>
{
RunClosedLoopStreamingAsync
().
Wait
();
};
}
}
throw
new
ArgumentException
(
"Unsupported configuration."
);
}
private
SimpleRequest
CreateSimpleRequest
()
{
return
new
SimpleRequest
{
Payload
=
CreateZerosPayload
(
payloadParams
.
ReqSize
),
ResponseSize
=
payloadParams
.
RespSize
};
}
private
static
Payload
CreateZerosPayload
(
int
size
)
{
return
new
Payload
{
Body
=
ByteString
.
CopyFrom
(
new
byte
[
size
])
};
...
...
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