aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.IntegrationTesting
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2017-12-06 22:29:12 -0800
committerGravatar Muxi Yan <mxyan@google.com>2017-12-06 22:29:12 -0800
commit6043006af142fd2e10372ce5ef74f56b3064ce43 (patch)
tree35b85d640b0e78e227a9f09f48ce06725b6aa7c1 /src/csharp/Grpc.IntegrationTesting
parent67454d71e833a7704d61e673ad32e71dd31c868a (diff)
parent84d78acfa41a1263ba75b46dd4e857e02ea2cb96 (diff)
Merge remote-tracking branch 'upstream/master' into fix-stream-compression-config-interface
Diffstat (limited to 'src/csharp/Grpc.IntegrationTesting')
-rw-r--r--src/csharp/Grpc.IntegrationTesting/ClientRunners.cs28
-rw-r--r--src/csharp/Grpc.IntegrationTesting/ControlExtensions.cs43
-rw-r--r--src/csharp/Grpc.IntegrationTesting/ServerRunners.cs16
-rw-r--r--src/csharp/Grpc.IntegrationTesting/StressTestClient.cs6
-rw-r--r--src/csharp/Grpc.IntegrationTesting/TimeStats.cs90
-rw-r--r--src/csharp/Grpc.IntegrationTesting/WallClockStopwatch.cs63
6 files changed, 158 insertions, 88 deletions
diff --git a/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs b/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
index 60696b62d9..9d41d34414 100644
--- a/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
+++ b/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
@@ -72,7 +72,7 @@ namespace Grpc.IntegrationTesting
Logger.Warning("ClientConfig.CoreList is not supported for C#. Ignoring the value");
}
- var channels = CreateChannels(config.ClientChannels, config.ServerTargets, config.SecurityParams);
+ var channels = CreateChannels(config.ClientChannels, config.ServerTargets, config.SecurityParams, config.ChannelArgs);
return new ClientRunnerImpl(channels,
config.ClientType,
@@ -84,19 +84,20 @@ namespace Grpc.IntegrationTesting
() => GetNextProfiler());
}
- private static List<Channel> CreateChannels(int clientChannels, IEnumerable<string> serverTargets, SecurityParams securityParams)
+ private static List<Channel> CreateChannels(int clientChannels, IEnumerable<string> serverTargets, SecurityParams securityParams, IEnumerable<ChannelArg> channelArguments)
{
GrpcPreconditions.CheckArgument(clientChannels > 0, "clientChannels needs to be at least 1.");
GrpcPreconditions.CheckArgument(serverTargets.Count() > 0, "at least one serverTarget needs to be specified.");
var credentials = securityParams != null ? TestCredentials.CreateSslCredentials() : ChannelCredentials.Insecure;
- List<ChannelOption> channelOptions = null;
+ var channelOptions = new List<ChannelOption>();
if (securityParams != null && securityParams.ServerHostOverride != "")
{
- channelOptions = new List<ChannelOption>
- {
- new ChannelOption(ChannelOptions.SslTargetNameOverride, securityParams.ServerHostOverride)
- };
+ channelOptions.Add(new ChannelOption(ChannelOptions.SslTargetNameOverride, securityParams.ServerHostOverride));
+ }
+ foreach (var channelArgument in channelArguments)
+ {
+ channelOptions.Add(channelArgument.ToChannelOption());
}
var result = new List<Channel>();
@@ -130,7 +131,7 @@ namespace Grpc.IntegrationTesting
readonly List<Task> runnerTasks;
readonly CancellationTokenSource stoppedCts = new CancellationTokenSource();
- readonly WallClockStopwatch wallClockStopwatch = new WallClockStopwatch();
+ readonly TimeStats timeStats = new TimeStats();
readonly AtomicCounter statsResetCount = new AtomicCounter();
public ClientRunnerImpl(List<Channel> channels, ClientType clientType, RpcType rpcType, int outstandingRpcsPerChannel, LoadParams loadParams, PayloadConfig payloadConfig, HistogramParams histogramParams, Func<BasicProfiler> profilerFactory)
@@ -164,7 +165,7 @@ namespace Grpc.IntegrationTesting
hist.GetSnapshot(histogramData, reset);
}
- var secondsElapsed = wallClockStopwatch.GetElapsedSnapshot(reset).TotalSeconds;
+ var timeSnapshot = timeStats.GetSnapshot(reset);
if (reset)
{
@@ -172,15 +173,14 @@ namespace Grpc.IntegrationTesting
}
GrpcEnvironment.Logger.Info("[ClientRunnerImpl.GetStats] GC collection counts: gen0 {0}, gen1 {1}, gen2 {2}, (histogram reset count:{3}, seconds since reset: {4})",
- GC.CollectionCount(0), GC.CollectionCount(1), GC.CollectionCount(2), statsResetCount.Count, secondsElapsed);
+ GC.CollectionCount(0), GC.CollectionCount(1), GC.CollectionCount(2), statsResetCount.Count, timeSnapshot.WallClockTime.TotalSeconds);
- // TODO: populate user time and system time
return new ClientStats
{
Latencies = histogramData,
- TimeElapsed = secondsElapsed,
- TimeUser = 0,
- TimeSystem = 0
+ TimeElapsed = timeSnapshot.WallClockTime.TotalSeconds,
+ TimeUser = timeSnapshot.UserProcessorTime.TotalSeconds,
+ TimeSystem = timeSnapshot.PrivilegedProcessorTime.TotalSeconds
};
}
diff --git a/src/csharp/Grpc.IntegrationTesting/ControlExtensions.cs b/src/csharp/Grpc.IntegrationTesting/ControlExtensions.cs
new file mode 100644
index 0000000000..67f5faed20
--- /dev/null
+++ b/src/csharp/Grpc.IntegrationTesting/ControlExtensions.cs
@@ -0,0 +1,43 @@
+#region Copyright notice and license
+
+// Copyright 2016 gRPC authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#endregion
+
+using System;
+using Grpc.Core;
+using Grpc.Testing;
+
+namespace Grpc.IntegrationTesting
+{
+ /// <summary>
+ /// Helpers for Control.cs
+ /// </summary>
+ public static class ControlExtensions
+ {
+ public static ChannelOption ToChannelOption(this ChannelArg channelArgument)
+ {
+ switch (channelArgument.ValueCase)
+ {
+ case ChannelArg.ValueOneofCase.StrValue:
+ return new ChannelOption(channelArgument.Name, channelArgument.StrValue);
+ case ChannelArg.ValueOneofCase.IntValue:
+ return new ChannelOption(channelArgument.Name, channelArgument.IntValue);
+ default:
+ throw new ArgumentException("Unsupported channel argument value.");
+ }
+ }
+ }
+}
diff --git a/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs b/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs
index 45bff3aaf8..ea29bd74e5 100644
--- a/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs
+++ b/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs
@@ -78,7 +78,8 @@ namespace Grpc.IntegrationTesting
throw new ArgumentException("Unsupported ServerType");
}
- var server = new Server
+ var channelOptions = new List<ChannelOption>(config.ChannelArgs.Select((arg) => arg.ToChannelOption()));
+ var server = new Server(channelOptions)
{
Services = { service },
Ports = { new ServerPort("[::]", config.Port, credentials) }
@@ -116,7 +117,7 @@ namespace Grpc.IntegrationTesting
public class ServerRunnerImpl : IServerRunner
{
readonly Server server;
- readonly WallClockStopwatch wallClockStopwatch = new WallClockStopwatch();
+ readonly TimeStats timeStats = new TimeStats();
public ServerRunnerImpl(Server server)
{
@@ -137,17 +138,16 @@ namespace Grpc.IntegrationTesting
/// <returns>The stats.</returns>
public ServerStats GetStats(bool reset)
{
- var secondsElapsed = wallClockStopwatch.GetElapsedSnapshot(reset).TotalSeconds;
+ var timeSnapshot = timeStats.GetSnapshot(reset);
GrpcEnvironment.Logger.Info("[ServerRunner.GetStats] GC collection counts: gen0 {0}, gen1 {1}, gen2 {2}, (seconds since last reset {3})",
- GC.CollectionCount(0), GC.CollectionCount(1), GC.CollectionCount(2), secondsElapsed);
+ GC.CollectionCount(0), GC.CollectionCount(1), GC.CollectionCount(2), timeSnapshot.WallClockTime.TotalSeconds);
- // TODO: populate user time and system time
return new ServerStats
{
- TimeElapsed = secondsElapsed,
- TimeUser = 0,
- TimeSystem = 0
+ TimeElapsed = timeSnapshot.WallClockTime.TotalSeconds,
+ TimeUser = timeSnapshot.UserProcessorTime.TotalSeconds,
+ TimeSystem = timeSnapshot.PrivilegedProcessorTime.TotalSeconds
};
}
diff --git a/src/csharp/Grpc.IntegrationTesting/StressTestClient.cs b/src/csharp/Grpc.IntegrationTesting/StressTestClient.cs
index 11956e4ac8..0c62380768 100644
--- a/src/csharp/Grpc.IntegrationTesting/StressTestClient.cs
+++ b/src/csharp/Grpc.IntegrationTesting/StressTestClient.cs
@@ -243,7 +243,7 @@ namespace Grpc.IntegrationTesting
const string GaugeName = "csharp_overall_qps";
readonly Histogram histogram;
- readonly WallClockStopwatch wallClockStopwatch = new WallClockStopwatch();
+ readonly TimeStats timeStats = new TimeStats();
public MetricsServiceImpl(Histogram histogram)
{
@@ -280,9 +280,9 @@ namespace Grpc.IntegrationTesting
long GetQpsAndReset()
{
var snapshot = histogram.GetSnapshot(true);
- var elapsedSnapshot = wallClockStopwatch.GetElapsedSnapshot(true);
+ var timeSnapshot = timeStats.GetSnapshot(true);
- return (long) (snapshot.Count / elapsedSnapshot.TotalSeconds);
+ return (long) (snapshot.Count / timeSnapshot.WallClockTime.TotalSeconds);
}
}
}
diff --git a/src/csharp/Grpc.IntegrationTesting/TimeStats.cs b/src/csharp/Grpc.IntegrationTesting/TimeStats.cs
new file mode 100644
index 0000000000..6aba04c194
--- /dev/null
+++ b/src/csharp/Grpc.IntegrationTesting/TimeStats.cs
@@ -0,0 +1,90 @@
+#region Copyright notice and license
+
+// Copyright 2015 gRPC authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text.RegularExpressions;
+using System.Threading;
+using System.Threading.Tasks;
+using Google.Protobuf;
+using Grpc.Core;
+using Grpc.Core.Utils;
+using NUnit.Framework;
+using Grpc.Testing;
+
+namespace Grpc.IntegrationTesting
+{
+ /// <summary>
+ /// Snapshottable time statistics.
+ /// </summary>
+ public class TimeStats
+ {
+ readonly object myLock = new object();
+ DateTime lastWallClock;
+ TimeSpan lastUserTime;
+ TimeSpan lastPrivilegedTime;
+
+ public TimeStats()
+ {
+ lastWallClock = DateTime.UtcNow;
+ lastUserTime = Process.GetCurrentProcess().UserProcessorTime;
+ lastPrivilegedTime = Process.GetCurrentProcess().PrivilegedProcessorTime;
+ }
+
+ public Snapshot GetSnapshot(bool reset)
+ {
+ lock (myLock)
+ {
+ var wallClock = DateTime.UtcNow;
+ var userTime = Process.GetCurrentProcess().UserProcessorTime;
+ var privilegedTime = Process.GetCurrentProcess().PrivilegedProcessorTime;
+ var snapshot = new Snapshot(wallClock - lastWallClock, userTime - lastUserTime, privilegedTime - lastPrivilegedTime);
+
+ if (reset)
+ {
+ lastWallClock = wallClock;
+ lastUserTime = userTime;
+ lastPrivilegedTime = privilegedTime;
+ }
+ return snapshot;
+ }
+ }
+
+ public class Snapshot
+ {
+ public TimeSpan WallClockTime { get; }
+ public TimeSpan UserProcessorTime { get; }
+ public TimeSpan PrivilegedProcessorTime { get; }
+
+ public Snapshot(TimeSpan wallClockTime, TimeSpan userProcessorTime, TimeSpan privilegedProcessorTime)
+ {
+ this.WallClockTime = wallClockTime;
+ this.UserProcessorTime = userProcessorTime;
+ this.PrivilegedProcessorTime = privilegedProcessorTime;
+ }
+
+ public override string ToString()
+ {
+ return string.Format("[TimeStats.Snapshot: wallClock {0}, userProcessor {1}, privilegedProcessor {2}]", WallClockTime, UserProcessorTime, PrivilegedProcessorTime);
+ }
+ }
+ }
+}
diff --git a/src/csharp/Grpc.IntegrationTesting/WallClockStopwatch.cs b/src/csharp/Grpc.IntegrationTesting/WallClockStopwatch.cs
deleted file mode 100644
index 38b58f296c..0000000000
--- a/src/csharp/Grpc.IntegrationTesting/WallClockStopwatch.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-#region Copyright notice and license
-
-// Copyright 2015 gRPC authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using System.Text.RegularExpressions;
-using System.Threading;
-using System.Threading.Tasks;
-using Google.Protobuf;
-using Grpc.Core;
-using Grpc.Core.Utils;
-using NUnit.Framework;
-using Grpc.Testing;
-
-namespace Grpc.IntegrationTesting
-{
- /// <summary>
- /// Snapshottable wall clock stopwatch.
- /// </summary>
- public class WallClockStopwatch
- {
- long startTicks;
-
- public WallClockStopwatch()
- {
- this.startTicks = DateTime.UtcNow.Ticks;
- }
-
- public TimeSpan GetElapsedSnapshot(bool reset)
- {
- var utcNow = DateTime.UtcNow;
-
- long oldStartTicks;
- if (reset)
- {
- oldStartTicks = Interlocked.Exchange(ref this.startTicks, utcNow.Ticks);
- }
- else
- {
- oldStartTicks = this.startTicks;
- }
- return utcNow - new DateTime(oldStartTicks, DateTimeKind.Utc);
- }
- }
-}