diff --git a/BUILD.bazel b/BUILD.bazel index efcc9378a..aa144adc0 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -71,8 +71,8 @@ cc_binary( ) cc_binary( - name = "coro_http_channel", - srcs = ["src/coro_http/examples/channel.cpp"], + name = "coro_http_load_blancer", + srcs = ["src/coro_http/examples/load_blancer.cpp"], copts = YA_BIN_COPT, includes = [ "include", diff --git a/include/ylt/coro_io/client_pool.hpp b/include/ylt/coro_io/client_pool.hpp index f93bfd2c0..43f536eb3 100644 --- a/include/ylt/coro_io/client_pool.hpp +++ b/include/ylt/coro_io/client_pool.hpp @@ -55,7 +55,7 @@ template class client_pools; template -class channel; +class load_blancer; template @@ -405,7 +405,7 @@ class client_pool : public std::enable_shared_from_this< friend class client_pools; template - friend class channel; + friend class load_blancer; template async_simple::coro::Lazy> send_request( diff --git a/include/ylt/coro_io/coro_io.hpp b/include/ylt/coro_io/coro_io.hpp index f22b91445..2f4b7900c 100644 --- a/include/ylt/coro_io/coro_io.hpp +++ b/include/ylt/coro_io/coro_io.hpp @@ -364,12 +364,11 @@ post(Func func, } template -struct coro_channel - : public asio::experimental::channel { +struct channel : public asio::experimental::channel { using return_type = R; using ValueType = std::pair; using asio::experimental::channel::channel; - coro_channel(coro_io::ExecutorWrapper<> *executor, size_t capacity) + channel(coro_io::ExecutorWrapper<> *executor, size_t capacity) : executor_(executor), asio::experimental::channel( executor->get_asio_executor(), capacity) {} @@ -380,17 +379,17 @@ struct coro_channel }; template -inline coro_channel create_channel( +inline channel create_load_blancer( size_t capacity, coro_io::ExecutorWrapper<> *executor = coro_io::get_global_executor()) { - return coro_channel(executor, capacity); + return channel(executor, capacity); } template inline auto create_shared_channel( size_t capacity, coro_io::ExecutorWrapper<> *executor = coro_io::get_global_executor()) { - return std::make_shared>(executor, capacity); + return std::make_shared>(executor, capacity); } template diff --git a/include/ylt/coro_io/channel.hpp b/include/ylt/coro_io/load_blancer.hpp similarity index 81% rename from include/ylt/coro_io/channel.hpp rename to include/ylt/coro_io/load_blancer.hpp index e78f7da9d..33ba699cb 100644 --- a/include/ylt/coro_io/channel.hpp +++ b/include/ylt/coro_io/load_blancer.hpp @@ -25,22 +25,22 @@ #include "io_context_pool.hpp" namespace coro_io { -enum class load_blance_algorithm { +enum class load_blancer_algorithm { RR = 0, // round-robin WRR, // weight round-robin random, }; template -class channel { +class load_blancer { using client_pool_t = client_pool; using client_pools_t = client_pools; public: - struct channel_config { + struct load_blancer_config { typename client_pool_t::pool_config pool_config; - load_blance_algorithm lba = load_blance_algorithm::RR; - ~channel_config(){}; + load_blancer_algorithm lba = load_blancer_algorithm::RR; + ~load_blancer_config(){}; }; private: @@ -48,9 +48,10 @@ class channel { std::unique_ptr> index = std::make_unique>(); async_simple::coro::Lazy> operator()( - const channel& channel) { + const load_blancer& load_blancer) { auto i = index->fetch_add(1, std::memory_order_relaxed); - co_return channel.client_pools_[i % channel.client_pools_.size()]; + co_return load_blancer + .client_pools_[i % load_blancer.client_pools_.size()]; } }; @@ -84,14 +85,15 @@ class channel { } async_simple::coro::Lazy> operator()( - const channel& channel) { + const load_blancer& load_blancer) { int selected = select_host_with_weight_round_robin(); if (selected == -1) { selected = 0; } wrr_current_ = selected; - co_return channel.client_pools_[selected % channel.client_pools_.size()]; + co_return load_blancer + .client_pools_[selected % load_blancer.client_pools_.size()]; } private: @@ -138,27 +140,27 @@ class channel { struct RandomLoadBlancer { async_simple::coro::Lazy> operator()( - const channel& channel) { + const load_blancer& load_blancer) { static thread_local std::default_random_engine e(std::time(nullptr)); std::uniform_int_distribution rnd{std::size_t{0}, - channel.client_pools_.size() - 1}; - co_return channel.client_pools_[rnd(e)]; + load_blancer.client_pools_.size() - 1}; + co_return load_blancer.client_pools_[rnd(e)]; } }; - channel() = default; + load_blancer() = default; public: - channel(channel&& o) + load_blancer(load_blancer&& o) : config_(std::move(o.config_)), lb_worker(std::move(o.lb_worker)), client_pools_(std::move(o.client_pools_)){}; - channel& operator=(channel&& o) { + load_blancer& operator=(load_blancer&& o) { this->config_ = std::move(o.config_); this->lb_worker = std::move(o.lb_worker); this->client_pools_ = std::move(o.client_pools_); } - channel(const channel& o) = delete; - channel& operator=(const channel& o) = delete; + load_blancer(const load_blancer& o) = delete; + load_blancer& operator=(const load_blancer& o) = delete; auto send_request(auto op, typename client_t::config& config) -> decltype(std::declval().send_request(std::move(op), @@ -185,18 +187,19 @@ class channel { return send_request(std::move(op), config_.pool_config.client_config); } - static channel create(const std::vector& hosts, - const channel_config& config = {}, - const std::vector& weights = {}, - client_pools_t& client_pools = - g_clients_pool()) { - channel ch; + static load_blancer create( + const std::vector& hosts, + const load_blancer_config& config = {}, + const std::vector& weights = {}, + client_pools_t& client_pools = + g_clients_pool()) { + load_blancer ch; ch.init(hosts, config, weights, client_pools); return ch; } /** - * @brief return the channel's hosts size. + * @brief return the load_blancer's hosts size. * * @return std::size_t */ @@ -204,7 +207,7 @@ class channel { private: void init(const std::vector& hosts, - const channel_config& config, const std::vector& weights, + const load_blancer_config& config, const std::vector& weights, client_pools_t& client_pools) { config_ = config; client_pools_.reserve(hosts.size()); @@ -212,10 +215,10 @@ class channel { client_pools_.emplace_back(client_pools.at(host, config.pool_config)); } switch (config_.lba) { - case load_blance_algorithm::RR: + case load_blancer_algorithm::RR: lb_worker = RRLoadBlancer{}; break; - case load_blance_algorithm::WRR: { + case load_blancer_algorithm::WRR: { if (hosts.empty() || weights.empty()) { throw std::invalid_argument("host/weight list is empty!"); } @@ -224,13 +227,13 @@ class channel { } lb_worker = WRRLoadBlancer(weights); } break; - case load_blance_algorithm::random: + case load_blancer_algorithm::random: default: lb_worker = RandomLoadBlancer{}; } return; } - channel_config config_; + load_blancer_config config_; std::variant lb_worker; std::vector> client_pools_; }; diff --git a/include/ylt/standalone/cinatra/coro_http_server.hpp b/include/ylt/standalone/cinatra/coro_http_server.hpp index 95b846124..90294029f 100644 --- a/include/ylt/standalone/cinatra/coro_http_server.hpp +++ b/include/ylt/standalone/cinatra/coro_http_server.hpp @@ -7,10 +7,10 @@ #include "cinatra/mime_types.hpp" #include "cinatra_log_wrapper.hpp" #include "coro_http_connection.hpp" -#include "ylt/coro_io/channel.hpp" #include "ylt/coro_io/coro_file.hpp" #include "ylt/coro_io/coro_io.hpp" #include "ylt/coro_io/io_context_pool.hpp" +#include "ylt/coro_io/load_blancer.hpp" #include "ylt/metric/system_metric.hpp" namespace cinatra { @@ -208,22 +208,23 @@ class coro_http_server { template void set_http_proxy_handler(std::string url_path, std::vector hosts, - coro_io::load_blance_algorithm type = - coro_io::load_blance_algorithm::random, + coro_io::load_blancer_algorithm type = + coro_io::load_blancer_algorithm::random, std::vector weights = {}, Aspects &&...aspects) { if (hosts.empty()) { throw std::invalid_argument("not config hosts yet!"); } - auto channel = std::make_shared>( - coro_io::channel::create(hosts, {.lba = type}, - weights)); + auto load_blancer = + std::make_shared>( + coro_io::load_blancer::create( + hosts, {.lba = type}, weights)); auto handler = - [this, channel, type]( + [this, load_blancer, type]( coro_http_request &req, coro_http_response &response) -> async_simple::coro::Lazy { - co_await channel->send_request( + co_await load_blancer->send_request( [this, &req, &response]( coro_http_client &client, std::string_view host) -> async_simple::coro::Lazy { @@ -247,22 +248,23 @@ class coro_http_server { template void set_websocket_proxy_handler(std::string url_path, std::vector hosts, - coro_io::load_blance_algorithm type = - coro_io::load_blance_algorithm::random, + coro_io::load_blancer_algorithm type = + coro_io::load_blancer_algorithm::random, std::vector weights = {}, Aspects &&...aspects) { if (hosts.empty()) { throw std::invalid_argument("not config hosts yet!"); } - auto channel = std::make_shared>( - coro_io::channel::create(hosts, {.lba = type}, - weights)); + auto load_blancer = + std::make_shared>( + coro_io::load_blancer::create( + hosts, {.lba = type}, weights)); set_http_handler( url_path, - [channel](coro_http_request &req, - coro_http_response &resp) -> async_simple::coro::Lazy { + [load_blancer](coro_http_request &req, coro_http_response &resp) + -> async_simple::coro::Lazy { websocket_result result{}; while (true) { result = co_await req.get_conn()->read_websocket(); @@ -275,7 +277,7 @@ class coro_http_server { break; } - co_await channel->send_request( + co_await load_blancer->send_request( [&req, result]( coro_http_client &client, std::string_view host) -> async_simple::coro::Lazy { diff --git a/src/coro_http/examples/CMakeLists.txt b/src/coro_http/examples/CMakeLists.txt index 81029f1f2..0c7272c31 100644 --- a/src/coro_http/examples/CMakeLists.txt +++ b/src/coro_http/examples/CMakeLists.txt @@ -28,11 +28,11 @@ else() endif() add_executable(coro_http_example example.cpp) -add_executable(coro_http_channel channel.cpp) +add_executable(coro_http_load_blancer load_blancer.cpp) add_executable(coro_chat_room chat_room.cpp) if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows") # mingw-w64 target_link_libraries(coro_http_example wsock32 ws2_32) - target_link_libraries(coro_http_channel wsock32 ws2_32) + target_link_libraries(coro_http_load_blancer wsock32 ws2_32) target_link_libraries(coro_chat_room wsock32 ws2_32) endif() \ No newline at end of file diff --git a/src/coro_http/examples/example.cpp b/src/coro_http/examples/example.cpp index 4ec41cbdf..1888c7701 100644 --- a/src/coro_http/examples/example.cpp +++ b/src/coro_http/examples/example.cpp @@ -17,6 +17,7 @@ #include "ylt/coro_http/coro_http_client.hpp" #include "ylt/coro_http/coro_http_server.hpp" +#include "ylt/coro_io/coro_io.hpp" using namespace std::chrono_literals; using namespace coro_http; @@ -569,12 +570,12 @@ void http_proxy() { coro_http_server proxy_wrr(2, 8090); proxy_wrr.set_http_proxy_handler( "/", {"127.0.0.1:9001", "127.0.0.1:9002", "127.0.0.1:9003"}, - coro_io::load_blance_algorithm::WRR, {10, 5, 5}); + coro_io::load_blancer_algorithm::WRR, {10, 5, 5}); coro_http_server proxy_rr(2, 8091); proxy_rr.set_http_proxy_handler( "/", {"127.0.0.1:9001", "127.0.0.1:9002", "127.0.0.1:9003"}, - coro_io::load_blance_algorithm::RR); + coro_io::load_blancer_algorithm::RR); coro_http_server proxy_random(2, 8092); proxy_random.set_http_proxy_handler( @@ -628,8 +629,8 @@ void http_proxy() { assert(!resp_random.resp_body.empty()); } -void coro_channel() { - auto ch = coro_io::create_channel(10000); +void coro_load_blancer() { + auto ch = coro_io::create_load_blancer(10000); auto ec = async_simple::coro::syncAwait(coro_io::async_send(ch, 41)); assert(!ec); ec = async_simple::coro::syncAwait(coro_io::async_send(ch, 42)); @@ -660,6 +661,6 @@ int main() { test_gzip(); #endif http_proxy(); - coro_channel(); + coro_load_blancer(); return 0; } \ No newline at end of file diff --git a/src/coro_http/examples/channel.cpp b/src/coro_http/examples/load_blancer.cpp similarity index 86% rename from src/coro_http/examples/channel.cpp rename to src/coro_http/examples/load_blancer.cpp index 8a79a6e37..7be401c6f 100644 --- a/src/coro_http/examples/channel.cpp +++ b/src/coro_http/examples/load_blancer.cpp @@ -20,9 +20,9 @@ #include #include #include -#include #include #include +#include #include using namespace async_simple::coro; @@ -30,7 +30,8 @@ using namespace coro_http; using namespace std::chrono_literals; using namespace coro_io; std::atomic qps, working_echo; -Lazy test_async_channel(coro_io::channel &chan) { +Lazy test_async_load_blancer( + coro_io::load_blancer &chan) { ++working_echo; for (int i = 0; i < 100; ++i) { auto result = co_await chan.send_request( @@ -65,12 +66,11 @@ Lazy qps_watcher() { int main() { std::vector hosts{"http://baidu.com", "http://www.baidu.com"}; - auto chan = coro_io::channel::create( - hosts, coro_io::channel::channel_config{ - .pool_config{.max_connection = 100}}); + auto chan = coro_io::load_blancer::create( + hosts, {.pool_config{.max_connection = 100}}); for (int i = 0, lim = std::thread::hardware_concurrency(); i < lim; ++i) - test_async_channel(chan).start([](auto &&) { + test_async_load_blancer(chan).start([](auto &&) { }); syncAwait(qps_watcher()); std::cout << "OK" << std::endl; diff --git a/src/coro_io/tests/test_channel.cpp b/src/coro_io/tests/test_channel.cpp index 8561ea509..8f04eb59b 100644 --- a/src/coro_io/tests/test_channel.cpp +++ b/src/coro_io/tests/test_channel.cpp @@ -11,10 +11,10 @@ #include #include #include -#include #include #include #include +#include #include "async_simple/coro/Lazy.h" #include "ylt/coro_io/client_pool.hpp" @@ -28,9 +28,10 @@ TEST_CASE("test RR") { REQUIRE_MESSAGE(!res.hasResult(), "server start failed"); auto hosts = std::vector{"127.0.0.1:8801", "localhost:8801"}; - auto channel = coro_io::channel::create(hosts); + auto load_blancer = + coro_io::load_blancer::create(hosts); for (int i = 0; i < 100; ++i) { - auto res = co_await channel.send_request( + auto res = co_await load_blancer.send_request( [&i, &hosts]( coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { @@ -47,18 +48,18 @@ TEST_CASE("test WRR") { SUBCASE( "exception tests: empty hosts, empty weights test or count not equal") { CHECK_THROWS_AS( - coro_io::channel::create( - {}, {.lba = coro_io::load_blance_algorithm::WRR}, {2, 1}), + coro_io::load_blancer::create( + {}, {.lba = coro_io::load_blancer_algorithm::WRR}, {2, 1}), std::invalid_argument); - CHECK_THROWS_AS(coro_io::channel::create( + CHECK_THROWS_AS(coro_io::load_blancer::create( {"127.0.0.1:8801", "127.0.0.1:8802"}, - {.lba = coro_io::load_blance_algorithm::WRR}), + {.lba = coro_io::load_blancer_algorithm::WRR}), std::invalid_argument); - CHECK_THROWS_AS(coro_io::channel::create( + CHECK_THROWS_AS(coro_io::load_blancer::create( {"127.0.0.1:8801", "127.0.0.1:8802"}, - {.lba = coro_io::load_blance_algorithm::WRR}, {1}), + {.lba = coro_io::load_blancer_algorithm::WRR}, {1}), std::invalid_argument); } @@ -72,10 +73,11 @@ TEST_CASE("test WRR") { async_simple::coro::syncAwait([]() -> async_simple::coro::Lazy { auto hosts = std::vector{"127.0.0.1:8801", "127.0.0.1:8802"}; - auto channel = coro_io::channel::create( - hosts, {.lba = coro_io::load_blance_algorithm::WRR}, {2, 1}); + auto load_blancer = + coro_io::load_blancer::create( + hosts, {.lba = coro_io::load_blancer_algorithm::WRR}, {2, 1}); for (int i = 0; i < 6; ++i) { - auto res = co_await channel.send_request( + auto res = co_await load_blancer.send_request( [&i, &hosts]( coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { @@ -97,10 +99,11 @@ TEST_CASE("test WRR") { async_simple::coro::syncAwait([]() -> async_simple::coro::Lazy { auto hosts = std::vector{"127.0.0.1:8801", "127.0.0.1:8802"}; - auto channel = coro_io::channel::create( - hosts, {.lba = coro_io::load_blance_algorithm::WRR}, {0, 0}); + auto load_blancer = + coro_io::load_blancer::create( + hosts, {.lba = coro_io::load_blancer_algorithm::WRR}, {0, 0}); for (int i = 0; i < 6; ++i) { - auto res = co_await channel.send_request( + auto res = co_await load_blancer.send_request( [&i, &hosts]( coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { @@ -124,11 +127,12 @@ TEST_CASE("test Random") { REQUIRE_MESSAGE(!res.hasResult(), "server start failed"); auto hosts = std::vector{"127.0.0.1:8801", "localhost:8801"}; - auto channel = coro_io::channel::create( - hosts, {.lba = coro_io::load_blance_algorithm::random}); + auto load_blancer = + coro_io::load_blancer::create( + hosts, {.lba = coro_io::load_blancer_algorithm::random}); int host0_cnt = 0, hostRR_cnt = 0; for (int i = 0; i < 100; ++i) { - auto res = co_await channel.send_request( + auto res = co_await load_blancer.send_request( [&i, &hosts, &host0_cnt, &hostRR_cnt]( coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { @@ -152,9 +156,10 @@ TEST_CASE("test single host") { auto res = server.async_start(); REQUIRE_MESSAGE(!res.hasResult(), "server start failed"); auto hosts = std::vector{"127.0.0.1:8801"}; - auto channel = coro_io::channel::create(hosts); + auto load_blancer = + coro_io::load_blancer::create(hosts); for (int i = 0; i < 100; ++i) { - auto res = co_await channel.send_request( + auto res = co_await load_blancer.send_request( [&hosts](coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { CHECK(host == hosts[0]); @@ -172,10 +177,11 @@ TEST_CASE("test send_request config") { auto res = server.async_start(); REQUIRE_MESSAGE(!res.hasResult(), "server start failed"); auto hosts = std::vector{"127.0.0.1:9813"}; - auto channel = coro_io::channel::create(hosts); + auto load_blancer = + coro_io::load_blancer::create(hosts); for (int i = 0; i < 100; ++i) { auto config = coro_rpc::coro_rpc_client::config{.client_id = 114514}; - auto res = co_await channel.send_request( + auto res = co_await load_blancer.send_request( [&i, &hosts](coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { CHECK(client.get_client_id() == 114514); @@ -206,11 +212,12 @@ TEST_CASE("test server down") { .connect_retry_count = 0, .reconnect_wait_time = std::chrono::milliseconds{0}, .host_alive_detect_duration = std::chrono::milliseconds{500}}; - auto channel = - coro_io::channel::create(hosts, {config}); + auto load_blancer = + coro_io::load_blancer::create(hosts, + {config}); for (int i = 0; i < 100; ++i) { - auto res = co_await channel.send_request( + auto res = co_await load_blancer.send_request( [&i, &hosts]( coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { @@ -221,7 +228,7 @@ TEST_CASE("test server down") { } server1.stop(); for (int i = 0; i < 100; ++i) { - auto res = co_await channel.send_request( + auto res = co_await load_blancer.send_request( [&i, &hosts]( coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { @@ -236,13 +243,13 @@ TEST_CASE("test server down") { server2.stop(); { { - auto res = co_await channel.send_request( + auto res = co_await load_blancer.send_request( [](coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { co_await client.call(); co_return; }); - res = co_await channel.send_request( + res = co_await load_blancer.send_request( [](coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { co_await client.call(); @@ -259,7 +266,7 @@ TEST_CASE("test server down") { co_await coro_io::sleep_for(std::chrono::seconds{1}); { for (int i = 0; i < 100; ++i) { - auto res = co_await channel.send_request( + auto res = co_await load_blancer.send_request( [&i, &hosts]( coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { @@ -277,7 +284,7 @@ TEST_CASE("test server down") { { int counter = 0; for (int i = 0; i < 100; ++i) { - auto res = co_await channel.send_request( + auto res = co_await load_blancer.send_request( [&i, &hosts, &counter]( coro_rpc::coro_rpc_client &client, std::string_view host) -> async_simple::coro::Lazy { diff --git a/src/coro_io/tests/test_client_pool.cpp b/src/coro_io/tests/test_client_pool.cpp index a2878a5da..5c85b1a73 100644 --- a/src/coro_io/tests/test_client_pool.cpp +++ b/src/coro_io/tests/test_client_pool.cpp @@ -15,10 +15,10 @@ #include #include #include -#include #include #include #include +#include #include "async_simple/Executor.h" #include "async_simple/Promise.h" diff --git a/src/coro_io/tests/test_coro_channel.cpp b/src/coro_io/tests/test_coro_channel.cpp index 384ce62ee..fa5135dce 100644 --- a/src/coro_io/tests/test_coro_channel.cpp +++ b/src/coro_io/tests/test_coro_channel.cpp @@ -19,8 +19,8 @@ using namespace std::chrono_literals; #define IS_OK #endif -async_simple::coro::Lazy test_coro_channel() { - auto ch = coro_io::create_channel(1000); +async_simple::coro::Lazy test_channel() { + auto ch = coro_io::create_load_blancer(1000); co_await coro_io::async_send(ch, 41); co_await coro_io::async_send(ch, 42); @@ -37,8 +37,8 @@ async_simple::coro::Lazy test_coro_channel() { async_simple::coro::Lazy test_select_channel() { using namespace coro_io; using namespace async_simple::coro; - auto ch1 = coro_io::create_channel(1000); - auto ch2 = coro_io::create_channel(1000); + auto ch1 = coro_io::create_load_blancer(1000); + auto ch2 = coro_io::create_load_blancer(1000); co_await async_send(ch1, 41); co_await async_send(ch2, 42); @@ -162,7 +162,7 @@ void callback_lazy() { } TEST_CASE("test channel send recieve, test select channel and coroutine") { - async_simple::coro::syncAwait(test_coro_channel()); + async_simple::coro::syncAwait(test_channel()); async_simple::coro::syncAwait(test_select_channel()); callback_lazy(); } \ No newline at end of file diff --git a/src/coro_rpc/examples/base_examples/CMakeLists.txt b/src/coro_rpc/examples/base_examples/CMakeLists.txt index 1265fd7ca..88e861f7d 100644 --- a/src/coro_rpc/examples/base_examples/CMakeLists.txt +++ b/src/coro_rpc/examples/base_examples/CMakeLists.txt @@ -36,7 +36,7 @@ else() endif() endif() -add_executable(coro_rpc_example_channel channel.cpp) +add_executable(coro_rpc_example_load_blancer load_blancer.cpp) add_executable(coro_rpc_example_client_pool client_pool.cpp) add_executable(coro_rpc_example_client_pools client_pools.cpp) add_executable(coro_rpc_example_client client.cpp) @@ -44,7 +44,7 @@ add_executable(coro_rpc_example_concurrent_clients concurrent_clients.cpp) add_executable(coro_rpc_example_server server.cpp rpc_service.cpp) if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows") # mingw-w64 - target_link_libraries(coro_rpc_example_channel wsock32 ws2_32) + target_link_libraries(coro_rpc_example_load_blancer wsock32 ws2_32) target_link_libraries(coro_rpc_example_client_pool wsock32 ws2_32) target_link_libraries(coro_rpc_example_client_pools wsock32 ws2_32) target_link_libraries(coro_rpc_example_client wsock32 ws2_32) diff --git a/src/coro_rpc/examples/base_examples/channel.cpp b/src/coro_rpc/examples/base_examples/load_blancer.cpp similarity index 92% rename from src/coro_rpc/examples/base_examples/channel.cpp rename to src/coro_rpc/examples/base_examples/load_blancer.cpp index 411de6ce4..f91330004 100644 --- a/src/coro_rpc/examples/base_examples/channel.cpp +++ b/src/coro_rpc/examples/base_examples/load_blancer.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "ylt/coro_io/channel.hpp" +#include "ylt/coro_io/load_blancer.hpp" #include #include @@ -48,13 +48,13 @@ std::atomic working_echo = 0; int request_cnt = 10000; Lazy> call_echo( - std::shared_ptr> channel) { + std::shared_ptr> load_blancer) { std::vector result; result.reserve(request_cnt); auto tp = std::chrono::steady_clock::now(); ++working_echo; for (int i = 0; i < request_cnt; ++i) { - auto res = co_await channel->send_request( + auto res = co_await load_blancer->send_request( [](coro_rpc_client &client, std::string_view hostname) -> Lazy { auto res = co_await client.call("Hello world!"); if (!res.has_value()) { @@ -112,9 +112,8 @@ int main() { auto hosts = std::vector{"127.0.0.1:8801", "localhost:8801"}; auto worker_cnt = std::thread::hardware_concurrency() * 20; - auto chan = coro_io::channel::create( - hosts, coro_io::channel::channel_config{ - .pool_config{.max_connection = worker_cnt}}); + auto chan = coro_io::load_blancer::create( + hosts, {.pool_config{.max_connection = worker_cnt}}); auto chan_ptr = std::make_shared(std::move(chan)); auto executor = coro_io::get_global_block_executor(); for (int i = 0; i < worker_cnt; ++i) {