Skip to content

Commit

Permalink
use new proto option in C#
Browse files Browse the repository at this point in the history
  • Loading branch information
jtattermusch committed Nov 19, 2015
1 parent 4d7dbbf commit 18ce9d6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public static IClientRunner CreateStarted(ClientConfig config)
switch (config.RpcType)
{
case RpcType.UNARY:
return new SyncUnaryClientRunner(channel, config.PayloadConfig.SimpleParams.ReqSize);
return new SyncUnaryClientRunner(channel,
config.PayloadConfig.SimpleParams.ReqSize,
config.HistogramParams);

case RpcType.STREAMING:
default:
Expand All @@ -80,6 +82,8 @@ public static IClientRunner CreateStarted(ClientConfig config)
/// </summary>
public class SyncUnaryClientRunner : IClientRunner
{
const double SecondsToNanos = 1e9;

readonly Channel channel;
readonly int payloadSize;
readonly Histogram histogram;
Expand All @@ -89,11 +93,11 @@ public class SyncUnaryClientRunner : IClientRunner
readonly CancellationTokenSource stoppedCts;
readonly WallClockStopwatch wallClockStopwatch = new WallClockStopwatch();

public SyncUnaryClientRunner(Channel channel, int payloadSize)
public SyncUnaryClientRunner(Channel channel, int payloadSize, HistogramParams histogramParams)
{
this.channel = Grpc.Core.Utils.Preconditions.CheckNotNull(channel);
this.payloadSize = payloadSize;
this.histogram = new Histogram(0.01, 60e9); // TODO: needs to be in sync with test/cpp/qps/histogram.h
this.histogram = new Histogram(histogramParams.Resolution, histogramParams.MaxPossible);

this.stoppedCts = new CancellationTokenSource();
this.client = BenchmarkService.NewClient(channel);
Expand Down Expand Up @@ -136,8 +140,8 @@ private void Run()
client.UnaryCall(request);
stopwatch.Stop();

// TODO: 1e9 needs to be in sync with C++ code
histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * 1e9);
// spec requires data point in nanoseconds.
histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/csharp/Grpc.IntegrationTesting/RunnerClientServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void Init()
var serverConfig = new ServerConfig
{
ServerType = ServerType.ASYNC_SERVER,
Host = Host,
PayloadConfig = new PayloadConfig
{
SimpleParams = new SimpleProtoParams
Expand Down Expand Up @@ -90,6 +91,11 @@ public async Task ClientServerRunner()
{
ReqSize = 100
}
},
HistogramParams = new HistogramParams
{
Resolution = 0.01,
MaxPossible = 60e9
}
};

Expand All @@ -105,7 +111,7 @@ public async Task ClientServerRunner()
await runner.StopAsync();

System.Console.WriteLine(stats);
System.Console.WriteLine("avg micros/call " + (long) ((stats.Latencies.Sum / stats.Latencies.Count) * 1000000));
System.Console.WriteLine("avg micros/call " + (long) (stats.Latencies.Sum / stats.Latencies.Count / 1000.0));
}
}
}
2 changes: 1 addition & 1 deletion src/csharp/Grpc.IntegrationTesting/ServerRunners.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static IServerRunner CreateStarted(ServerConfig config)
var server = new Server
{
Services = { BenchmarkService.BindService(new BenchmarkServiceImpl(responseSize)) },
Ports = { new ServerPort("0.0.0.0", config.Port, credentials) }
Ports = { new ServerPort(config.Host, config.Port, credentials) }
};

server.Start();
Expand Down
1 change: 1 addition & 0 deletions test/proto/benchmarks/stats.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ message HistogramData {
}

message ClientStats {
// Latency histogram. Data points are in nanoseconds.
HistogramData latencies = 1;

// See ServerStats for details.
Expand Down

0 comments on commit 18ce9d6

Please sign in to comment.