ソースを参照

Merge branch 'master' of github.com:google/grpc

murgatroid99 10 年 前
コミット
9e14ead3f6

+ 1 - 53
.clang-format

@@ -1,57 +1,5 @@
 ---
 ---
 Language:        Cpp
 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
 ...
 ...
 
 

+ 104 - 45
INSTALL

@@ -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
 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
 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
 The recommended version of OpenSSL that provides ALPN support is available
 at this URL:
 at this URL:
 
 
   https://www.openssl.org/source/openssl-1.0.2-beta3.tar.gz
   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
 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
 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:
 libraries and headers:
 
 
-$ sudo make install
+  # make install

+ 23 - 7
src/core/iomgr/pollset_kick_posix.c

@@ -43,6 +43,9 @@
 
 
 /* This implementation is based on a freelist of pipes. */
 /* 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 {
 typedef struct grpc_kick_pipe_info {
   int pipe_read_fd;
   int pipe_read_fd;
   int pipe_write_fd;
   int pipe_write_fd;
@@ -50,14 +53,16 @@ typedef struct grpc_kick_pipe_info {
 } grpc_kick_pipe_info;
 } grpc_kick_pipe_info;
 
 
 static grpc_kick_pipe_info *pipe_freelist = NULL;
 static grpc_kick_pipe_info *pipe_freelist = NULL;
+static int pipe_freelist_count = 0;
 static gpr_mu pipe_freelist_mu;
 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;
   grpc_kick_pipe_info *info;
   gpr_mu_lock(&pipe_freelist_mu);
   gpr_mu_lock(&pipe_freelist_mu);
   if (pipe_freelist != NULL) {
   if (pipe_freelist != NULL) {
     info = pipe_freelist;
     info = pipe_freelist;
     pipe_freelist = pipe_freelist->next;
     pipe_freelist = pipe_freelist->next;
+    --pipe_freelist_count;
   } else {
   } else {
     int pipefd[2];
     int pipefd[2];
     /* TODO(klempner): Make this nonfatal */
     /* TODO(klempner): Make this nonfatal */
@@ -73,11 +78,26 @@ static grpc_kick_pipe_info *allocate_pipe() {
   return info;
   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) {
 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);
   gpr_mu_lock(&pipe_freelist_mu);
   pipe_info->next = pipe_freelist;
   pipe_info->next = pipe_freelist;
   pipe_freelist = pipe_info;
   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);
   gpr_mu_unlock(&pipe_freelist_mu);
 }
 }
 
 
@@ -88,11 +108,7 @@ void grpc_pollset_kick_global_init() {
 
 
 void grpc_pollset_kick_global_destroy() {
 void grpc_pollset_kick_global_destroy() {
   while (pipe_freelist != NULL) {
   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);
   gpr_mu_destroy(&pipe_freelist_mu);
 }
 }

+ 9 - 7
src/ruby/bin/interop/interop_client.rb

@@ -107,11 +107,11 @@ class PingPongPlayer
     @msg_sizes.each do |m|
     @msg_sizes.each do |m|
       req_size, resp_size = m
       req_size, resp_size = m
       req = req_cls.new(payload: Payload.new(body: nulls(req_size)),
       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)])
                         response_parameters: [p_cls.new(size: resp_size)])
       yield req
       yield req
       resp = @queue.pop
       resp = @queue.pop
-      assert_equal(PayloadType.lookup(COMPRESSABLE), resp.payload.type,
+      assert_equal(:COMPRESSABLE, resp.payload.type,
                    'payload type is wrong')
                    'payload type is wrong')
       assert_equal(resp_size, resp.payload.body.length,
       assert_equal(resp_size, resp.payload.body.length,
                    'payload body #{i} has the wrong length')
                    'payload body #{i} has the wrong length')
@@ -149,11 +149,13 @@ class NamedTests
   # FAILED
   # FAILED
   def large_unary
   def large_unary
     req_size, wanted_response_size = 271_828, 314_159
     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,
                             response_size: wanted_response_size,
                             payload: payload)
                             payload: payload)
     resp = @stub.unary_call(req)
     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,
     assert_equal(wanted_response_size, resp.payload.body.length,
                  'large_unary: payload had the wrong length')
                  'large_unary: payload had the wrong length')
     assert_equal(nulls(wanted_response_size), resp.payload.body,
     assert_equal(nulls(wanted_response_size), resp.payload.body,
@@ -185,12 +187,12 @@ class NamedTests
   def server_streaming
   def server_streaming
     msg_sizes = [31_415, 9, 2653, 58_979]
     msg_sizes = [31_415, 9, 2653, 58_979]
     response_spec = msg_sizes.map { |s| ResponseParameters.new(size: s) }
     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)
                                          response_parameters: response_spec)
     resps = @stub.streaming_output_call(req)
     resps = @stub.streaming_output_call(req)
     resps.each_with_index do |r, i|
     resps.each_with_index do |r, i|
       assert i < msg_sizes.length, 'too many responses'
       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')
                    'payload type is wrong')
       assert_equal(msg_sizes[i], r.payload.body.length,
       assert_equal(msg_sizes[i], r.payload.body.length,
                    'payload body #{i} has the wrong length')
                    'payload body #{i} has the wrong length')
@@ -235,7 +237,7 @@ def parse_options
     end
     end
   end.parse!
   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?
     if options[arg].nil?
       fail(OptionParser::MissingArgument, "please specify --#{arg}")
       fail(OptionParser::MissingArgument, "please specify --#{arg}")
     end
     end

+ 1 - 1
src/ruby/bin/interop/interop_server.rb

@@ -104,7 +104,7 @@ class TestTarget < Grpc::Testing::TestService::Service
 
 
   def unary_call(simple_req, _call)
   def unary_call(simple_req, _call)
     req_size = simple_req.response_size
     req_size = simple_req.response_size
-    SimpleResponse.new(payload: Payload.new(type: COMPRESSABLE,
+    SimpleResponse.new(payload: Payload.new(type: :COMPRESSABLE,
                                             body: nulls(req_size)))
                                             body: nulls(req_size)))
   end
   end
 
 

+ 26 - 4
test/core/iomgr/poll_kick_test.c

@@ -33,16 +33,17 @@
 
 
 #include "src/core/iomgr/pollset_kick.h"
 #include "src/core/iomgr/pollset_kick.h"
 
 
+#include <grpc/support/alloc.h>
 #include <grpc/support/log.h>
 #include <grpc/support/log.h>
 #include "test/core/util/test_config.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_state state;
   grpc_pollset_kick_init(&state);
   grpc_pollset_kick_init(&state);
   grpc_pollset_kick_destroy(&state);
   grpc_pollset_kick_destroy(&state);
 }
 }
 
 
-static void test_non_kick() {
+static void test_non_kick(void) {
   grpc_pollset_kick_state state;
   grpc_pollset_kick_state state;
   int fd;
   int fd;
 
 
@@ -54,7 +55,7 @@ static void test_non_kick() {
   grpc_pollset_kick_destroy(&state);
   grpc_pollset_kick_destroy(&state);
 }
 }
 
 
-static void test_basic_kick() {
+static void test_basic_kick(void) {
   /* Kicked during poll */
   /* Kicked during poll */
   grpc_pollset_kick_state state;
   grpc_pollset_kick_state state;
   int fd;
   int fd;
@@ -73,7 +74,7 @@ static void test_basic_kick() {
   grpc_pollset_kick_destroy(&state);
   grpc_pollset_kick_destroy(&state);
 }
 }
 
 
-static void test_non_poll_kick() {
+static void test_non_poll_kick(void) {
   /* Kick before entering poll */
   /* Kick before entering poll */
   grpc_pollset_kick_state state;
   grpc_pollset_kick_state state;
   int fd;
   int fd;
@@ -86,6 +87,26 @@ static void test_non_poll_kick() {
   grpc_pollset_kick_destroy(&state);
   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) {
 int main(int argc, char **argv) {
   grpc_test_init(argc, argv);
   grpc_test_init(argc, argv);
 
 
@@ -95,6 +116,7 @@ int main(int argc, char **argv) {
   test_basic_kick();
   test_basic_kick();
   test_non_poll_kick();
   test_non_poll_kick();
   test_non_kick();
   test_non_kick();
+  test_over_free();
 
 
   grpc_pollset_kick_global_destroy();
   grpc_pollset_kick_global_destroy();
   return 0;
   return 0;