[channel] Add CallFactory, CallDestination (#35766)
Closes #35766
COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/35766 from ctiller:chan3 ea9a3260e3
PiperOrigin-RevId: 603437058
pull/35787/head
parent
354cdecc12
commit
610f439342
21 changed files with 216 additions and 24 deletions
@ -0,0 +1,35 @@ |
||||
// Copyright 2024 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_SRC_CORE_LIB_TRANSPORT_CALL_DESTINATION_H |
||||
#define GRPC_SRC_CORE_LIB_TRANSPORT_CALL_DESTINATION_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/gprpp/orphanable.h" |
||||
#include "src/core/lib/transport/call_spine.h" |
||||
|
||||
namespace grpc_core { |
||||
|
||||
// CallDestination is responsible for the processing of a CallHandler.
|
||||
// It might be a transport, the server API, or a subchannel on the client (for
|
||||
// instance).
|
||||
class CallDestination : public Orphanable { |
||||
public: |
||||
virtual void StartCall(CallHandler call_handler) = 0; |
||||
}; |
||||
|
||||
} // namespace grpc_core
|
||||
|
||||
#endif // GRPC_SRC_CORE_LIB_TRANSPORT_CALL_DESTINATION_H
|
@ -0,0 +1,41 @@ |
||||
// Copyright 2024 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 <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/transport/call_factory.h" |
||||
|
||||
#include "src/core/lib/debug/stats.h" |
||||
#include "src/core/lib/resource_quota/resource_quota.h" |
||||
|
||||
namespace grpc_core { |
||||
|
||||
CallFactory::CallFactory(const ChannelArgs& args) |
||||
: call_size_estimator_(1024), |
||||
allocator_(args.GetObject<ResourceQuota>() |
||||
->memory_quota() |
||||
->CreateMemoryOwner()) {} |
||||
|
||||
Arena* CallFactory::CreateArena() { |
||||
const size_t initial_size = call_size_estimator_.CallSizeEstimate(); |
||||
global_stats().IncrementCallInitialSize(initial_size); |
||||
return Arena::Create(initial_size, &allocator_); |
||||
} |
||||
|
||||
void CallFactory::DestroyArena(Arena* arena) { |
||||
call_size_estimator_.UpdateCallSizeEstimate(arena->TotalUsedBytes()); |
||||
arena->Destroy(); |
||||
} |
||||
|
||||
} // namespace grpc_core
|
@ -0,0 +1,56 @@ |
||||
// Copyright 2024 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_SRC_CORE_LIB_TRANSPORT_CALL_FACTORY_H |
||||
#define GRPC_SRC_CORE_LIB_TRANSPORT_CALL_FACTORY_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/gprpp/ref_counted.h" |
||||
#include "src/core/lib/resource_quota/arena.h" |
||||
#include "src/core/lib/transport/call_size_estimator.h" |
||||
#include "src/core/lib/transport/call_spine.h" |
||||
|
||||
namespace grpc_core { |
||||
|
||||
// CallFactory creates calls.
|
||||
class CallFactory : public RefCounted<CallFactory> { |
||||
public: |
||||
explicit CallFactory(const ChannelArgs& args); |
||||
|
||||
// Create an arena for a call.
|
||||
// We do this as a separate step so that servers can create arenas without
|
||||
// creating the call into it - in the case that we have a HTTP/2 rapid reset
|
||||
// like attack this saves a lot of cpu time.
|
||||
Arena* CreateArena(); |
||||
// Destroy an arena created by CreateArena.
|
||||
// Updates the call size estimator so that we always create arenas of about
|
||||
// the right size.
|
||||
void DestroyArena(Arena* arena); |
||||
|
||||
// Create a call. The call will be created in the given arena.
|
||||
// It is the CallFactory's responsibility to ensure that the CallHandler
|
||||
// associated with the call is eventually handled by something (typically a
|
||||
// CallDestination, but this is not strictly required).
|
||||
virtual CallInitiator CreateCall(ClientMetadataHandle md, Arena* arena) = 0; |
||||
|
||||
private: |
||||
CallSizeEstimator call_size_estimator_; |
||||
MemoryAllocator allocator_; |
||||
}; |
||||
|
||||
} // namespace grpc_core
|
||||
|
||||
#endif // GRPC_SRC_CORE_LIB_TRANSPORT_CALL_FACTORY_H
|
Loading…
Reference in new issue