Merge github.com:grpc/grpc into mmm-mmm-mmm-mmm

pull/1625/head
Craig Tiller 10 years ago
commit f79f63cb1d
  1. 218
      Makefile
  2. 65
      doc/connection-backoff.md
  3. 4
      src/csharp/Grpc.Examples.MathServer/Grpc.Examples.MathServer.csproj
  4. 2
      src/csharp/Grpc.nuspec
  5. 111
      src/csharp/README.md
  6. 8
      src/csharp/build_packages.bat
  7. 63
      src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m
  8. 1
      test/core/end2end/gen_build_json.py
  9. 7
      test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c
  10. 97
      tools/run_tests/tests.json
  11. 71
      vsprojects/Grpc.mak
  12. 1
      vsprojects/nuget_package/buildall.bat

File diff suppressed because one or more lines are too long

@ -0,0 +1,65 @@
GRPC Connection Backoff Protocol
================================
When we do a connection to a backend which fails, it is typically desirable to
not retry immediately (to avoid flooding the network or the server with
requests) and instead do some form of exponential backoff.
We have several parameters:
1. INITIAL_BACKOFF (how long to wait after the first failure before retrying)
2. MULTIPLIER (factor with which to multiply backoff after a failed retry)
3. MAX_BACKOFF (Upper bound on backoff)
4. MIN_CONNECTION_TIMEOUT
## Proposed Backoff Algorithm
Exponentially back off the start time of connection attempts up to a limit of
MAX_BACKOFF.
```
ConnectWithBackoff()
current_backoff = INITIAL_BACKOFF
current_deadline = now() + INITIAL_BACKOFF
while (TryConnect(Max(current_deadline, MIN_CONNECT_TIMEOUT))
!= SUCCESS)
SleepUntil(current_deadline)
current_backoff = Min(current_backoff * MULTIPLIER, MAX_BACKOFF)
current_deadline = now() + current_backoff
```
## Historical Algorithm in Stubby
Exponentially increase up to a limit of MAX_BACKOFF the intervals between
connection attempts. This is what stubby 2 uses, and is equivalent if
TryConnect() fails instantly.
```
LegacyConnectWithBackoff()
current_backoff = INITIAL_BACKOFF
while (TryConnect(MIN_CONNECT_TIMEOUT) != SUCCESS)
SleepFor(current_backoff)
current_backoff = Min(current_backoff * MULTIPLIER, MAX_BACKOFF)
```
The grpc C implementation currently uses this approach with an initial backoff
of 1 second, multiplier of 2, and maximum backoff of 120 seconds. (This will
change)
Stubby, or at least rpc2, uses exactly this algorithm with an initial backoff
of 1 second, multiplier of 1.2, and a maximum backoff of 120 seconds.
## Use Cases to Consider
* Client tries to connect to a server which is down for multiple hours, eg for
maintenance
* Client tries to connect to a server which is overloaded
* User is bringing up both a client and a server at the same time
* In particular, we would like to avoid a large unnecessary delay if the
client connects to a server which is about to come up
* Client/server are misconfigured such that connection attempts always fail
* We want to make sure these don’t put too much load on the server by
default.
* Server is overloaded and wants to transiently make clients back off
* Application has out of band reason to believe a server is back
* We should consider an out of band mechanism for the client to hint that
we should short circuit the backoff.

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -8,7 +8,7 @@
<ProjectGuid>{BF62FE08-373A-43D6-9D73-41CAA38B7011}</ProjectGuid> <ProjectGuid>{BF62FE08-373A-43D6-9D73-41CAA38B7011}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>Grpc.Examples.MathServer</RootNamespace> <RootNamespace>Grpc.Examples.MathServer</RootNamespace>
<AssemblyName>Grpc.Examples.MathServer</AssemblyName> <AssemblyName>MathServer</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">

@ -2,7 +2,7 @@
<package> <package>
<metadata> <metadata>
<id>Grpc</id> <id>Grpc</id>
<title>gRPC</title> <title>gRPC C#</title>
<summary>C# implementation of gRPC - an RPC library and framework</summary> <summary>C# implementation of gRPC - an RPC library and framework</summary>
<description>C# implementation of gRPC - an RPC library and framework. See project site for more info.</description> <description>C# implementation of gRPC - an RPC library and framework. See project site for more info.</description>
<version>0.5.0</version> <version>0.5.0</version>

@ -4,74 +4,117 @@ gRPC C#
A C# implementation of gRPC. A C# implementation of gRPC.
Status Status
----------------- ------
**This gRPC C# implementation is work-in-progress and is not expected to work yet.** Ready for early adopters.
- The implementation is a wrapper around gRPC C core library Usage: Windows
- Code only runs under mono currently, building gRPC C core library under Windows --------------
is in progress.
- It is very possible that some parts of the code will be heavily refactored or
completely rewritten.
- Prerequisites: .NET Framework 4.5+, Visual Studio 2013 with NuGet extension installed (VS2015 should work).
INSTALLATION AND USAGE: WINDOWS - Open Visual Studio and start a new project/solution.
-------------------------------
- Open Grpc.sln using Visual Studio 2013. NuGet dependencies will be restored - Add NuGet package `Grpc` as a dependency (Project options -> Manage NuGet Packages).
upon build. That will also pull all the transitive dependencies (including the native libraries that
gRPC C# is internally using).
- TODO: link to Helloworld example
INSTALLATION AND USAGE: LINUX & MONO Usage: Linux (Mono)
------------------------------------ --------------
- Compile and install the gRPC C# extension library (that will be used via - Prerequisites: Mono framework, MonoDevelop 5.9 with NuGet add-in installed.
P/Invoke from C#).
- Install gRPC C Core using instructions in https://github.com/grpc/homebrew-grpc
- TODO: explain using LD_LIBRARY_PATH or installation to /usr/local
- Open MonoDevelop and start a new project/solution.
- Add NuGet package `Grpc` as a dependency (Project -> Add NuGet packages).
- TODO: link to Helloworld example
Building: Windows
-----------------
You only need to go through these steps if you are planning to develop gRPC C#.
If you are a user of gRPC C#, go to Usage section above.
- Prerequisites for development: NET Framework 4.5+, Visual Studio 2013 (with NuGet and NUnit extensions installed).
- The grpc_csharp_ext native library needs to be built so you can build the Grpc C# solution. You can
either build the native solution in `vsprojects/grpc.sln` from Visual Studio manually, or you can use
a convenience batch script that builds everything for you.
``` ```
make grpc_csharp_ext buildall.bat
sudo make install_grpc_csharp_ext
``` ```
- Prerequisites for development: Mono framework, MonoDevelop (IDE) - Open Grpc.sln using Visual Studio 2013. NuGet dependencies will be restored
upon build (you need to have NuGet add-in installed).
Building: Linux & Mono
----------------------
You only need to go through these steps if you are planning to develop gRPC C#.
If you are a user of gRPC C#, go to Usage section above.
- Prerequisites for development: Mono framework, MonoDevelop 5.9 with NuGet and Nunit add-ins installed.
``` ```
sudo apt-get install mono-devel sudo apt-get install mono-devel
sudo apt-get install monodevelop monodevelop-nunit
sudo apt-get install nunit nunit-console sudo apt-get install nunit nunit-console
``` ```
- NuGet is used to manage project's dependencies. Prior opening Grpc.sln, You can use older versions of MonoDevelop, but then you might need to restore
download dependencies using NuGet restore command: NuGet dependencies manually (by `nuget restore`), because older versions of MonoDevelop
don't support NuGet add-in.
- Compile and install the gRPC C# extension library (that will be used via
P/Invoke from C#).
``` ```
# Import needed certicates into Mono certificate store: make grpc_csharp_ext
mozroots --import --sync sudo make install_grpc_csharp_ext
# Download NuGet.exe http://nuget.codeplex.com/releases/
# Restore the nuget packages with Grpc C# dependencies
mono ~/Downloads/NuGet.exe restore Grpc.sln
``` ```
- Use MonoDevelop to open the solution Grpc.sln (you can also run unit tests - Use MonoDevelop to open the solution Grpc.sln
from there).
- Build the solution & run all the tests from test view.
Tests
-----
- After building the solution with MonoDevelop, you can use gRPC C# is using NUnit as the testing framework.
nunit-console to run the unit tests (currently only running one by
one will make them pass. Under Visual Studio, make sure NUnit test adapter is installed (under "Extensions and Updates").
Then you should be able to run all the tests using Test Explorer.
Under Monodevelop, make sure you installed "NUnit support" in Add-in manager.
Then you should be able to run all the test from the Test View.
After building the solution, you can also run the tests from command line
using nunit-console tool.
``` ```
# from Grpc.Core.Test/bin/Debug directory
nunit-console Grpc.Core.Tests.dll nunit-console Grpc.Core.Tests.dll
``` ```
CONTENTS Contents
-------- --------
- ext: - ext:
The extension library that wraps C API to be more digestible by C#. The extension library that wraps C API to be more digestible by C#.
- Grpc.Auth:
gRPC OAuth2 support.
- Grpc.Core: - Grpc.Core:
The main gRPC C# library. The main gRPC C# library.
- Grpc.Examples: - Grpc.Examples:
API examples for math.proto API examples for math.proto
- Grpc.Examples.MathClient: - Grpc.Examples.MathClient:
An example client that sends some requests to math server. An example client that sends some requests to math server.
- Grpc.Examples.MathServer:
An example client that sends some requests to math server.
- Grpc.IntegrationTesting: - Grpc.IntegrationTesting:
Client for cross-language gRPC implementation testing (interop testing). Cross-language gRPC implementation testing (interop testing).

@ -1,10 +1,16 @@
@rem Builds NuGet packages @rem Builds gRPC NuGet packages
@rem Adjust the location of nuget.exe @rem Adjust the location of nuget.exe
set NUGET=C:\nuget\nuget.exe set NUGET=C:\nuget\nuget.exe
setlocal
cd ..\..\vsprojects\nuget_package
@call buildall.bat || goto :error @call buildall.bat || goto :error
endlocal
@call buildall.bat || goto :error
%NUGET% pack ..\..\vsprojects\nuget_package\grpc.native.csharp_ext.nuspec || goto :error
%NUGET% pack Grpc.Core\Grpc.Core.nuspec || goto :error %NUGET% pack Grpc.Core\Grpc.Core.nuspec || goto :error
%NUGET% pack Grpc.Auth\Grpc.Auth.nuspec || goto :error %NUGET% pack Grpc.Auth\Grpc.Auth.nuspec || goto :error
%NUGET% pack Grpc.nuspec || goto :error %NUGET% pack Grpc.nuspec || goto :error

@ -31,9 +31,12 @@
* *
*/ */
#include <grpc/status.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import <gRPC/ProtoRPC.h>
#import <gRPC/GRXWriter+Immediate.h> #import <gRPC/GRXWriter+Immediate.h>
#import <RemoteTest/Messages.pb.h> #import <RemoteTest/Messages.pb.h>
#import <RemoteTest/Test.pb.h> #import <RemoteTest/Test.pb.h>
@ -69,7 +72,7 @@
} }
- (void)testLargeUnaryRPC { - (void)testLargeUnaryRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"];
RMTSimpleRequest *request = [[[[[[RMTSimpleRequestBuilder alloc] init] RMTSimpleRequest *request = [[[[[[RMTSimpleRequestBuilder alloc] init]
setResponseType:RMTPayloadTypeCompressable] setResponseType:RMTPayloadTypeCompressable]
@ -95,7 +98,7 @@
} }
- (void)testClientStreamingRPC { - (void)testClientStreamingRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"ClientStreaming"];
id request1 = [[[[RMTStreamingInputCallRequestBuilder alloc] init] id request1 = [[[[RMTStreamingInputCallRequestBuilder alloc] init]
setPayloadBuilder:[[[RMTPayloadBuilder alloc] init] setPayloadBuilder:[[[RMTPayloadBuilder alloc] init]
@ -130,4 +133,60 @@
[self waitForExpectationsWithTimeout:4. handler:nil]; [self waitForExpectationsWithTimeout:4. handler:nil];
} }
- (void)testServerStreamingRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"ServerStreaming"];
NSArray *expectedSizes = @[@31415, @9, @2653, @58979];
__block int index = 0;
id request = [[[[[[[RMTStreamingOutputCallRequestBuilder alloc] init]
addResponseParameters:[[[[RMTResponseParametersBuilder alloc] init]
setSize:31415] build]]
addResponseParameters:[[[[RMTResponseParametersBuilder alloc] init]
setSize:9] build]]
addResponseParameters:[[[[RMTResponseParametersBuilder alloc] init]
setSize:2653] build]]
addResponseParameters:[[[[RMTResponseParametersBuilder alloc] init]
setSize:58979] build]]
build];
[_service streamingOutputCallWithRequest:request handler:^(BOOL done, RMTStreamingOutputCallResponse *response, NSError *error){
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
id expectedResponseBuilder = [[RMTStreamingOutputCallResponseBuilder alloc] init];
id expectedPayload = [[[[[RMTPayloadBuilder alloc] init]
setType:RMTPayloadTypeCompressable]
setBody:[NSMutableData dataWithLength:[expectedSizes[index] unsignedIntegerValue]]]
build];
expectedResponseBuilder = [expectedResponseBuilder setPayload:expectedPayload];
id expectedResponse = [expectedResponseBuilder build];
XCTAssertEqualObjects(response, expectedResponse);
[expectation fulfill];
index += 1;
}];
[self waitForExpectationsWithTimeout:4 handler:nil];
}
- (void)testEmptyStreamRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyStream"];
[_service fullDuplexCallWithRequestsWriter:[GRXWriter emptyWriter]
handler:^(bool done, RMTStreamingOutputCallResponse *response, NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
XCTAssert(done, @"Unexpected response: %@", response);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:4 handler:nil];
}
- (void)testCancelAfterBeginRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"CancelAfterBegin"];
// TODO(mlumish): change to writing that blocks instead of writing
ProtoRPC *call = [_service RPCToStreamingInputCallWithRequestsWriter:[GRXWriter emptyWriter]
handler:^(RMTStreamingInputCallResponse *response, NSError *error) {
XCTAssertEqual([error code], GRPC_STATUS_CANCELLED);
[expectation fulfill];
}];
[call start];
[call cancel];
[self waitForExpectationsWithTimeout:1 handler:nil];
}
@end @end

@ -75,6 +75,7 @@ END2END_TESTS = {
'ping_pong_streaming': default_test_options, 'ping_pong_streaming': default_test_options,
'registered_call': default_test_options, 'registered_call': default_test_options,
'request_response_with_binary_metadata_and_payload': default_test_options, 'request_response_with_binary_metadata_and_payload': default_test_options,
'request_response_with_trailing_metadata_and_payload': default_test_options,
'request_response_with_metadata_and_payload': default_test_options, 'request_response_with_metadata_and_payload': default_test_options,
'request_response_with_payload': default_test_options, 'request_response_with_payload': default_test_options,
'request_response_with_payload_and_call_creds': TestOptions(flaky=False, secure=True), 'request_response_with_payload_and_call_creds': TestOptions(flaky=False, secure=True),

@ -164,14 +164,9 @@ static void test_request_response_with_metadata_and_payload(
GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s, GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s,
&call_details, &call_details,
&request_metadata_recv, &request_metadata_recv,
<<<<<<< HEAD
f.server_cq, tag(101)));
cq_expect_completion(v_server, tag(101), 1);
=======
f.server_cq, f.server_cq, f.server_cq, f.server_cq,
tag(101))); tag(101)));
cq_expect_completion(v_server, tag(101), GRPC_OP_OK); cq_expect_completion(v_server, tag(101), 1);
>>>>>>> a468c36601dd5997580129bbd66b5ebed02521f8
cq_verify(v_server); cq_verify(v_server);
op = ops; op = ops;

@ -902,6 +902,15 @@
"posix" "posix"
] ]
}, },
{
"flaky": false,
"language": "c",
"name": "chttp2_fake_security_request_response_with_trailing_metadata_and_payload_test",
"platforms": [
"windows",
"posix"
]
},
{ {
"flaky": false, "flaky": false,
"language": "c", "language": "c",
@ -1145,6 +1154,15 @@
"posix" "posix"
] ]
}, },
{
"flaky": false,
"language": "c",
"name": "chttp2_fullstack_request_response_with_trailing_metadata_and_payload_test",
"platforms": [
"windows",
"posix"
]
},
{ {
"flaky": false, "flaky": false,
"language": "c", "language": "c",
@ -1366,6 +1384,14 @@
"posix" "posix"
] ]
}, },
{
"flaky": false,
"language": "c",
"name": "chttp2_fullstack_uds_posix_request_response_with_trailing_metadata_and_payload_test",
"platforms": [
"posix"
]
},
{ {
"flaky": false, "flaky": false,
"language": "c", "language": "c",
@ -1604,6 +1630,15 @@
"posix" "posix"
] ]
}, },
{
"flaky": false,
"language": "c",
"name": "chttp2_simple_ssl_fullstack_request_response_with_trailing_metadata_and_payload_test",
"platforms": [
"windows",
"posix"
]
},
{ {
"flaky": false, "flaky": false,
"language": "c", "language": "c",
@ -1847,6 +1882,15 @@
"posix" "posix"
] ]
}, },
{
"flaky": false,
"language": "c",
"name": "chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_trailing_metadata_and_payload_test",
"platforms": [
"windows",
"posix"
]
},
{ {
"flaky": false, "flaky": false,
"language": "c", "language": "c",
@ -2090,6 +2134,15 @@
"posix" "posix"
] ]
}, },
{
"flaky": false,
"language": "c",
"name": "chttp2_socket_pair_request_response_with_trailing_metadata_and_payload_test",
"platforms": [
"windows",
"posix"
]
},
{ {
"flaky": false, "flaky": false,
"language": "c", "language": "c",
@ -2333,6 +2386,15 @@
"posix" "posix"
] ]
}, },
{
"flaky": false,
"language": "c",
"name": "chttp2_socket_pair_one_byte_at_a_time_request_response_with_trailing_metadata_and_payload_test",
"platforms": [
"windows",
"posix"
]
},
{ {
"flaky": false, "flaky": false,
"language": "c", "language": "c",
@ -2567,6 +2629,15 @@
"posix" "posix"
] ]
}, },
{
"flaky": false,
"language": "c",
"name": "chttp2_fullstack_request_response_with_trailing_metadata_and_payload_unsecure_test",
"platforms": [
"windows",
"posix"
]
},
{ {
"flaky": false, "flaky": false,
"language": "c", "language": "c",
@ -2780,6 +2851,14 @@
"posix" "posix"
] ]
}, },
{
"flaky": false,
"language": "c",
"name": "chttp2_fullstack_uds_posix_request_response_with_trailing_metadata_and_payload_unsecure_test",
"platforms": [
"posix"
]
},
{ {
"flaky": false, "flaky": false,
"language": "c", "language": "c",
@ -3009,6 +3088,15 @@
"posix" "posix"
] ]
}, },
{
"flaky": false,
"language": "c",
"name": "chttp2_socket_pair_request_response_with_trailing_metadata_and_payload_unsecure_test",
"platforms": [
"windows",
"posix"
]
},
{ {
"flaky": false, "flaky": false,
"language": "c", "language": "c",
@ -3243,6 +3331,15 @@
"posix" "posix"
] ]
}, },
{
"flaky": false,
"language": "c",
"name": "chttp2_socket_pair_one_byte_at_a_time_request_response_with_trailing_metadata_and_payload_unsecure_test",
"platforms": [
"windows",
"posix"
]
},
{ {
"flaky": false, "flaky": false,
"language": "c", "language": "c",

File diff suppressed because one or more lines are too long

@ -1,5 +1,4 @@
@echo off @echo off
setlocal
REM setlocal REM setlocal
REM call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64 REM call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64

Loading…
Cancel
Save