diff options
author | Yang Gao <yangg@google.com> | 2017-05-22 10:41:17 -0700 |
---|---|---|
committer | Yang Gao <yangg@google.com> | 2017-05-22 10:41:17 -0700 |
commit | 725d82274385217b5f0345e834f7fae7e76fbd84 (patch) | |
tree | 310cf74a491e11efd86e16ebfd879f9a83e5e648 /src/csharp | |
parent | 21035da1c9c20b5204ad4e9f2339490b3a3b6c0f (diff) | |
parent | 495cf83c86e04567f8b907a51cc0f86f5068fab6 (diff) |
merge with head
Diffstat (limited to 'src/csharp')
-rw-r--r-- | src/csharp/Grpc.Core/Internal/CallError.cs | 5 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/CallSafeHandle.cs | 4 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/NativeMethods.cs | 6 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs | 2 | ||||
-rw-r--r-- | src/csharp/Grpc.IntegrationTesting/ClientRunners.cs | 28 | ||||
-rw-r--r-- | src/csharp/Grpc.IntegrationTesting/Histogram.cs | 57 | ||||
-rw-r--r-- | src/csharp/Grpc.IntegrationTesting/HistogramTest.cs | 26 | ||||
-rwxr-xr-x | src/csharp/build_packages_dotnetcli.bat | 10 | ||||
-rwxr-xr-x | src/csharp/build_packages_dotnetcli.sh | 10 |
9 files changed, 102 insertions, 46 deletions
diff --git a/src/csharp/Grpc.Core/Internal/CallError.cs b/src/csharp/Grpc.Core/Internal/CallError.cs index 541575f5e6..a46f9b3859 100644 --- a/src/csharp/Grpc.Core/Internal/CallError.cs +++ b/src/csharp/Grpc.Core/Internal/CallError.cs @@ -72,7 +72,10 @@ namespace Grpc.Core.Internal /// </summary> public static void CheckOk(this CallError callError) { - GrpcPreconditions.CheckState(callError == CallError.OK, "Call error: " + callError); + if (callError != CallError.OK) + { + throw new InvalidOperationException("Call error: " + callError); + } } } } diff --git a/src/csharp/Grpc.Core/Internal/CallSafeHandle.cs b/src/csharp/Grpc.Core/Internal/CallSafeHandle.cs index 3c368fbc6c..8ed0c0b92f 100644 --- a/src/csharp/Grpc.Core/Internal/CallSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/CallSafeHandle.cs @@ -117,7 +117,7 @@ namespace Grpc.Core.Internal { var ctx = BatchContextSafeHandle.Create(); completionQueue.CompletionRegistry.RegisterBatchCompletion(ctx, (success, context) => callback(success)); - Native.grpcsharp_call_send_message(this, ctx, payload, new UIntPtr((ulong)payload.Length), writeFlags, sendEmptyInitialMetadata).CheckOk(); + Native.grpcsharp_call_send_message(this, ctx, payload, new UIntPtr((ulong)payload.Length), writeFlags, sendEmptyInitialMetadata ? 1 : 0).CheckOk(); } } @@ -140,7 +140,7 @@ namespace Grpc.Core.Internal var optionalPayloadLength = optionalPayload != null ? new UIntPtr((ulong)optionalPayload.Length) : UIntPtr.Zero; completionQueue.CompletionRegistry.RegisterBatchCompletion(ctx, (success, context) => callback(success)); var statusDetailBytes = MarshalUtils.GetBytesUTF8(status.Detail); - Native.grpcsharp_call_send_status_from_server(this, ctx, status.StatusCode, statusDetailBytes, new UIntPtr((ulong)statusDetailBytes.Length), metadataArray, sendEmptyInitialMetadata, + Native.grpcsharp_call_send_status_from_server(this, ctx, status.StatusCode, statusDetailBytes, new UIntPtr((ulong)statusDetailBytes.Length), metadataArray, sendEmptyInitialMetadata ? 1 : 0, optionalPayload, optionalPayloadLength, writeFlags).CheckOk(); } } diff --git a/src/csharp/Grpc.Core/Internal/NativeMethods.cs b/src/csharp/Grpc.Core/Internal/NativeMethods.cs index a98861af61..696987d2a8 100644 --- a/src/csharp/Grpc.Core/Internal/NativeMethods.cs +++ b/src/csharp/Grpc.Core/Internal/NativeMethods.cs @@ -346,11 +346,11 @@ namespace Grpc.Core.Internal public delegate CallError grpcsharp_call_start_duplex_streaming_delegate(CallSafeHandle call, BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray, CallFlags metadataFlags); public delegate CallError grpcsharp_call_send_message_delegate(CallSafeHandle call, - BatchContextSafeHandle ctx, byte[] sendBuffer, UIntPtr sendBufferLen, WriteFlags writeFlags, bool sendEmptyInitialMetadata); + BatchContextSafeHandle ctx, byte[] sendBuffer, UIntPtr sendBufferLen, WriteFlags writeFlags, int sendEmptyInitialMetadata); public delegate CallError grpcsharp_call_send_close_from_client_delegate(CallSafeHandle call, BatchContextSafeHandle ctx); public delegate CallError grpcsharp_call_send_status_from_server_delegate(CallSafeHandle call, - BatchContextSafeHandle ctx, StatusCode statusCode, byte[] statusMessage, UIntPtr statusMessageLen, MetadataArraySafeHandle metadataArray, bool sendEmptyInitialMetadata, + BatchContextSafeHandle ctx, StatusCode statusCode, byte[] statusMessage, UIntPtr statusMessageLen, MetadataArraySafeHandle metadataArray, int sendEmptyInitialMetadata, byte[] optionalSendBuffer, UIntPtr optionalSendBufferLen, WriteFlags writeFlags); public delegate CallError grpcsharp_call_recv_message_delegate(CallSafeHandle call, BatchContextSafeHandle ctx); @@ -406,7 +406,7 @@ namespace Grpc.Core.Internal public delegate CallCredentialsSafeHandle grpcsharp_metadata_credentials_create_from_plugin_delegate(NativeMetadataInterceptor interceptor); public delegate void grpcsharp_metadata_credentials_notify_from_plugin_delegate(IntPtr callbackPtr, IntPtr userData, MetadataArraySafeHandle metadataArray, StatusCode statusCode, string errorDetails); - public delegate ServerCredentialsSafeHandle grpcsharp_ssl_server_credentials_create_delegate(string pemRootCerts, string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray, UIntPtr numKeyCertPairs, bool forceClientAuth); + public delegate ServerCredentialsSafeHandle grpcsharp_ssl_server_credentials_create_delegate(string pemRootCerts, string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray, UIntPtr numKeyCertPairs, int forceClientAuth); public delegate void grpcsharp_server_credentials_release_delegate(IntPtr credentials); public delegate ServerSafeHandle grpcsharp_server_create_delegate(ChannelArgsSafeHandle args); diff --git a/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs index 24f686fddc..c14fa7c827 100644 --- a/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs @@ -53,7 +53,7 @@ namespace Grpc.Core.Internal return Native.grpcsharp_ssl_server_credentials_create(pemRootCerts, keyCertPairCertChainArray, keyCertPairPrivateKeyArray, new UIntPtr((ulong)keyCertPairCertChainArray.Length), - forceClientAuth); + forceClientAuth ? 1 : 0); } protected override bool ReleaseHandle() diff --git a/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs b/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs index c9f7c42b71..8a44f8d68f 100644 --- a/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs +++ b/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs @@ -140,7 +140,8 @@ namespace Grpc.IntegrationTesting readonly ClientType clientType; readonly RpcType rpcType; readonly PayloadConfig payloadConfig; - readonly Histogram histogram; + readonly Lazy<byte[]> cachedByteBufferRequest; + readonly ThreadLocal<Histogram> threadLocalHistogram; readonly List<Task> runnerTasks; readonly CancellationTokenSource stoppedCts = new CancellationTokenSource(); @@ -155,7 +156,8 @@ namespace Grpc.IntegrationTesting this.clientType = clientType; this.rpcType = rpcType; this.payloadConfig = payloadConfig; - this.histogram = new Histogram(histogramParams.Resolution, histogramParams.MaxPossible); + this.cachedByteBufferRequest = new Lazy<byte[]>(() => new byte[payloadConfig.BytebufParams.ReqSize]); + this.threadLocalHistogram = new ThreadLocal<Histogram>(() => new Histogram(histogramParams.Resolution, histogramParams.MaxPossible), true); this.runnerTasks = new List<Task>(); foreach (var channel in this.channels) @@ -171,7 +173,12 @@ namespace Grpc.IntegrationTesting public ClientStats GetStats(bool reset) { - var histogramData = histogram.GetSnapshot(reset); + var histogramData = new HistogramData(); + foreach (var hist in threadLocalHistogram.Values) + { + hist.GetSnapshot(histogramData, reset); + } + var secondsElapsed = wallClockStopwatch.GetElapsedSnapshot(reset).TotalSeconds; if (reset) @@ -232,7 +239,7 @@ namespace Grpc.IntegrationTesting stopwatch.Stop(); // spec requires data point in nanoseconds. - histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos); + threadLocalHistogram.Value.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos); timer.WaitForNext(); } @@ -251,7 +258,7 @@ namespace Grpc.IntegrationTesting stopwatch.Stop(); // spec requires data point in nanoseconds. - histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos); + threadLocalHistogram.Value.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos); await timer.WaitForNextAsync(); } @@ -273,7 +280,7 @@ namespace Grpc.IntegrationTesting stopwatch.Stop(); // spec requires data point in nanoseconds. - histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos); + threadLocalHistogram.Value.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos); await timer.WaitForNextAsync(); } @@ -286,7 +293,7 @@ namespace Grpc.IntegrationTesting private async Task RunGenericStreamingAsync(Channel channel, IInterarrivalTimer timer) { - var request = CreateByteBufferRequest(); + var request = cachedByteBufferRequest.Value; var stopwatch = new Stopwatch(); var callDetails = new CallInvocationDetails<byte[], byte[]>(channel, GenericService.StreamingCallMethod, new CallOptions()); @@ -301,7 +308,7 @@ namespace Grpc.IntegrationTesting stopwatch.Stop(); // spec requires data point in nanoseconds. - histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos); + threadLocalHistogram.Value.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos); await timer.WaitForNextAsync(); } @@ -351,11 +358,6 @@ namespace Grpc.IntegrationTesting }; } - private byte[] CreateByteBufferRequest() - { - return new byte[payloadConfig.BytebufParams.ReqSize]; - } - private static Payload CreateZerosPayload(int size) { return new Payload { Body = ByteString.CopyFrom(new byte[size]) }; diff --git a/src/csharp/Grpc.IntegrationTesting/Histogram.cs b/src/csharp/Grpc.IntegrationTesting/Histogram.cs index 28d1f078a9..9d33c497e6 100644 --- a/src/csharp/Grpc.IntegrationTesting/Histogram.cs +++ b/src/csharp/Grpc.IntegrationTesting/Histogram.cs @@ -84,15 +84,27 @@ namespace Grpc.IntegrationTesting } } - /// <summary> - /// Gets snapshot of stats and reset + /// Gets snapshot of stats and optionally resets the histogram. /// </summary> public HistogramData GetSnapshot(bool reset = false) { lock (myLock) { - return GetSnapshotUnsafe(reset); + var histogramData = new HistogramData(); + GetSnapshotUnsafe(histogramData, reset); + return histogramData; + } + } + + /// <summary> + /// Merges snapshot of stats into <c>mergeTo</c> and optionally resets the histogram. + /// </summary> + public void GetSnapshot(HistogramData mergeTo, bool reset) + { + lock (myLock) + { + GetSnapshotUnsafe(mergeTo, reset); } } @@ -117,24 +129,39 @@ namespace Grpc.IntegrationTesting this.buckets[FindBucket(value)]++; } - private HistogramData GetSnapshotUnsafe(bool reset) + private void GetSnapshotUnsafe(HistogramData mergeTo, bool reset) { - var data = new HistogramData + GrpcPreconditions.CheckArgument(mergeTo.Bucket.Count == 0 || mergeTo.Bucket.Count == buckets.Length); + if (mergeTo.Count == 0) { - Count = count, - Sum = sum, - SumOfSquares = sumOfSquares, - MinSeen = min, - MaxSeen = max, - Bucket = { buckets } - }; + mergeTo.MinSeen = min; + mergeTo.MaxSeen = max; + } + else + { + mergeTo.MinSeen = Math.Min(mergeTo.MinSeen, min); + mergeTo.MaxSeen = Math.Max(mergeTo.MaxSeen, max); + } + mergeTo.Count += count; + mergeTo.Sum += sum; + mergeTo.SumOfSquares += sumOfSquares; - if (reset) + if (mergeTo.Bucket.Count == 0) { - ResetUnsafe(); + mergeTo.Bucket.AddRange(buckets); + } + else + { + for (int i = 0; i < buckets.Length; i++) + { + mergeTo.Bucket[i] += buckets[i]; + } } - return data; + if (reset) + { + ResetUnsafe(); + } } private void ResetUnsafe() diff --git a/src/csharp/Grpc.IntegrationTesting/HistogramTest.cs b/src/csharp/Grpc.IntegrationTesting/HistogramTest.cs index fa160cbd15..e8a2ed0c5b 100644 --- a/src/csharp/Grpc.IntegrationTesting/HistogramTest.cs +++ b/src/csharp/Grpc.IntegrationTesting/HistogramTest.cs @@ -73,7 +73,7 @@ namespace Grpc.IntegrationTesting { var hist = new Histogram(0.01, 60e9); hist.AddObservation(-0.5); // should be in the first bucket - hist.AddObservation(1e12); // should be in the last bucket + hist.AddObservation(1e12); // should be in the last bucket var data = hist.GetSnapshot(); Assert.AreEqual(1, data.Bucket[0]); @@ -81,6 +81,30 @@ namespace Grpc.IntegrationTesting } [Test] + public void MergeSnapshots() + { + var data = new HistogramData(); + + var hist1 = new Histogram(0.01, 60e9); + hist1.AddObservation(-0.5); // should be in the first bucket + hist1.AddObservation(1e12); // should be in the last bucket + hist1.GetSnapshot(data, false); + + var hist2 = new Histogram(0.01, 60e9); + hist2.AddObservation(10000); + hist2.AddObservation(11000); + hist2.GetSnapshot(data, false); + + Assert.AreEqual(4, data.Count); + Assert.AreEqual(-0.5, data.MinSeen); + Assert.AreEqual(1e12, data.MaxSeen); + Assert.AreEqual(1, data.Bucket[0]); + Assert.AreEqual(1, data.Bucket[925]); + Assert.AreEqual(1, data.Bucket[935]); + Assert.AreEqual(1, data.Bucket[data.Bucket.Count - 1]); + } + + [Test] public void Reset() { var hist = new Histogram(0.01, 60e9); diff --git a/src/csharp/build_packages_dotnetcli.bat b/src/csharp/build_packages_dotnetcli.bat index aa8a8d3b17..d823942be5 100755 --- a/src/csharp/build_packages_dotnetcli.bat +++ b/src/csharp/build_packages_dotnetcli.bat @@ -51,11 +51,11 @@ powershell -Command "cp -r ..\..\platform=*\artifacts\protoc_* protoc_plugins" @rem To be able to build, we also need to put grpc_csharp_ext to its normal location xcopy /Y /I nativelibs\csharp_ext_windows_x64\grpc_csharp_ext.dll ..\..\cmake\build\x64\Release\ -%DOTNET% pack --configuration Release Grpc.Core --output ..\..\..\artifacts || goto :error -%DOTNET% pack --configuration Release Grpc.Core.Testing --output ..\..\..\artifacts || goto :error -%DOTNET% pack --configuration Release Grpc.Auth --output ..\..\..\artifacts || goto :error -%DOTNET% pack --configuration Release Grpc.HealthCheck --output ..\..\..\artifacts || goto :error -%DOTNET% pack --configuration Release Grpc.Reflection --output ..\..\..\artifacts || goto :error +%DOTNET% pack --configuration Release --include-symbols --include-source Grpc.Core --output ..\..\..\artifacts || goto :error +%DOTNET% pack --configuration Release --include-symbols --include-source Grpc.Core.Testing --output ..\..\..\artifacts || goto :error +%DOTNET% pack --configuration Release --include-symbols --include-source Grpc.Auth --output ..\..\..\artifacts || goto :error +%DOTNET% pack --configuration Release --include-symbols --include-source Grpc.HealthCheck --output ..\..\..\artifacts || goto :error +%DOTNET% pack --configuration Release --include-symbols --include-source Grpc.Reflection --output ..\..\..\artifacts || goto :error %NUGET% pack Grpc.nuspec -Version %VERSION% -OutputDirectory ..\..\artifacts || goto :error %NUGET% pack Grpc.Tools.nuspec -Version %VERSION% -OutputDirectory ..\..\artifacts diff --git a/src/csharp/build_packages_dotnetcli.sh b/src/csharp/build_packages_dotnetcli.sh index d33923845c..f79c97fbbc 100755 --- a/src/csharp/build_packages_dotnetcli.sh +++ b/src/csharp/build_packages_dotnetcli.sh @@ -48,11 +48,11 @@ dotnet restore Grpc.sln mkdir -p ../../libs/opt cp nativelibs/csharp_ext_linux_x64/libgrpc_csharp_ext.so ../../libs/opt -dotnet pack --configuration Release Grpc.Core --output ../../../artifacts -dotnet pack --configuration Release Grpc.Core.Testing --output ../../../artifacts -dotnet pack --configuration Release Grpc.Auth --output ../../../artifacts -dotnet pack --configuration Release Grpc.HealthCheck --output ../../../artifacts -dotnet pack --configuration Release Grpc.Reflection --output ../../../artifacts +dotnet pack --configuration Release --include-symbols --include-source Grpc.Core --output ../../../artifacts +dotnet pack --configuration Release --include-symbols --include-source Grpc.Core.Testing --output ../../../artifacts +dotnet pack --configuration Release --include-symbols --include-source Grpc.Auth --output ../../../artifacts +dotnet pack --configuration Release --include-symbols --include-source Grpc.HealthCheck --output ../../../artifacts +dotnet pack --configuration Release --include-symbols --include-source Grpc.Reflection --output ../../../artifacts nuget pack Grpc.nuspec -Version "1.4.0-dev" -OutputDirectory ../../artifacts nuget pack Grpc.Tools.nuspec -Version "1.4.0-dev" -OutputDirectory ../../artifacts |