Skip to content

Commit

Permalink
[core] Use single asio context along the IO path (ray-project#49172)
Browse files Browse the repository at this point in the history
Signed-off-by: hjiang <dentinyhao@gmail.com>
  • Loading branch information
dentiny authored and simonsays1980 committed Dec 12, 2024
1 parent 4783f33 commit 03c6b36
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/ray/gcs/redis_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ RedisRequestContext::RedisRequestContext(instrumented_io_context &io_service,
callback_(std::move(callback)),
start_time_(absl::Now()),
redis_cmds_(std::move(args)) {
argc_.reserve(redis_cmds_.size());
argv_.reserve(redis_cmds_.size());
for (size_t i = 0; i < redis_cmds_.size(); ++i) {
argv_.push_back(redis_cmds_[i].data());
argc_.push_back(redis_cmds_[i].size());
Expand Down Expand Up @@ -560,10 +562,11 @@ Status ConnectRedisSentinel(RedisContext &context,
}
}

std::vector<std::string> ResolveDNS(const std::string &address, int port) {
std::vector<std::string> ResolveDNS(instrumented_io_context &io_service,
const std::string &address,
int port) {
using namespace boost::asio;
io_context ctx;
ip::tcp::resolver resolver(ctx);
ip::tcp::resolver resolver(io_service);
ip::tcp::resolver::iterator iter = resolver.resolve(address, std::to_string(port));
ip::tcp::resolver::iterator end;
std::vector<std::string> ip_addresses;
Expand Down Expand Up @@ -597,7 +600,7 @@ Status RedisContext::Connect(const std::string &address,
RAY_CHECK(!redis_async_context_);
// Fetch the ip address from the address. It might return multiple
// addresses and only the first one will be used.
auto ip_addresses = ResolveDNS(address, port);
auto ip_addresses = ResolveDNS(io_service_, address, port);
RAY_CHECK(!ip_addresses.empty())
<< "Failed to resolve DNS for " << address << ":" << port;

Expand Down

0 comments on commit 03c6b36

Please sign in to comment.