Merge pull request #18881 from nanahpang/master

Add microbenchmark for callback apis
pull/18897/head
nanahpang 6 years ago committed by GitHub
commit f2efc92cc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 159
      CMakeLists.txt
  2. 151
      Makefile
  3. 64
      build.yaml
  4. 18
      grpc.gyp
  5. 93
      test/cpp/microbenchmarks/BUILD
  6. 136
      test/cpp/microbenchmarks/bm_callback_streaming_ping_pong.cc
  7. 118
      test/cpp/microbenchmarks/bm_callback_unary_ping_pong.cc
  8. 60
      test/cpp/microbenchmarks/bm_cq.cc
  9. 150
      test/cpp/microbenchmarks/callback_streaming_ping_pong.h
  10. 112
      test/cpp/microbenchmarks/callback_test_service.cc
  11. 48
      test/cpp/microbenchmarks/callback_test_service.h
  12. 101
      test/cpp/microbenchmarks/callback_unary_ping_pong.h
  13. 77
      tools/run_tests/generated/sources_and_headers.json
  14. 44
      tools/run_tests/generated/tests.json

@ -556,6 +556,12 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx bm_call_create)
endif()
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx bm_callback_streaming_ping_pong)
endif()
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx bm_callback_unary_ping_pong)
endif()
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx bm_channel)
endif()
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
@ -2908,6 +2914,67 @@ target_link_libraries(test_tcp_server
)
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
if (gRPC_BUILD_CODEGEN)
add_library(bm_callback_test_service_impl
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_mock.grpc.pb.h
test/cpp/microbenchmarks/callback_test_service.cc
)
if(WIN32 AND MSVC)
set_target_properties(bm_callback_test_service_impl PROPERTIES COMPILE_PDB_NAME "bm_callback_test_service_impl"
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
if (gRPC_INSTALL)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bm_callback_test_service_impl.pdb
DESTINATION ${gRPC_INSTALL_LIBDIR} OPTIONAL
)
endif()
endif()
protobuf_generate_grpc_cpp(
src/proto/grpc/testing/echo.proto
)
target_include_directories(bm_callback_test_service_impl
PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${_gRPC_SSL_INCLUDE_DIR}
PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR}
PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR}
PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR}
PRIVATE ${_gRPC_CARES_INCLUDE_DIR}
PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR}
PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR}
PRIVATE third_party/googletest/googletest/include
PRIVATE third_party/googletest/googletest
PRIVATE third_party/googletest/googlemock/include
PRIVATE third_party/googletest/googlemock
PRIVATE ${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(bm_callback_test_service_impl
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_benchmark
${_gRPC_BENCHMARK_LIBRARIES}
grpc++_test_util_unsecure
grpc_test_util_unsecure
grpc++_unsecure
grpc_unsecure
gpr
grpc++_test_config
${_gRPC_GFLAGS_LIBRARIES}
)
endif (gRPC_BUILD_CODEGEN)
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
@ -11551,6 +11618,98 @@ target_link_libraries(bm_call_create
)
endif()
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_executable(bm_callback_streaming_ping_pong
test/cpp/microbenchmarks/bm_callback_streaming_ping_pong.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(bm_callback_streaming_ping_pong
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${_gRPC_SSL_INCLUDE_DIR}
PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR}
PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR}
PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR}
PRIVATE ${_gRPC_CARES_INCLUDE_DIR}
PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR}
PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR}
PRIVATE third_party/googletest/googletest/include
PRIVATE third_party/googletest/googletest
PRIVATE third_party/googletest/googlemock/include
PRIVATE third_party/googletest/googlemock
PRIVATE ${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(bm_callback_streaming_ping_pong
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_benchmark
${_gRPC_BENCHMARK_LIBRARIES}
grpc++_test_util_unsecure
grpc_test_util_unsecure
grpc++_unsecure
grpc_unsecure
gpr
grpc++_test_config
bm_callback_test_service_impl
${_gRPC_GFLAGS_LIBRARIES}
)
endif()
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_executable(bm_callback_unary_ping_pong
test/cpp/microbenchmarks/bm_callback_unary_ping_pong.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(bm_callback_unary_ping_pong
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${_gRPC_SSL_INCLUDE_DIR}
PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR}
PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR}
PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR}
PRIVATE ${_gRPC_CARES_INCLUDE_DIR}
PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR}
PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR}
PRIVATE third_party/googletest/googletest/include
PRIVATE third_party/googletest/googletest
PRIVATE third_party/googletest/googlemock/include
PRIVATE third_party/googletest/googlemock
PRIVATE ${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(bm_callback_unary_ping_pong
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_benchmark
${_gRPC_BENCHMARK_LIBRARIES}
grpc++_test_util_unsecure
grpc_test_util_unsecure
grpc++_unsecure
grpc_unsecure
gpr
grpc++_test_config
bm_callback_test_service_impl
${_gRPC_GFLAGS_LIBRARIES}
)
endif()
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)

@ -1162,6 +1162,8 @@ bm_alarm: $(BINDIR)/$(CONFIG)/bm_alarm
bm_arena: $(BINDIR)/$(CONFIG)/bm_arena
bm_byte_buffer: $(BINDIR)/$(CONFIG)/bm_byte_buffer
bm_call_create: $(BINDIR)/$(CONFIG)/bm_call_create
bm_callback_streaming_ping_pong: $(BINDIR)/$(CONFIG)/bm_callback_streaming_ping_pong
bm_callback_unary_ping_pong: $(BINDIR)/$(CONFIG)/bm_callback_unary_ping_pong
bm_channel: $(BINDIR)/$(CONFIG)/bm_channel
bm_chttp2_hpack: $(BINDIR)/$(CONFIG)/bm_chttp2_hpack
bm_chttp2_transport: $(BINDIR)/$(CONFIG)/bm_chttp2_transport
@ -1641,6 +1643,8 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/bm_arena \
$(BINDIR)/$(CONFIG)/bm_byte_buffer \
$(BINDIR)/$(CONFIG)/bm_call_create \
$(BINDIR)/$(CONFIG)/bm_callback_streaming_ping_pong \
$(BINDIR)/$(CONFIG)/bm_callback_unary_ping_pong \
$(BINDIR)/$(CONFIG)/bm_channel \
$(BINDIR)/$(CONFIG)/bm_chttp2_hpack \
$(BINDIR)/$(CONFIG)/bm_chttp2_transport \
@ -1788,6 +1792,8 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/bm_arena \
$(BINDIR)/$(CONFIG)/bm_byte_buffer \
$(BINDIR)/$(CONFIG)/bm_call_create \
$(BINDIR)/$(CONFIG)/bm_callback_streaming_ping_pong \
$(BINDIR)/$(CONFIG)/bm_callback_unary_ping_pong \
$(BINDIR)/$(CONFIG)/bm_channel \
$(BINDIR)/$(CONFIG)/bm_chttp2_hpack \
$(BINDIR)/$(CONFIG)/bm_chttp2_transport \
@ -2241,6 +2247,10 @@ test_cxx: buildtests_cxx
$(Q) $(BINDIR)/$(CONFIG)/bm_byte_buffer || ( echo test bm_byte_buffer failed ; exit 1 )
$(E) "[RUN] Testing bm_call_create"
$(Q) $(BINDIR)/$(CONFIG)/bm_call_create || ( echo test bm_call_create failed ; exit 1 )
$(E) "[RUN] Testing bm_callback_streaming_ping_pong"
$(Q) $(BINDIR)/$(CONFIG)/bm_callback_streaming_ping_pong || ( echo test bm_callback_streaming_ping_pong failed ; exit 1 )
$(E) "[RUN] Testing bm_callback_unary_ping_pong"
$(Q) $(BINDIR)/$(CONFIG)/bm_callback_unary_ping_pong || ( echo test bm_callback_unary_ping_pong failed ; exit 1 )
$(E) "[RUN] Testing bm_channel"
$(Q) $(BINDIR)/$(CONFIG)/bm_channel || ( echo test bm_channel failed ; exit 1 )
$(E) "[RUN] Testing bm_chttp2_hpack"
@ -5297,6 +5307,58 @@ endif
endif
LIBBM_CALLBACK_TEST_SERVICE_IMPL_SRC = \
$(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc \
test/cpp/microbenchmarks/callback_test_service.cc \
PUBLIC_HEADERS_CXX += \
LIBBM_CALLBACK_TEST_SERVICE_IMPL_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBM_CALLBACK_TEST_SERVICE_IMPL_SRC))))
$(LIBBM_CALLBACK_TEST_SERVICE_IMPL_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX
ifeq ($(NO_SECURE),true)
# You can't build secure libraries if you don't have OpenSSL.
$(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a: openssl_dep_error
else
ifeq ($(NO_PROTOBUF),true)
# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
$(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a: protobuf_dep_error
else
$(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(PROTOBUF_DEP) $(LIBBM_CALLBACK_TEST_SERVICE_IMPL_OBJS)
$(E) "[AR] Creating $@"
$(Q) mkdir -p `dirname $@`
$(Q) rm -f $(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a
$(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a $(LIBBM_CALLBACK_TEST_SERVICE_IMPL_OBJS)
ifeq ($(SYSTEM),Darwin)
$(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a
endif
endif
endif
ifneq ($(NO_SECURE),true)
ifneq ($(NO_DEPS),true)
-include $(LIBBM_CALLBACK_TEST_SERVICE_IMPL_OBJS:.o=.dep)
endif
endif
$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/callback_test_service.o: $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc
LIBDNS_TEST_UTIL_SRC = \
test/cpp/naming/dns_test_util.cc \
@ -14497,6 +14559,94 @@ endif
endif
BM_CALLBACK_STREAMING_PING_PONG_SRC = \
test/cpp/microbenchmarks/bm_callback_streaming_ping_pong.cc \
BM_CALLBACK_STREAMING_PING_PONG_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CALLBACK_STREAMING_PING_PONG_SRC))))
ifeq ($(NO_SECURE),true)
# You can't build secure targets if you don't have OpenSSL.
$(BINDIR)/$(CONFIG)/bm_callback_streaming_ping_pong: openssl_dep_error
else
ifeq ($(NO_PROTOBUF),true)
# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+.
$(BINDIR)/$(CONFIG)/bm_callback_streaming_ping_pong: protobuf_dep_error
else
$(BINDIR)/$(CONFIG)/bm_callback_streaming_ping_pong: $(PROTOBUF_DEP) $(BM_CALLBACK_STREAMING_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(BM_CALLBACK_STREAMING_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_callback_streaming_ping_pong
endif
endif
$(BM_CALLBACK_STREAMING_PING_PONG_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX
$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_callback_streaming_ping_pong.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a
deps_bm_callback_streaming_ping_pong: $(BM_CALLBACK_STREAMING_PING_PONG_OBJS:.o=.dep)
ifneq ($(NO_SECURE),true)
ifneq ($(NO_DEPS),true)
-include $(BM_CALLBACK_STREAMING_PING_PONG_OBJS:.o=.dep)
endif
endif
BM_CALLBACK_UNARY_PING_PONG_SRC = \
test/cpp/microbenchmarks/bm_callback_unary_ping_pong.cc \
BM_CALLBACK_UNARY_PING_PONG_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CALLBACK_UNARY_PING_PONG_SRC))))
ifeq ($(NO_SECURE),true)
# You can't build secure targets if you don't have OpenSSL.
$(BINDIR)/$(CONFIG)/bm_callback_unary_ping_pong: openssl_dep_error
else
ifeq ($(NO_PROTOBUF),true)
# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+.
$(BINDIR)/$(CONFIG)/bm_callback_unary_ping_pong: protobuf_dep_error
else
$(BINDIR)/$(CONFIG)/bm_callback_unary_ping_pong: $(PROTOBUF_DEP) $(BM_CALLBACK_UNARY_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(BM_CALLBACK_UNARY_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_callback_unary_ping_pong
endif
endif
$(BM_CALLBACK_UNARY_PING_PONG_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX
$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_callback_unary_ping_pong.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libbm_callback_test_service_impl.a
deps_bm_callback_unary_ping_pong: $(BM_CALLBACK_UNARY_PING_PONG_OBJS:.o=.dep)
ifneq ($(NO_SECURE),true)
ifneq ($(NO_DEPS),true)
-include $(BM_CALLBACK_UNARY_PING_PONG_OBJS:.o=.dep)
endif
endif
BM_CHANNEL_SRC = \
test/cpp/microbenchmarks/bm_channel.cc \
@ -22286,6 +22436,7 @@ test/cpp/interop/interop_client.cc: $(OPENSSL_DEP)
test/cpp/interop/interop_server.cc: $(OPENSSL_DEP)
test/cpp/interop/interop_server_bootstrap.cc: $(OPENSSL_DEP)
test/cpp/interop/server_helper.cc: $(OPENSSL_DEP)
test/cpp/microbenchmarks/callback_test_service.cc: $(OPENSSL_DEP)
test/cpp/microbenchmarks/helpers.cc: $(OPENSSL_DEP)
test/cpp/naming/dns_test_util.cc: $(OPENSSL_DEP)
test/cpp/qps/benchmark_config.cc: $(OPENSSL_DEP)

@ -1689,6 +1689,24 @@ libs:
- grpc_test_util
- grpc
- gpr
- name: bm_callback_test_service_impl
build: test
language: c++
headers:
- test/cpp/microbenchmarks/callback_test_service.h
src:
- src/proto/grpc/testing/echo.proto
- test/cpp/microbenchmarks/callback_test_service.cc
deps:
- grpc_benchmark
- benchmark
- grpc++_test_util_unsecure
- grpc_test_util_unsecure
- grpc++_unsecure
- grpc_unsecure
- gpr
- grpc++_test_config
defaults: benchmark
- name: dns_test_util
build: private
language: c++
@ -4055,6 +4073,52 @@ targets:
- linux
- posix
uses_polling: false
- name: bm_callback_streaming_ping_pong
build: test
language: c++
headers:
- test/cpp/microbenchmarks/callback_streaming_ping_pong.h
src:
- test/cpp/microbenchmarks/bm_callback_streaming_ping_pong.cc
deps:
- grpc_benchmark
- benchmark
- grpc++_test_util_unsecure
- grpc_test_util_unsecure
- grpc++_unsecure
- grpc_unsecure
- gpr
- grpc++_test_config
- bm_callback_test_service_impl
benchmark: true
defaults: benchmark
platforms:
- mac
- linux
- posix
- name: bm_callback_unary_ping_pong
build: test
language: c++
headers:
- test/cpp/microbenchmarks/callback_unary_ping_pong.h
src:
- test/cpp/microbenchmarks/bm_callback_unary_ping_pong.cc
deps:
- grpc_benchmark
- benchmark
- grpc++_test_util_unsecure
- grpc_test_util_unsecure
- grpc++_unsecure
- grpc_unsecure
- gpr
- grpc++_test_config
- bm_callback_test_service_impl
benchmark: true
defaults: benchmark
platforms:
- mac
- linux
- posix
- name: bm_channel
build: test
language: c++

@ -1407,6 +1407,24 @@
'test/core/util/test_tcp_server.cc',
],
},
{
'target_name': 'bm_callback_test_service_impl',
'type': 'static_library',
'dependencies': [
'grpc_benchmark',
'benchmark',
'grpc++_test_util_unsecure',
'grpc_test_util_unsecure',
'grpc++_unsecure',
'grpc_unsecure',
'gpr',
'grpc++_test_config',
],
'sources': [
'src/proto/grpc/testing/echo.proto',
'test/cpp/microbenchmarks/callback_test_service.cc',
],
},
{
'target_name': 'dns_test_util',
'type': 'static_library',

@ -39,85 +39,85 @@ grpc_cc_library(
external_deps = [
"benchmark",
],
tags = ["no_windows"],
deps = [
"//:grpc++_unsecure",
"//src/proto/grpc/testing:echo_proto",
"//test/core/util:grpc_test_util_unsecure",
"//test/cpp/util:test_config",
],
tags = ["no_windows"],
)
grpc_cc_binary(
name = "bm_closure",
testonly = 1,
srcs = ["bm_closure.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_binary(
name = "bm_alarm",
testonly = 1,
srcs = ["bm_alarm.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_binary(
name = "bm_arena",
testonly = 1,
srcs = ["bm_arena.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_binary(
name = "bm_byte_buffer",
testonly = 1,
srcs = ["bm_byte_buffer.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_binary(
name = "bm_channel",
testonly = 1,
srcs = ["bm_channel.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_binary(
name = "bm_call_create",
testonly = 1,
srcs = ["bm_call_create.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_binary(
name = "bm_cq",
testonly = 1,
srcs = ["bm_cq.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_binary(
name = "bm_cq_multiple_threads",
testonly = 1,
srcs = ["bm_cq_multiple_threads.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_binary(
name = "bm_error",
testonly = 1,
srcs = ["bm_error.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_library(
@ -126,8 +126,8 @@ grpc_cc_library(
hdrs = [
"fullstack_streaming_ping_pong.h",
],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_binary(
@ -136,8 +136,8 @@ grpc_cc_binary(
srcs = [
"bm_fullstack_streaming_ping_pong.cc",
],
deps = [":fullstack_streaming_ping_pong_h"],
tags = ["no_windows"],
deps = [":fullstack_streaming_ping_pong_h"],
)
grpc_cc_library(
@ -155,16 +155,16 @@ grpc_cc_binary(
srcs = [
"bm_fullstack_streaming_pump.cc",
],
deps = [":fullstack_streaming_pump_h"],
tags = ["no_windows"],
deps = [":fullstack_streaming_pump_h"],
)
grpc_cc_binary(
name = "bm_fullstack_trickle",
testonly = 1,
srcs = ["bm_fullstack_trickle.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_library(
@ -182,24 +182,24 @@ grpc_cc_binary(
srcs = [
"bm_fullstack_unary_ping_pong.cc",
],
deps = [":fullstack_unary_ping_pong_h"],
tags = ["no_windows"],
deps = [":fullstack_unary_ping_pong_h"],
)
grpc_cc_binary(
name = "bm_metadata",
testonly = 1,
srcs = ["bm_metadata.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_binary(
name = "bm_chttp2_hpack",
testonly = 1,
srcs = ["bm_chttp2_hpack.cc"],
deps = [":helpers"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_binary(
@ -218,6 +218,65 @@ grpc_cc_binary(
name = "bm_timer",
testonly = 1,
srcs = ["bm_timer.cc"],
tags = ["no_windows"],
deps = [":helpers"],
)
grpc_cc_library(
name = "bm_callback_test_service_impl",
testonly = 1,
srcs = ["callback_test_service.cc"],
hdrs = ["callback_test_service.h"],
external_deps = [
"benchmark",
],
deps = [
":helpers",
"//src/proto/grpc/testing:echo_proto",
"//test/cpp/util:test_util",
],
)
grpc_cc_library(
name = "callback_unary_ping_pong_h",
testonly = 1,
hdrs = [
"callback_unary_ping_pong.h",
],
deps = [
":bm_callback_test_service_impl",
":helpers",
],
)
grpc_cc_binary(
name = "bm_callback_unary_ping_pong",
testonly = 1,
srcs = [
"bm_callback_unary_ping_pong.cc",
],
tags = ["no_windows"],
deps = [":callback_unary_ping_pong_h"],
)
grpc_cc_library(
name = "callback_streaming_ping_pong_h",
testonly = 1,
hdrs = [
"callback_streaming_ping_pong.h",
],
deps = [
":bm_callback_test_service_impl",
":helpers",
],
)
grpc_cc_binary(
name = "bm_callback_streaming_ping_pong",
testonly = 1,
srcs = [
"bm_callback_streaming_ping_pong.cc",
],
tags = ["no_windows"],
deps = [":callback_streaming_ping_pong_h"],
)

@ -0,0 +1,136 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "test/cpp/microbenchmarks/callback_streaming_ping_pong.h"
#include "test/cpp/util/test_config.h"
namespace grpc {
namespace testing {
/*******************************************************************************
* CONFIGURATIONS
*/
// Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
// internal microbenchmarking tooling
static void StreamingPingPongMsgSizeArgs(benchmark::internal::Benchmark* b) {
// base case: 0 byte ping-pong msgs
b->Args({0, 1});
b->Args({0, 2});
for (int msg_size = 1; msg_size <= 128 * 1024 * 1024; msg_size *= 8) {
b->Args({msg_size, 1});
b->Args({msg_size, 2});
}
}
// Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
// internal microbenchmarking tooling
static void StreamingPingPongMsgsNumberArgs(benchmark::internal::Benchmark* b) {
for (int msg_number = 1; msg_number <= 256 * 1024; msg_number *= 8) {
b->Args({0, msg_number});
b->Args({1024, msg_number});
}
}
// Streaming with different message size
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
NoOpMutator)
->Apply(StreamingPingPongMsgSizeArgs);
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, MinInProcess, NoOpMutator,
NoOpMutator)
->Apply(StreamingPingPongMsgSizeArgs);
// Streaming with different message number
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
NoOpMutator)
->Apply(StreamingPingPongMsgsNumberArgs);
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, MinInProcess, NoOpMutator,
NoOpMutator)
->Apply(StreamingPingPongMsgsNumberArgs);
// Client context with different metadata
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
NoOpMutator)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
NoOpMutator)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
->Args({0, 1});
// Server context with different metadata
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
->Args({0, 1});
BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
->Args({0, 1});
} // namespace testing
} // namespace grpc
// Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
// and others do not. This allows us to support both modes.
namespace benchmark {
void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
} // namespace benchmark
int main(int argc, char** argv) {
LibraryInitializer libInit;
::benchmark::Initialize(&argc, argv);
::grpc::testing::InitTest(&argc, &argv, false);
benchmark::RunTheBenchmarksNamespaced();
return 0;
}

@ -0,0 +1,118 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "test/cpp/microbenchmarks/callback_unary_ping_pong.h"
#include "test/cpp/util/test_config.h"
namespace grpc {
namespace testing {
/*******************************************************************************
* CONFIGURATIONS
*/
// Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
// internal microbenchmarking tooling
static void SweepSizesArgs(benchmark::internal::Benchmark* b) {
b->Args({0, 0});
for (int i = 1; i <= 128 * 1024 * 1024; i *= 8) {
// First argument is the message size of request
// Second argument is the message size of response
b->Args({i, 0});
b->Args({0, i});
b->Args({i, i});
}
}
// Unary ping pong with different message size of request and response
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
NoOpMutator)
->Apply(SweepSizesArgs);
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, MinInProcess, NoOpMutator,
NoOpMutator)
->Apply(SweepSizesArgs);
// Client context with different metadata
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
->Args({0, 0});
// Server context with different metadata
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
->Args({0, 0});
} // namespace testing
} // namespace grpc
// Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
// and others do not. This allows us to support both modes.
namespace benchmark {
void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
} // namespace benchmark
int main(int argc, char** argv) {
LibraryInitializer libInit;
::benchmark::Initialize(&argc, argv);
::grpc::testing::InitTest(&argc, &argv, false);
benchmark::RunTheBenchmarksNamespaced();
return 0;
}

@ -144,6 +144,66 @@ static void BM_EmptyCore(benchmark::State& state) {
}
BENCHMARK(BM_EmptyCore);
// Helper for tests to shutdown correctly and tersely
static void shutdown_and_destroy(grpc_completion_queue* cc) {
grpc_completion_queue_shutdown(cc);
grpc_completion_queue_destroy(cc);
}
// Tag completion queue iterate times
class TagCallback : public grpc_experimental_completion_queue_functor {
public:
explicit TagCallback(int* iter) : iter_(iter) {
functor_run = &TagCallback::Run;
}
~TagCallback() {}
static void Run(grpc_experimental_completion_queue_functor* cb, int ok) {
GPR_ASSERT(static_cast<bool>(ok));
*static_cast<TagCallback*>(cb)->iter_ += 1;
};
private:
int* iter_;
};
// Check if completion queue is shut down
class ShutdownCallback : public grpc_experimental_completion_queue_functor {
public:
explicit ShutdownCallback(bool* done) : done_(done) {
functor_run = &ShutdownCallback::Run;
}
~ShutdownCallback() {}
static void Run(grpc_experimental_completion_queue_functor* cb, int ok) {
*static_cast<ShutdownCallback*>(cb)->done_ = static_cast<bool>(ok);
}
private:
bool* done_;
};
static void BM_Callback_CQ_Pass1Core(benchmark::State& state) {
TrackCounters track_counters;
int iteration = 0;
TagCallback tag_cb(&iteration);
bool got_shutdown = false;
ShutdownCallback shutdown_cb(&got_shutdown);
grpc_completion_queue* cc =
grpc_completion_queue_create_for_callback(&shutdown_cb, nullptr);
while (state.KeepRunning()) {
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx;
grpc_cq_completion completion;
GPR_ASSERT(grpc_cq_begin_op(cc, &tag_cb));
grpc_cq_end_op(cc, &tag_cb, GRPC_ERROR_NONE, DoneWithCompletionOnStack,
nullptr, &completion);
}
shutdown_and_destroy(cc);
GPR_ASSERT(got_shutdown);
GPR_ASSERT(iteration == static_cast<int>(state.iterations()));
track_counters.Finish(state);
}
BENCHMARK(BM_Callback_CQ_Pass1Core);
} // namespace testing
} // namespace grpc

@ -0,0 +1,150 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef TEST_CPP_MICROBENCHMARKS_CALLBACK_STREAMING_PING_PONG_H
#define TEST_CPP_MICROBENCHMARKS_CALLBACK_STREAMING_PING_PONG_H
#include <benchmark/benchmark.h>
#include <sstream>
#include "src/core/lib/profiling/timers.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/microbenchmarks/callback_test_service.h"
#include "test/cpp/microbenchmarks/fullstack_context_mutators.h"
#include "test/cpp/microbenchmarks/fullstack_fixtures.h"
namespace grpc {
namespace testing {
/*******************************************************************************
* BENCHMARKING KERNELS
*/
class BidiClient
: public grpc::experimental::ClientBidiReactor<EchoRequest, EchoResponse> {
public:
BidiClient(benchmark::State* state, EchoTestService::Stub* stub,
ClientContext* cli_ctx, EchoRequest* request,
EchoResponse* response)
: state_{state},
stub_{stub},
cli_ctx_{cli_ctx},
request_{request},
response_{response} {
msgs_size_ = state->range(0);
msgs_to_send_ = state->range(1);
StartNewRpc();
}
void OnReadDone(bool ok) override {
if (!ok) {
gpr_log(GPR_ERROR, "Client read failed");
return;
}
MaybeWrite();
}
void OnWriteDone(bool ok) override {
if (!ok) {
gpr_log(GPR_ERROR, "Client write failed");
return;
}
writes_complete_++;
StartRead(response_);
}
void OnDone(const Status& s) override {
GPR_ASSERT(s.ok());
GPR_ASSERT(writes_complete_ == msgs_to_send_);
if (state_->KeepRunning()) {
writes_complete_ = 0;
StartNewRpc();
} else {
std::unique_lock<std::mutex> l(mu);
done = true;
cv.notify_one();
}
}
void StartNewRpc() {
cli_ctx_->~ClientContext();
new (cli_ctx_) ClientContext();
cli_ctx_->AddMetadata(kServerMessageSize, grpc::to_string(msgs_size_));
stub_->experimental_async()->BidiStream(cli_ctx_, this);
MaybeWrite();
StartCall();
}
void Await() {
std::unique_lock<std::mutex> l(mu);
while (!done) {
cv.wait(l);
}
}
private:
void MaybeWrite() {
if (writes_complete_ < msgs_to_send_) {
StartWrite(request_);
} else {
StartWritesDone();
}
}
benchmark::State* state_;
EchoTestService::Stub* stub_;
ClientContext* cli_ctx_;
EchoRequest* request_;
EchoResponse* response_;
int writes_complete_{0};
int msgs_to_send_;
int msgs_size_;
std::mutex mu;
std::condition_variable cv;
bool done;
};
template <class Fixture, class ClientContextMutator, class ServerContextMutator>
static void BM_CallbackBidiStreaming(benchmark::State& state) {
int message_size = state.range(0);
int max_ping_pongs = state.range(1);
CallbackStreamingTestService service;
std::unique_ptr<Fixture> fixture(new Fixture(&service));
std::unique_ptr<EchoTestService::Stub> stub_(
EchoTestService::NewStub(fixture->channel()));
EchoRequest request;
EchoResponse response;
ClientContext cli_ctx;
if (message_size > 0) {
request.set_message(std::string(message_size, 'a'));
} else {
request.set_message("");
}
if (state.KeepRunning()) {
GPR_TIMER_SCOPE("BenchmarkCycle", 0);
BidiClient test{&state, stub_.get(), &cli_ctx, &request, &response};
test.Await();
}
fixture->Finish(state);
fixture.reset();
state.SetBytesProcessed(2 * message_size * max_ping_pongs *
state.iterations());
}
} // namespace testing
} // namespace grpc
#endif // TEST_CPP_MICROBENCHMARKS_CALLBACK_STREAMING_PING_PONG_H

@ -0,0 +1,112 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "test/cpp/microbenchmarks/callback_test_service.h"
namespace grpc {
namespace testing {
namespace {
grpc::string ToString(const grpc::string_ref& r) {
return grpc::string(r.data(), r.size());
}
int GetIntValueFromMetadataHelper(
const char* key,
const std::multimap<grpc::string_ref, grpc::string_ref>& metadata,
int default_value) {
if (metadata.find(key) != metadata.end()) {
std::istringstream iss(ToString(metadata.find(key)->second));
iss >> default_value;
}
return default_value;
}
int GetIntValueFromMetadata(
const char* key,
const std::multimap<grpc::string_ref, grpc::string_ref>& metadata,
int default_value) {
return GetIntValueFromMetadataHelper(key, metadata, default_value);
}
} // namespace
void CallbackStreamingTestService::Echo(
ServerContext* context, const EchoRequest* request, EchoResponse* response,
experimental::ServerCallbackRpcController* controller) {
int response_msgs_size = GetIntValueFromMetadata(
kServerMessageSize, context->client_metadata(), 0);
if (response_msgs_size > 0) {
response->set_message(std::string(response_msgs_size, 'a'));
} else {
response->set_message("");
}
controller->Finish(Status::OK);
}
experimental::ServerBidiReactor<EchoRequest, EchoResponse>*
CallbackStreamingTestService::BidiStream() {
class Reactor
: public experimental::ServerBidiReactor<EchoRequest, EchoResponse> {
public:
Reactor() {}
void OnStarted(ServerContext* context) override {
ctx_ = context;
message_size_ = GetIntValueFromMetadata(kServerMessageSize,
context->client_metadata(), 0);
StartRead(&request_);
}
void OnDone() override {
GPR_ASSERT(finished_);
delete this;
}
void OnCancel() override {}
void OnReadDone(bool ok) override {
if (!ok) {
// Stream is over
Finish(::grpc::Status::OK);
finished_ = true;
return;
}
if (message_size_ > 0) {
response_.set_message(std::string(message_size_, 'a'));
} else {
response_.set_message("");
}
StartWrite(&response_);
}
void OnWriteDone(bool ok) override {
if (!ok) {
gpr_log(GPR_ERROR, "Server write failed");
return;
}
StartRead(&request_);
}
private:
ServerContext* ctx_;
EchoRequest request_;
EchoResponse response_;
int message_size_;
bool finished_{false};
};
return new Reactor;
}
} // namespace testing
} // namespace grpc

@ -0,0 +1,48 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef TEST_CPP_MICROBENCHMARKS_CALLBACK_TEST_SERVICE_H
#define TEST_CPP_MICROBENCHMARKS_CALLBACK_TEST_SERVICE_H
#include <benchmark/benchmark.h>
#include <condition_variable>
#include <memory>
#include <mutex>
#include <sstream>
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/util/string_ref_helper.h"
namespace grpc {
namespace testing {
const char* const kServerMessageSize = "server_message_size";
class CallbackStreamingTestService
: public EchoTestService::ExperimentalCallbackService {
public:
CallbackStreamingTestService() {}
void Echo(ServerContext* context, const EchoRequest* request,
EchoResponse* response,
experimental::ServerCallbackRpcController* controller) override;
experimental::ServerBidiReactor<EchoRequest, EchoResponse>* BidiStream()
override;
};
} // namespace testing
} // namespace grpc
#endif // TEST_CPP_MICROBENCHMARKS_CALLBACK_TEST_SERVICE_H

@ -0,0 +1,101 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/* Benchmark gRPC end2end in various configurations */
#ifndef TEST_CPP_MICROBENCHMARKS_CALLBACK_UNARY_PING_PONG_H
#define TEST_CPP_MICROBENCHMARKS_CALLBACK_UNARY_PING_PONG_H
#include <benchmark/benchmark.h>
#include <sstream>
#include "src/core/lib/profiling/timers.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/microbenchmarks/callback_test_service.h"
#include "test/cpp/microbenchmarks/fullstack_context_mutators.h"
#include "test/cpp/microbenchmarks/fullstack_fixtures.h"
namespace grpc {
namespace testing {
/*******************************************************************************
* BENCHMARKING KERNELS
*/
void SendCallbackUnaryPingPong(benchmark::State* state, ClientContext* cli_ctx,
EchoRequest* request, EchoResponse* response,
EchoTestService::Stub* stub_, bool* done,
std::mutex* mu, std::condition_variable* cv) {
int response_msgs_size = state->range(1);
cli_ctx->AddMetadata(kServerMessageSize, grpc::to_string(response_msgs_size));
stub_->experimental_async()->Echo(
cli_ctx, request, response,
[state, cli_ctx, request, response, stub_, done, mu, cv](Status s) {
GPR_ASSERT(s.ok());
if (state->KeepRunning()) {
cli_ctx->~ClientContext();
new (cli_ctx) ClientContext();
SendCallbackUnaryPingPong(state, cli_ctx, request, response, stub_,
done, mu, cv);
} else {
std::lock_guard<std::mutex> l(*mu);
*done = true;
cv->notify_one();
}
});
};
template <class Fixture, class ClientContextMutator, class ServerContextMutator>
static void BM_CallbackUnaryPingPong(benchmark::State& state) {
int request_msgs_size = state.range(0);
int response_msgs_size = state.range(1);
CallbackStreamingTestService service;
std::unique_ptr<Fixture> fixture(new Fixture(&service));
std::unique_ptr<EchoTestService::Stub> stub_(
EchoTestService::NewStub(fixture->channel()));
EchoRequest request;
EchoResponse response;
ClientContext cli_ctx;
if (request_msgs_size > 0) {
request.set_message(std::string(request_msgs_size, 'a'));
} else {
request.set_message("");
}
std::mutex mu;
std::condition_variable cv;
bool done = false;
if (state.KeepRunning()) {
GPR_TIMER_SCOPE("BenchmarkCycle", 0);
SendCallbackUnaryPingPong(&state, &cli_ctx, &request, &response,
stub_.get(), &done, &mu, &cv);
}
std::unique_lock<std::mutex> l(mu);
while (!done) {
cv.wait(l);
}
fixture->Finish(state);
fixture.reset();
state.SetBytesProcessed(request_msgs_size * state.iterations() +
response_msgs_size * state.iterations());
}
} // namespace testing
} // namespace grpc
#endif // TEST_CPP_MICROBENCHMARKS_FULLSTACK_UNARY_PING_PONG_H

@ -2776,6 +2776,56 @@
"third_party": false,
"type": "target"
},
{
"deps": [
"benchmark",
"bm_callback_test_service_impl",
"gpr",
"grpc++_test_config",
"grpc++_test_util_unsecure",
"grpc++_unsecure",
"grpc_benchmark",
"grpc_test_util_unsecure",
"grpc_unsecure"
],
"headers": [
"test/cpp/microbenchmarks/callback_streaming_ping_pong.h"
],
"is_filegroup": false,
"language": "c++",
"name": "bm_callback_streaming_ping_pong",
"src": [
"test/cpp/microbenchmarks/bm_callback_streaming_ping_pong.cc",
"test/cpp/microbenchmarks/callback_streaming_ping_pong.h"
],
"third_party": false,
"type": "target"
},
{
"deps": [
"benchmark",
"bm_callback_test_service_impl",
"gpr",
"grpc++_test_config",
"grpc++_test_util_unsecure",
"grpc++_unsecure",
"grpc_benchmark",
"grpc_test_util_unsecure",
"grpc_unsecure"
],
"headers": [
"test/cpp/microbenchmarks/callback_unary_ping_pong.h"
],
"is_filegroup": false,
"language": "c++",
"name": "bm_callback_unary_ping_pong",
"src": [
"test/cpp/microbenchmarks/bm_callback_unary_ping_pong.cc",
"test/cpp/microbenchmarks/callback_unary_ping_pong.h"
],
"third_party": false,
"type": "target"
},
{
"deps": [
"benchmark",
@ -6624,6 +6674,33 @@
"third_party": false,
"type": "lib"
},
{
"deps": [
"benchmark",
"gpr",
"grpc++_test_config",
"grpc++_test_util_unsecure",
"grpc++_unsecure",
"grpc_benchmark",
"grpc_test_util_unsecure",
"grpc_unsecure"
],
"headers": [
"src/proto/grpc/testing/echo.grpc.pb.h",
"src/proto/grpc/testing/echo.pb.h",
"src/proto/grpc/testing/echo_mock.grpc.pb.h",
"test/cpp/microbenchmarks/callback_test_service.h"
],
"is_filegroup": false,
"language": "c++",
"name": "bm_callback_test_service_impl",
"src": [
"test/cpp/microbenchmarks/callback_test_service.cc",
"test/cpp/microbenchmarks/callback_test_service.h"
],
"third_party": false,
"type": "lib"
},
{
"deps": [],
"headers": [

@ -3479,6 +3479,50 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": true,
"ci_platforms": [
"linux",
"mac",
"posix"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c++",
"name": "bm_callback_streaming_ping_pong",
"platforms": [
"linux",
"mac",
"posix"
],
"uses_polling": true
},
{
"args": [],
"benchmark": true,
"ci_platforms": [
"linux",
"mac",
"posix"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c++",
"name": "bm_callback_unary_ping_pong",
"platforms": [
"linux",
"mac",
"posix"
],
"uses_polling": true
},
{
"args": [],
"benchmark": true,

Loading…
Cancel
Save