Skip to content

Commit

Permalink
gRPC EventEngine Interface (grpc#25795)
Browse files Browse the repository at this point in the history
  • Loading branch information
drfloob authored Apr 5, 2021
1 parent a483e6c commit 4d4ee60
Show file tree
Hide file tree
Showing 30 changed files with 694 additions and 50 deletions.
10 changes: 9 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ GRPC_PUBLIC_HDRS = [
"include/grpc/support/workaround_list.h",
]

GRPC_PUBLIC_EVENT_ENGINE_HDRS = [
"include/grpc/event_engine/channel_args.h",
"include/grpc/event_engine/event_engine.h",
"include/grpc/event_engine/slice_allocator.h",
]

GRPC_SECURE_PUBLIC_HDRS = [
"include/grpc/grpc_security.h",
]
Expand Down Expand Up @@ -767,6 +773,8 @@ grpc_cc_library(
"src/core/lib/compression/stream_compression_identity.cc",
"src/core/lib/debug/stats.cc",
"src/core/lib/debug/stats_data.cc",
"src/core/lib/event_engine/slice_allocator.cc",
"src/core/lib/event_engine/sockaddr.cc",
"src/core/lib/http/format_request.cc",
"src/core/lib/http/httpcli.cc",
"src/core/lib/http/parser.cc",
Expand Down Expand Up @@ -1057,7 +1065,7 @@ grpc_cc_library(
"absl/container:flat_hash_map",
],
language = "c++",
public_hdrs = GRPC_PUBLIC_HDRS,
public_hdrs = GRPC_PUBLIC_HDRS + GRPC_PUBLIC_EVENT_ENGINE_HDRS,
deps = [
"dual_ref_counted",
"eventmanager_libuv",
Expand Down
5 changes: 5 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ config("grpc_config") {
"include/grpc/byte_buffer_reader.h",
"include/grpc/census.h",
"include/grpc/compression.h",
"include/grpc/event_engine/channel_args.h",
"include/grpc/event_engine/event_engine.h",
"include/grpc/event_engine/slice_allocator.h",
"include/grpc/fork.h",
"include/grpc/grpc.h",
"include/grpc/grpc_posix.h",
Expand Down Expand Up @@ -849,6 +852,8 @@ config("grpc_config") {
"src/core/lib/debug/stats_data.h",
"src/core/lib/debug/trace.cc",
"src/core/lib/debug/trace.h",
"src/core/lib/event_engine/slice_allocator.cc",
"src/core/lib/event_engine/sockaddr.cc",
"src/core/lib/gprpp/atomic.h",
"src/core/lib/gprpp/debug_location.h",
"src/core/lib/gprpp/dual_ref_counted.h",
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,8 @@ add_library(grpc
src/core/lib/debug/stats.cc
src/core/lib/debug/stats_data.cc
src/core/lib/debug/trace.cc
src/core/lib/event_engine/slice_allocator.cc
src/core/lib/event_engine/sockaddr.cc
src/core/lib/http/format_request.cc
src/core/lib/http/httpcli.cc
src/core/lib/http/httpcli_security_connector.cc
Expand Down Expand Up @@ -2082,6 +2084,9 @@ foreach(_hdr
include/grpc/byte_buffer_reader.h
include/grpc/census.h
include/grpc/compression.h
include/grpc/event_engine/channel_args.h
include/grpc/event_engine/event_engine.h
include/grpc/event_engine/slice_allocator.h
include/grpc/fork.h
include/grpc/grpc.h
include/grpc/grpc_posix.h
Expand Down Expand Up @@ -2430,6 +2435,8 @@ add_library(grpc_unsecure
src/core/lib/debug/stats.cc
src/core/lib/debug/stats_data.cc
src/core/lib/debug/trace.cc
src/core/lib/event_engine/slice_allocator.cc
src/core/lib/event_engine/sockaddr.cc
src/core/lib/http/format_request.cc
src/core/lib/http/httpcli.cc
src/core/lib/http/parser.cc
Expand Down Expand Up @@ -2629,6 +2636,9 @@ foreach(_hdr
include/grpc/byte_buffer_reader.h
include/grpc/census.h
include/grpc/compression.h
include/grpc/event_engine/channel_args.h
include/grpc/event_engine/event_engine.h
include/grpc/event_engine/slice_allocator.h
include/grpc/fork.h
include/grpc/grpc.h
include/grpc/grpc_posix.h
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,8 @@ LIBGRPC_SRC = \
src/core/lib/debug/stats.cc \
src/core/lib/debug/stats_data.cc \
src/core/lib/debug/trace.cc \
src/core/lib/event_engine/slice_allocator.cc \
src/core/lib/event_engine/sockaddr.cc \
src/core/lib/http/format_request.cc \
src/core/lib/http/httpcli.cc \
src/core/lib/http/httpcli_security_connector.cc \
Expand Down Expand Up @@ -1595,6 +1597,9 @@ PUBLIC_HEADERS_C += \
include/grpc/byte_buffer_reader.h \
include/grpc/census.h \
include/grpc/compression.h \
include/grpc/event_engine/channel_args.h \
include/grpc/event_engine/event_engine.h \
include/grpc/event_engine/slice_allocator.h \
include/grpc/fork.h \
include/grpc/grpc.h \
include/grpc/grpc_posix.h \
Expand Down Expand Up @@ -1842,6 +1847,8 @@ LIBGRPC_UNSECURE_SRC = \
src/core/lib/debug/stats.cc \
src/core/lib/debug/stats_data.cc \
src/core/lib/debug/trace.cc \
src/core/lib/event_engine/slice_allocator.cc \
src/core/lib/event_engine/sockaddr.cc \
src/core/lib/http/format_request.cc \
src/core/lib/http/httpcli.cc \
src/core/lib/http/parser.cc \
Expand Down Expand Up @@ -1992,6 +1999,9 @@ PUBLIC_HEADERS_C += \
include/grpc/byte_buffer_reader.h \
include/grpc/census.h \
include/grpc/compression.h \
include/grpc/event_engine/channel_args.h \
include/grpc/event_engine/event_engine.h \
include/grpc/event_engine/slice_allocator.h \
include/grpc/fork.h \
include/grpc/grpc.h \
include/grpc/grpc_posix.h \
Expand Down
10 changes: 10 additions & 0 deletions build_autogenerated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ libs:
- include/grpc/byte_buffer_reader.h
- include/grpc/census.h
- include/grpc/compression.h
- include/grpc/event_engine/channel_args.h
- include/grpc/event_engine/event_engine.h
- include/grpc/event_engine/slice_allocator.h
- include/grpc/fork.h
- include/grpc/grpc.h
- include/grpc/grpc_posix.h
Expand Down Expand Up @@ -1214,6 +1217,8 @@ libs:
- src/core/lib/debug/stats.cc
- src/core/lib/debug/stats_data.cc
- src/core/lib/debug/trace.cc
- src/core/lib/event_engine/slice_allocator.cc
- src/core/lib/event_engine/sockaddr.cc
- src/core/lib/http/format_request.cc
- src/core/lib/http/httpcli.cc
- src/core/lib/http/httpcli_security_connector.cc
Expand Down Expand Up @@ -1575,6 +1580,9 @@ libs:
- include/grpc/byte_buffer_reader.h
- include/grpc/census.h
- include/grpc/compression.h
- include/grpc/event_engine/channel_args.h
- include/grpc/event_engine/event_engine.h
- include/grpc/event_engine/slice_allocator.h
- include/grpc/fork.h
- include/grpc/grpc.h
- include/grpc/grpc_posix.h
Expand Down Expand Up @@ -1968,6 +1976,8 @@ libs:
- src/core/lib/debug/stats.cc
- src/core/lib/debug/stats_data.cc
- src/core/lib/debug/trace.cc
- src/core/lib/event_engine/slice_allocator.cc
- src/core/lib/event_engine/sockaddr.cc
- src/core/lib/http/format_request.cc
- src/core/lib/http/httpcli.cc
- src/core/lib/http/parser.cc
Expand Down
3 changes: 3 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/debug/stats.cc \
src/core/lib/debug/stats_data.cc \
src/core/lib/debug/trace.cc \
src/core/lib/event_engine/slice_allocator.cc \
src/core/lib/event_engine/sockaddr.cc \
src/core/lib/gpr/alloc.cc \
src/core/lib/gpr/atm.cc \
src/core/lib/gpr/cpu_iphone.cc \
Expand Down Expand Up @@ -1158,6 +1160,7 @@ if test "$PHP_GRPC" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/channel)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/compression)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/debug)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/event_engine)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gpr)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gprpp)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/http)
Expand Down
3 changes: 3 additions & 0 deletions config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\debug\\stats.cc " +
"src\\core\\lib\\debug\\stats_data.cc " +
"src\\core\\lib\\debug\\trace.cc " +
"src\\core\\lib\\event_engine\\slice_allocator.cc " +
"src\\core\\lib\\event_engine\\sockaddr.cc " +
"src\\core\\lib\\gpr\\alloc.cc " +
"src\\core\\lib\\gpr\\atm.cc " +
"src\\core\\lib\\gpr\\cpu_iphone.cc " +
Expand Down Expand Up @@ -1258,6 +1260,7 @@ if (PHP_GRPC != "no") {
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\channel");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\compression");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\debug");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\event_engine");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gpr");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gprpp");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\http");
Expand Down
5 changes: 5 additions & 0 deletions grpc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ Gem::Specification.new do |s|
s.files += %w( include/grpc/byte_buffer_reader.h )
s.files += %w( include/grpc/census.h )
s.files += %w( include/grpc/compression.h )
s.files += %w( include/grpc/event_engine/channel_args.h )
s.files += %w( include/grpc/event_engine/event_engine.h )
s.files += %w( include/grpc/event_engine/slice_allocator.h )
s.files += %w( include/grpc/fork.h )
s.files += %w( include/grpc/grpc.h )
s.files += %w( include/grpc/grpc_posix.h )
Expand Down Expand Up @@ -748,6 +751,8 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/debug/stats_data.h )
s.files += %w( src/core/lib/debug/trace.cc )
s.files += %w( src/core/lib/debug/trace.h )
s.files += %w( src/core/lib/event_engine/slice_allocator.cc )
s.files += %w( src/core/lib/event_engine/sockaddr.cc )
s.files += %w( src/core/lib/gpr/alloc.cc )
s.files += %w( src/core/lib/gpr/alloc.h )
s.files += %w( src/core/lib/gpr/arena.h )
Expand Down
4 changes: 4 additions & 0 deletions grpc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@
'src/core/lib/debug/stats.cc',
'src/core/lib/debug/stats_data.cc',
'src/core/lib/debug/trace.cc',
'src/core/lib/event_engine/slice_allocator.cc',
'src/core/lib/event_engine/sockaddr.cc',
'src/core/lib/http/format_request.cc',
'src/core/lib/http/httpcli.cc',
'src/core/lib/http/httpcli_security_connector.cc',
Expand Down Expand Up @@ -1234,6 +1236,8 @@
'src/core/lib/debug/stats.cc',
'src/core/lib/debug/stats_data.cc',
'src/core/lib/debug/trace.cc',
'src/core/lib/event_engine/slice_allocator.cc',
'src/core/lib/event_engine/sockaddr.cc',
'src/core/lib/http/format_request.cc',
'src/core/lib/http/httpcli.cc',
'src/core/lib/http/parser.cc',
Expand Down
38 changes: 38 additions & 0 deletions include/grpc/event_engine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# gRPC EventEngine

An EventEngine handles all cross-platform I/O, task execution, and DNS
resolution for gRPC. A default, cross-platform implementation is provided with
gRPC, but part of the intent here is to provide an interface for external
integrators to bring their own functionality. This allows for integration with
external event loops, siloing I/O and task execution between channels or
servers, and other custom integrations that were previously unsupported.

*WARNING*: This is experimental code and is subject to change.

## High level expectations of an EventEngine implementation

### Provide their own I/O threads
EventEngines are expected to internally create whatever threads are required to
perform I/O and execute callbacks. For example, an EventEngine implementation
may want to spawn separate thread pools for polling and callback execution.

### Provisioning data buffers via Slice allocation
At a high level, gRPC provides a `ResourceQuota` system that allows gRPC to
reclaim memory and degrade gracefully when memory reaches application-defined
thresholds. To enable this feature, the memory allocation of read/write buffers
within an EventEngine must be acquired in the form of Slices from
SliceAllocators. This is covered more fully in the gRFC and code.

### Documentating expectations around callback execution
Some callbacks may be expensive to run. EventEngines should decide on and
document whether callback execution might block polling operations. This way,
application developers can plan accordingly (e.g., run their expensive callbacks
on a separate thread if necessary).

### Handling concurrent usage
Assume that gRPC may use an EventEngine concurrently across multiple threads.

## TODO: documentation

* Example usage
* Link to gRFC
28 changes: 28 additions & 0 deletions include/grpc/event_engine/channel_args.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2021 The 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 GRPC_EVENT_ENGINE_CHANNEL_ARGS_H
#define GRPC_EVENT_ENGINE_CHANNEL_ARGS_H

#include <grpc/support/port_platform.h>

namespace grpc_event_engine {
namespace experimental {

// TODO(hork): define
class ChannelArgs;

} // namespace experimental
} // namespace grpc_event_engine

#endif // GRPC_EVENT_ENGINE_CHANNEL_ARGS_H
Loading

0 comments on commit 4d4ee60

Please sign in to comment.