-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathprotocol_driver_allocator.cc
86 lines (77 loc) · 2.82 KB
/
protocol_driver_allocator.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2023 Google LLC
//
// 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
//
// https://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 "protocol_driver_allocator.h"
#include <functional>
#include <memory>
#include <string>
#include "absl/log/log.h"
#include "composable_rpc_counter.h"
#include "protocol_driver_double_barrel.h"
#include "protocol_driver_grpc.h"
#ifdef WITH_HOMA
#include "protocol_driver_homa.h"
#endif
#ifdef WITH_MERCURY
#include "protocol_driver_mercury.h"
#endif
namespace distbench {
int max_protocol_driver_tree_depth_ = 4;
std::function<absl::StatusOr<ProtocolDriverOptions>(const std::string&)>
alias_resolver_;
void SetProtocolDriverAliasResolver(
std::function<absl::StatusOr<ProtocolDriverOptions>(const std::string&)>
alias_resolver) {
alias_resolver_ = alias_resolver;
}
absl::StatusOr<std::unique_ptr<ProtocolDriver>> AllocateProtocolDriver(
ProtocolDriverOptions opts, int* port, int tree_depth) {
if (tree_depth == max_protocol_driver_tree_depth_) {
return absl::FailedPreconditionError(
absl::StrCat("Tree cannot be deeper than max depth of: ",
max_protocol_driver_tree_depth_, "."));
}
std::unique_ptr<ProtocolDriver> pd;
if (opts.protocol_name() == "grpc" ||
opts.protocol_name() == "grpc_async_callback") {
pd = std::make_unique<ProtocolDriverGrpc>();
} else if (opts.protocol_name() == "double_barrel") {
pd = std::make_unique<ProtocolDriverDoubleBarrel>(tree_depth);
} else if (opts.protocol_name() == "composable_rpc_counter") {
pd = std::make_unique<ComposableRpcCounter>(tree_depth);
#ifdef WITH_HOMA
} else if (opts.protocol_name() == "homa") {
pd = std::make_unique<ProtocolDriverHoma>();
#endif
#ifdef WITH_MERCURY
} else if (opts.protocol_name() == "mercury") {
pd = std::make_unique<ProtocolDriverMercury>();
#endif
} else {
if (alias_resolver_ == nullptr) {
return absl::InvalidArgumentError(
"Protocol driver alias resolver function is not set.");
}
auto maybe_resolved_opts = alias_resolver_(opts.protocol_name());
if (!maybe_resolved_opts.ok()) return maybe_resolved_opts.status();
opts = maybe_resolved_opts.value();
return AllocateProtocolDriver(opts, port, tree_depth + 1);
}
absl::Status ret = pd->Initialize(opts, port);
if (!ret.ok()) {
return ret;
} else {
return pd;
}
}
} // namespace distbench