Add ability to override default thread pool

pull/1894/head
Yang Gao 10 years ago
parent 82c8d6de1e
commit 6f4fb3b133
  1. 2
      BUILD
  2. 2
      Makefile
  3. 1
      build.json
  4. 49
      src/cpp/server/create_default_thread_pool.cc
  5. 4
      src/cpp/server/server_builder.cc
  6. 2
      src/cpp/server/thread_pool.h
  7. 2
      tools/doxygen/Doxyfile.c++.internal
  8. 2
      vsprojects/grpc++/grpc++.vcxproj
  9. 3
      vsprojects/grpc++/grpc++.vcxproj.filters
  10. 2
      vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj
  11. 3
      vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters

@ -582,6 +582,7 @@ cc_library(
"src/cpp/common/rpc_method.cc", "src/cpp/common/rpc_method.cc",
"src/cpp/proto/proto_utils.cc", "src/cpp/proto/proto_utils.cc",
"src/cpp/server/async_generic_service.cc", "src/cpp/server/async_generic_service.cc",
"src/cpp/server/create_default_thread_pool.cc",
"src/cpp/server/insecure_server_credentials.cc", "src/cpp/server/insecure_server_credentials.cc",
"src/cpp/server/server.cc", "src/cpp/server/server.cc",
"src/cpp/server/server_builder.cc", "src/cpp/server/server_builder.cc",
@ -661,6 +662,7 @@ cc_library(
"src/cpp/common/rpc_method.cc", "src/cpp/common/rpc_method.cc",
"src/cpp/proto/proto_utils.cc", "src/cpp/proto/proto_utils.cc",
"src/cpp/server/async_generic_service.cc", "src/cpp/server/async_generic_service.cc",
"src/cpp/server/create_default_thread_pool.cc",
"src/cpp/server/insecure_server_credentials.cc", "src/cpp/server/insecure_server_credentials.cc",
"src/cpp/server/server.cc", "src/cpp/server/server.cc",
"src/cpp/server/server_builder.cc", "src/cpp/server/server_builder.cc",

@ -3331,6 +3331,7 @@ LIBGRPC++_SRC = \
src/cpp/common/rpc_method.cc \ src/cpp/common/rpc_method.cc \
src/cpp/proto/proto_utils.cc \ src/cpp/proto/proto_utils.cc \
src/cpp/server/async_generic_service.cc \ src/cpp/server/async_generic_service.cc \
src/cpp/server/create_default_thread_pool.cc \
src/cpp/server/insecure_server_credentials.cc \ src/cpp/server/insecure_server_credentials.cc \
src/cpp/server/server.cc \ src/cpp/server/server.cc \
src/cpp/server/server_builder.cc \ src/cpp/server/server_builder.cc \
@ -3618,6 +3619,7 @@ LIBGRPC++_UNSECURE_SRC = \
src/cpp/common/rpc_method.cc \ src/cpp/common/rpc_method.cc \
src/cpp/proto/proto_utils.cc \ src/cpp/proto/proto_utils.cc \
src/cpp/server/async_generic_service.cc \ src/cpp/server/async_generic_service.cc \
src/cpp/server/create_default_thread_pool.cc \
src/cpp/server/insecure_server_credentials.cc \ src/cpp/server/insecure_server_credentials.cc \
src/cpp/server/server.cc \ src/cpp/server/server.cc \
src/cpp/server/server_builder.cc \ src/cpp/server/server_builder.cc \

@ -83,6 +83,7 @@
"src/cpp/common/rpc_method.cc", "src/cpp/common/rpc_method.cc",
"src/cpp/proto/proto_utils.cc", "src/cpp/proto/proto_utils.cc",
"src/cpp/server/async_generic_service.cc", "src/cpp/server/async_generic_service.cc",
"src/cpp/server/create_default_thread_pool.cc",
"src/cpp/server/insecure_server_credentials.cc", "src/cpp/server/insecure_server_credentials.cc",
"src/cpp/server/server.cc", "src/cpp/server/server.cc",
"src/cpp/server/server_builder.cc", "src/cpp/server/server_builder.cc",

@ -0,0 +1,49 @@
/*
*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <grpc/support/cpu.h>
#include "src/cpp/server/thread_pool.h"
#ifndef GRPC_CUSTOM_DEFAULT_THREAD_POOL
namespace grpc {
ThreadPoolInterface* CreateDefaultThreadPool() {
int cores = gpr_cpu_num_cores();
if (!cores) cores = 4;
return new ThreadPool(cores);
}
} // namespace grpc
#endif // !GRPC_CUSTOM_DEFAULT_THREAD_POOL

@ -87,9 +87,7 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
return nullptr; return nullptr;
} }
if (!thread_pool_ && !services_.empty()) { if (!thread_pool_ && !services_.empty()) {
int cores = gpr_cpu_num_cores(); thread_pool_ = CreateDefaultThreadPool();
if (!cores) cores = 4;
thread_pool_ = new ThreadPool(cores);
thread_pool_owned = true; thread_pool_owned = true;
} }
std::unique_ptr<Server> server( std::unique_ptr<Server> server(

@ -62,6 +62,8 @@ class ThreadPool GRPC_FINAL : public ThreadPoolInterface {
void ThreadFunc(); void ThreadFunc();
}; };
ThreadPoolInterface* CreateDefaultThreadPool();
} // namespace grpc } // namespace grpc
#endif // GRPC_INTERNAL_CPP_SERVER_THREAD_POOL_H #endif // GRPC_INTERNAL_CPP_SERVER_THREAD_POOL_H

@ -760,7 +760,7 @@ WARN_LOGFILE =
# spaces. # spaces.
# Note: If this tag is empty the current directory is searched. # Note: If this tag is empty the current directory is searched.
INPUT = include/grpc++/async_generic_service.h include/grpc++/async_unary_call.h include/grpc++/byte_buffer.h include/grpc++/channel_arguments.h include/grpc++/channel_interface.h include/grpc++/client_context.h include/grpc++/completion_queue.h include/grpc++/config.h include/grpc++/create_channel.h include/grpc++/credentials.h include/grpc++/generic_stub.h include/grpc++/impl/call.h include/grpc++/impl/client_unary_call.h include/grpc++/impl/grpc_library.h include/grpc++/impl/internal_stub.h include/grpc++/impl/rpc_method.h include/grpc++/impl/rpc_service_method.h include/grpc++/impl/service_type.h include/grpc++/impl/sync.h include/grpc++/impl/sync_cxx11.h include/grpc++/impl/sync_no_cxx11.h include/grpc++/impl/thd.h include/grpc++/impl/thd_cxx11.h include/grpc++/impl/thd_no_cxx11.h include/grpc++/server.h include/grpc++/server_builder.h include/grpc++/server_context.h include/grpc++/server_credentials.h include/grpc++/slice.h include/grpc++/status.h include/grpc++/status_code_enum.h include/grpc++/stream.h include/grpc++/thread_pool_interface.h include/grpc++/time.h src/cpp/client/secure_credentials.h src/cpp/server/secure_server_credentials.h src/cpp/client/channel.h src/cpp/proto/proto_utils.h src/cpp/server/thread_pool.h src/cpp/client/secure_credentials.cc src/cpp/server/secure_server_credentials.cc src/cpp/client/channel.cc src/cpp/client/channel_arguments.cc src/cpp/client/client_context.cc src/cpp/client/client_unary_call.cc src/cpp/client/create_channel.cc src/cpp/client/credentials.cc src/cpp/client/generic_stub.cc src/cpp/client/insecure_credentials.cc src/cpp/client/internal_stub.cc src/cpp/common/call.cc src/cpp/common/completion_queue.cc src/cpp/common/rpc_method.cc src/cpp/proto/proto_utils.cc src/cpp/server/async_generic_service.cc src/cpp/server/insecure_server_credentials.cc src/cpp/server/server.cc src/cpp/server/server_builder.cc src/cpp/server/server_context.cc src/cpp/server/server_credentials.cc src/cpp/server/thread_pool.cc src/cpp/util/byte_buffer.cc src/cpp/util/slice.cc src/cpp/util/status.cc src/cpp/util/time.cc INPUT = include/grpc++/async_generic_service.h include/grpc++/async_unary_call.h include/grpc++/byte_buffer.h include/grpc++/channel_arguments.h include/grpc++/channel_interface.h include/grpc++/client_context.h include/grpc++/completion_queue.h include/grpc++/config.h include/grpc++/create_channel.h include/grpc++/credentials.h include/grpc++/generic_stub.h include/grpc++/impl/call.h include/grpc++/impl/client_unary_call.h include/grpc++/impl/grpc_library.h include/grpc++/impl/internal_stub.h include/grpc++/impl/rpc_method.h include/grpc++/impl/rpc_service_method.h include/grpc++/impl/service_type.h include/grpc++/impl/sync.h include/grpc++/impl/sync_cxx11.h include/grpc++/impl/sync_no_cxx11.h include/grpc++/impl/thd.h include/grpc++/impl/thd_cxx11.h include/grpc++/impl/thd_no_cxx11.h include/grpc++/server.h include/grpc++/server_builder.h include/grpc++/server_context.h include/grpc++/server_credentials.h include/grpc++/slice.h include/grpc++/status.h include/grpc++/status_code_enum.h include/grpc++/stream.h include/grpc++/thread_pool_interface.h include/grpc++/time.h src/cpp/client/secure_credentials.h src/cpp/server/secure_server_credentials.h src/cpp/client/channel.h src/cpp/proto/proto_utils.h src/cpp/server/thread_pool.h src/cpp/client/secure_credentials.cc src/cpp/server/secure_server_credentials.cc src/cpp/client/channel.cc src/cpp/client/channel_arguments.cc src/cpp/client/client_context.cc src/cpp/client/client_unary_call.cc src/cpp/client/create_channel.cc src/cpp/client/credentials.cc src/cpp/client/generic_stub.cc src/cpp/client/insecure_credentials.cc src/cpp/client/internal_stub.cc src/cpp/common/call.cc src/cpp/common/completion_queue.cc src/cpp/common/rpc_method.cc src/cpp/proto/proto_utils.cc src/cpp/server/async_generic_service.cc src/cpp/server/create_default_thread_pool.cc src/cpp/server/insecure_server_credentials.cc src/cpp/server/server.cc src/cpp/server/server_builder.cc src/cpp/server/server_context.cc src/cpp/server/server_credentials.cc src/cpp/server/thread_pool.cc src/cpp/util/byte_buffer.cc src/cpp/util/slice.cc src/cpp/util/status.cc src/cpp/util/time.cc
# This tag can be used to specify the character encoding of the source files # This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

@ -221,6 +221,8 @@
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\cpp\server\async_generic_service.cc"> <ClCompile Include="..\..\src\cpp\server\async_generic_service.cc">
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\cpp\server\create_default_thread_pool.cc">
</ClCompile>
<ClCompile Include="..\..\src\cpp\server\insecure_server_credentials.cc"> <ClCompile Include="..\..\src\cpp\server\insecure_server_credentials.cc">
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\cpp\server\server.cc"> <ClCompile Include="..\..\src\cpp\server\server.cc">

@ -49,6 +49,9 @@
<ClCompile Include="..\..\src\cpp\server\async_generic_service.cc"> <ClCompile Include="..\..\src\cpp\server\async_generic_service.cc">
<Filter>src\cpp\server</Filter> <Filter>src\cpp\server</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\cpp\server\create_default_thread_pool.cc">
<Filter>src\cpp\server</Filter>
</ClCompile>
<ClCompile Include="..\..\src\cpp\server\insecure_server_credentials.cc"> <ClCompile Include="..\..\src\cpp\server\insecure_server_credentials.cc">
<Filter>src\cpp\server</Filter> <Filter>src\cpp\server</Filter>
</ClCompile> </ClCompile>

@ -215,6 +215,8 @@
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\cpp\server\async_generic_service.cc"> <ClCompile Include="..\..\src\cpp\server\async_generic_service.cc">
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\cpp\server\create_default_thread_pool.cc">
</ClCompile>
<ClCompile Include="..\..\src\cpp\server\insecure_server_credentials.cc"> <ClCompile Include="..\..\src\cpp\server\insecure_server_credentials.cc">
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\cpp\server\server.cc"> <ClCompile Include="..\..\src\cpp\server\server.cc">

@ -43,6 +43,9 @@
<ClCompile Include="..\..\src\cpp\server\async_generic_service.cc"> <ClCompile Include="..\..\src\cpp\server\async_generic_service.cc">
<Filter>src\cpp\server</Filter> <Filter>src\cpp\server</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\cpp\server\create_default_thread_pool.cc">
<Filter>src\cpp\server</Filter>
</ClCompile>
<ClCompile Include="..\..\src\cpp\server\insecure_server_credentials.cc"> <ClCompile Include="..\..\src\cpp\server\insecure_server_credentials.cc">
<Filter>src\cpp\server</Filter> <Filter>src\cpp\server</Filter>
</ClCompile> </ClCompile>

Loading…
Cancel
Save