diff options
author | murgatroid99 <michael.lumish@gmail.com> | 2015-01-21 10:40:39 -0800 |
---|---|---|
committer | murgatroid99 <michael.lumish@gmail.com> | 2015-01-21 10:40:39 -0800 |
commit | 9e14ead3f64a34faef39ba7ff5bfb1d198f3f4bd (patch) | |
tree | a71f5d3f348b7beb58951357767004d6f2a91dfa | |
parent | e1613dcd318f2b0240cea199d434dfeae05c5043 (diff) | |
parent | 6a3880b0f138a7e357f648826c69bc1b0d692cfa (diff) |
Merge branch 'master' of github.com:google/grpc
-rw-r--r-- | .clang-format | 54 | ||||
-rw-r--r-- | INSTALL | 149 | ||||
-rw-r--r-- | src/core/iomgr/pollset_kick_posix.c | 30 | ||||
-rwxr-xr-x | src/ruby/bin/interop/interop_client.rb | 16 | ||||
-rwxr-xr-x | src/ruby/bin/interop/interop_server.rb | 2 | ||||
-rw-r--r-- | test/core/iomgr/poll_kick_test.c | 30 |
6 files changed, 164 insertions, 117 deletions
diff --git a/.clang-format b/.clang-format index 651e1296ba..4b3f13fa55 100644 --- a/.clang-format +++ b/.clang-format @@ -1,57 +1,5 @@ --- Language: Cpp -# BasedOnStyle: Google -AccessModifierOffset: -1 -ConstructorInitializerIndentWidth: 4 -AlignEscapedNewlinesLeft: true -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: true -AllowShortFunctionsOnASingleLine: All -AlwaysBreakTemplateDeclarations: true -AlwaysBreakBeforeMultilineStrings: true -BreakBeforeBinaryOperators: false -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BinPackParameters: true -ColumnLimit: 80 -ConstructorInitializerAllOnOneLineOrOnePerLine: true -DerivePointerAlignment: true -ExperimentalAutoDetectBinPacking: false -IndentCaseLabels: true -IndentWrappedFunctionNames: false -IndentFunctionDeclarationAfterType: false -MaxEmptyLinesToKeep: 1 -KeepEmptyLinesAtTheStartOfBlocks: false -NamespaceIndentation: None -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: false -PenaltyBreakBeforeFirstCallParameter: 1 -PenaltyBreakComment: 300 -PenaltyBreakString: 1000 -PenaltyBreakFirstLessLess: 120 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 200 -PointerAlignment: Left -SpacesBeforeTrailingComments: 2 -Cpp11BracedListStyle: true -Standard: Auto -IndentWidth: 2 -TabWidth: 8 -UseTab: Never -BreakBeforeBraces: Attach -SpacesInParentheses: false -SpacesInAngles: false -SpaceInEmptyParentheses: false -SpacesInCStyleCastParentheses: false -SpacesInContainerLiterals: true -SpaceBeforeAssignmentOperators: true -ContinuationIndentWidth: 4 -CommentPragmas: '^ IWYU pragma:' -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -SpaceBeforeParens: ControlStatements -DisableFormat: false +BasedOnStyle: Google ... @@ -1,83 +1,142 @@ -Dependencies -============ +These instructions only cover building grpc C and C++ libraries under +typical unix systems. If you need more information, please try grpc's +wiki pages: -grpc has few external dependencies. If needed, they are present in the -third_party directory, if you have cloned the github repository recursively. -If you didn't clone recursively, you can still get them later by running the -following command: + https://github.com/google/grpc/wiki -$ git submodule update --init -Note that the Makefile makes it much easier for you to compile from sources -if you were to clone recursively our git repository. +************************* +* If you are in a hurry * +************************* +A typical unix installation won't require any more steps than running: -grpc core currently depends on zlib and OpenSSL 1.0.2beta3. + $ make + # make install -grpc++'s tests depends on protobuf 3.0.0, gtests and gflags. +You don't need anything else than GNU Make and gcc. Under a Debian or +Ubuntu system, this should boil down to the following package: -OpenSSL -------- + # apt-get install build-essential -Secure HTTP2 requires to have the TLS extension ALPN (see rfc 7301 and -http://http2.github.io/http2-spec/ section 3.3). Our HTTP2 implementation -relies on OpenSSL's implementation. OpenSSL 1.0.2beta3 is the first version -of OpenSSL that has ALPN support, and this explains our dependency on it. -Note that the Makefile supports compiling only the unsecure elements of grpc, -and if you do not have OpenSSL and do not want it, you can still proceed -with installing only the elements you require. However, it is recommended -to encrypt your network traffic, therefore we urge you to not use the unsecure -version of grpc if possible. +******************************* +* More detailled instructions * +******************************* +Setting up dependencies +======================= -Compiling -========= +Dependencies to compile the libraries +------------------------------------- -If you have all the dependencies in the third_party subfolder, you should -simply be able to go ahead and run "make" to compile grpc. The other targets -that you might find interesting are "buildtests" and "test". +grpc libraries have few external dependencies. If you need to compile and +install them, they are present in the third_party directory if you have +cloned the github repository recursively. If you didn't clone recursively, +you can still get them later by running the following command: -If you didn't clone from git, and thus are unable to get the required -dependencies, you can manually download and unpack the necessary packages, -and let the Makefile build them itself. + $ git submodule update --init -You may also install the dependencies yourself, from the sources, or from -your distribution's package manager. +Note that the Makefile makes it much easier for you to compile from sources +if you were to clone recursively our git repository: it will automatically +compile zlib and OpenSSL, which are core requirements for grpc. Note this +creates grpc libraries that will have zlib and OpenSSL built-in inside of them, +which significantly increases the libraries' size. + +In order to decrease that size, you can manually install zlib and OpenSSL on +your system, so that the Makefile can use them instead. + +Under a Debian or Ubuntu system, one can acquire the development package +for zlib this way: -The only development package needed for grpc is zlib. -The development packages needed for grpc++'s tests are gtests, and gflags. + # apt-get install zlib1g-dev To the best of our knowledge, no distribution has an OpenSSL package that supports ALPN yet, so you would still have to depend on installing from source -for that particular dependency. +for that particular dependency if you want to reduce the libraries' size. The recommended version of OpenSSL that provides ALPN support is available at this URL: https://www.openssl.org/source/openssl-1.0.2-beta3.tar.gz -If you want to let the Makefile build them automatically for you, please -extract them in the third_party folder. You will need to rename the extracted -folder the following way: - openssl-1.0.2-beta3 --> openssl +Dependencies to compile and run the tests +----------------------------------------- + +Compiling and running grpc plain-C tests dont't require any more dependency. + + +Compiling and running grpc C++ tests depend on protobuf 3.0.0, gtest and +gflags. Although gflags and protobuf are provided in third_party, you will +need to manually install these dependencies on your system to run these tests. + +Under a Debian or Ubuntu system, you can install the gtests and gflags packages +using apt-get: + + # apt-get install libgflags-dev libgtest-dev + +However, protobuf 3.0.0 isn't in a debian package yet: you'll need to compile +and install it from the sources in the third_party. Note that if you already +have the protobuf and protoc packages installed on your system, they will most +likely interfere, and you'll need to uninstall them first. + +Compiling and installing protobuf 3.0.0 requires a few more dependencies in +itself, notably the autoconf suite, curl, and unzip. If you have apt-get, you +can install these dependencies this way: + + # apt-get install unzip curl autotools-dev + +Then, you can build and install protobuf 3.0.0: + + $ cd third_party/protobuf + $ ./configure + $ make + # make install + # ldconfig + + +A word on OpenSSL +----------------- + +Secure HTTP2 requires to have the TLS extension ALPN (see rfc 7301 and +http://http2.github.io/http2-spec/ section 3.3). Our HTTP2 implementation +relies on OpenSSL's implementation. OpenSSL 1.0.2beta3 is the first version +of OpenSSL that has ALPN support, and this explains our dependency on it. + +Note that the Makefile supports compiling only the unsecure elements of grpc, +and if you do not have OpenSSL and do not want it, you can still proceed +with installing only the elements you require. However, it is recommended +to encrypt your network traffic, therefore we urge you to not use the unsecure +version of grpc if possible. + + +Compiling +========= + +If you have all the dependencies mentioned above, you should simply be able +to go ahead and run "make" to compile grpc's C and C++ libraries: + + $ make Testing ======= -At the moment, C++ tests aren't fully available yet. If you want to run tests -on the C core of grpc, you can do the following: +To build and run the tests, you can run the command: + + $ make test + +If you want to be able to run them in parallel, and get better output, you can +also use the python tool we have written: -$ make buildtests_c -$ make test_c + $ ./tools/run_tests/run_tests.py Installing ========== -Once everything is compiled, you should be able to install grpc and grpc++ +Once everything is compiled, you should be able to install grpc C and C++ libraries and headers: -$ sudo make install + # make install diff --git a/src/core/iomgr/pollset_kick_posix.c b/src/core/iomgr/pollset_kick_posix.c index d16e49e459..9f85b6137a 100644 --- a/src/core/iomgr/pollset_kick_posix.c +++ b/src/core/iomgr/pollset_kick_posix.c @@ -43,6 +43,9 @@ /* This implementation is based on a freelist of pipes. */ +#define GRPC_MAX_CACHED_PIPES 50 +#define GRPC_PIPE_LOW_WATERMARK 25 + typedef struct grpc_kick_pipe_info { int pipe_read_fd; int pipe_write_fd; @@ -50,14 +53,16 @@ typedef struct grpc_kick_pipe_info { } grpc_kick_pipe_info; static grpc_kick_pipe_info *pipe_freelist = NULL; +static int pipe_freelist_count = 0; static gpr_mu pipe_freelist_mu; -static grpc_kick_pipe_info *allocate_pipe() { +static grpc_kick_pipe_info *allocate_pipe(void) { grpc_kick_pipe_info *info; gpr_mu_lock(&pipe_freelist_mu); if (pipe_freelist != NULL) { info = pipe_freelist; pipe_freelist = pipe_freelist->next; + --pipe_freelist_count; } else { int pipefd[2]; /* TODO(klempner): Make this nonfatal */ @@ -73,11 +78,26 @@ static grpc_kick_pipe_info *allocate_pipe() { return info; } +static void destroy_pipe(void) { + /* assumes pipe_freelist_mu is held */ + grpc_kick_pipe_info *current = pipe_freelist; + pipe_freelist = pipe_freelist->next; + pipe_freelist_count--; + close(current->pipe_read_fd); + close(current->pipe_write_fd); + gpr_free(current); +} + static void free_pipe(grpc_kick_pipe_info *pipe_info) { - /* TODO(klempner): Start closing pipes if the free list gets too large */ gpr_mu_lock(&pipe_freelist_mu); pipe_info->next = pipe_freelist; pipe_freelist = pipe_info; + pipe_freelist_count++; + if (pipe_freelist_count > GRPC_MAX_CACHED_PIPES) { + while (pipe_freelist_count > GRPC_PIPE_LOW_WATERMARK) { + destroy_pipe(); + } + } gpr_mu_unlock(&pipe_freelist_mu); } @@ -88,11 +108,7 @@ void grpc_pollset_kick_global_init() { void grpc_pollset_kick_global_destroy() { while (pipe_freelist != NULL) { - grpc_kick_pipe_info *current = pipe_freelist; - pipe_freelist = pipe_freelist->next; - close(current->pipe_read_fd); - close(current->pipe_write_fd); - gpr_free(current); + destroy_pipe(); } gpr_mu_destroy(&pipe_freelist_mu); } diff --git a/src/ruby/bin/interop/interop_client.rb b/src/ruby/bin/interop/interop_client.rb index 0ce10d9e30..0ea7f376be 100755 --- a/src/ruby/bin/interop/interop_client.rb +++ b/src/ruby/bin/interop/interop_client.rb @@ -107,11 +107,11 @@ class PingPongPlayer @msg_sizes.each do |m| req_size, resp_size = m req = req_cls.new(payload: Payload.new(body: nulls(req_size)), - response_type: COMPRESSABLE, + response_type: :COMPRESSABLE, response_parameters: [p_cls.new(size: resp_size)]) yield req resp = @queue.pop - assert_equal(PayloadType.lookup(COMPRESSABLE), resp.payload.type, + assert_equal(:COMPRESSABLE, resp.payload.type, 'payload type is wrong') assert_equal(resp_size, resp.payload.body.length, 'payload body #{i} has the wrong length') @@ -149,11 +149,13 @@ class NamedTests # FAILED def large_unary req_size, wanted_response_size = 271_828, 314_159 - payload = Payload.new(type: COMPRESSABLE, body: nulls(req_size)) - req = SimpleRequest.new(response_type: COMPRESSABLE, + payload = Payload.new(type: :COMPRESSABLE, body: nulls(req_size)) + req = SimpleRequest.new(response_type: :COMPRESSABLE, response_size: wanted_response_size, payload: payload) resp = @stub.unary_call(req) + assert_equal(:COMPRESSABLE, resp.payload.type, + 'large_unary: payload had the wrong type') assert_equal(wanted_response_size, resp.payload.body.length, 'large_unary: payload had the wrong length') assert_equal(nulls(wanted_response_size), resp.payload.body, @@ -185,12 +187,12 @@ class NamedTests def server_streaming msg_sizes = [31_415, 9, 2653, 58_979] response_spec = msg_sizes.map { |s| ResponseParameters.new(size: s) } - req = StreamingOutputCallRequest.new(response_type: COMPRESSABLE, + req = StreamingOutputCallRequest.new(response_type: :COMPRESSABLE, response_parameters: response_spec) resps = @stub.streaming_output_call(req) resps.each_with_index do |r, i| assert i < msg_sizes.length, 'too many responses' - assert_equal(PayloadType.lookup(COMPRESSABLE), r.payload.type, + assert_equal(:COMPRESSABLE, r.payload.type, 'payload type is wrong') assert_equal(msg_sizes[i], r.payload.body.length, 'payload body #{i} has the wrong length') @@ -235,7 +237,7 @@ def parse_options end end.parse! - %w(server_host, server_port, test_case).each do |arg| + %w(server_host server_port test_case).each do |arg| if options[arg].nil? fail(OptionParser::MissingArgument, "please specify --#{arg}") end diff --git a/src/ruby/bin/interop/interop_server.rb b/src/ruby/bin/interop/interop_server.rb index 9273dcdf91..1a08eb97df 100755 --- a/src/ruby/bin/interop/interop_server.rb +++ b/src/ruby/bin/interop/interop_server.rb @@ -104,7 +104,7 @@ class TestTarget < Grpc::Testing::TestService::Service def unary_call(simple_req, _call) req_size = simple_req.response_size - SimpleResponse.new(payload: Payload.new(type: COMPRESSABLE, + SimpleResponse.new(payload: Payload.new(type: :COMPRESSABLE, body: nulls(req_size))) end diff --git a/test/core/iomgr/poll_kick_test.c b/test/core/iomgr/poll_kick_test.c index 9f0d0f38b3..c30a7b9ee0 100644 --- a/test/core/iomgr/poll_kick_test.c +++ b/test/core/iomgr/poll_kick_test.c @@ -33,16 +33,17 @@ #include "src/core/iomgr/pollset_kick.h" +#include <grpc/support/alloc.h> #include <grpc/support/log.h> #include "test/core/util/test_config.h" -static void test_allocation() { +static void test_allocation(void) { grpc_pollset_kick_state state; grpc_pollset_kick_init(&state); grpc_pollset_kick_destroy(&state); } -static void test_non_kick() { +static void test_non_kick(void) { grpc_pollset_kick_state state; int fd; @@ -54,7 +55,7 @@ static void test_non_kick() { grpc_pollset_kick_destroy(&state); } -static void test_basic_kick() { +static void test_basic_kick(void) { /* Kicked during poll */ grpc_pollset_kick_state state; int fd; @@ -73,7 +74,7 @@ static void test_basic_kick() { grpc_pollset_kick_destroy(&state); } -static void test_non_poll_kick() { +static void test_non_poll_kick(void) { /* Kick before entering poll */ grpc_pollset_kick_state state; int fd; @@ -86,6 +87,26 @@ static void test_non_poll_kick() { grpc_pollset_kick_destroy(&state); } +#define GRPC_MAX_CACHED_PIPES 50 + +static void test_over_free(void) { + /* Check high watermark pipe free logic */ + int i; + struct grpc_pollset_kick_state *kick_state = + gpr_malloc(sizeof(grpc_pollset_kick_state) * GRPC_MAX_CACHED_PIPES); + for (i = 0; i < GRPC_MAX_CACHED_PIPES; ++i) { + int fd; + grpc_pollset_kick_init(&kick_state[i]); + fd = grpc_pollset_kick_pre_poll(&kick_state[i]); + GPR_ASSERT(fd >= 0); + } + + for (i = 0; i < GRPC_MAX_CACHED_PIPES; ++i) { + grpc_pollset_kick_post_poll(&kick_state[i]); + grpc_pollset_kick_destroy(&kick_state[i]); + } +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); @@ -95,6 +116,7 @@ int main(int argc, char **argv) { test_basic_kick(); test_non_poll_kick(); test_non_kick(); + test_over_free(); grpc_pollset_kick_global_destroy(); return 0; |