Skip to content

[k2] rpc client boost#1635

Open
T-y-c-o-o-n wants to merge 20 commits into
masterfrom
n.siniachenko/k2/rpc-client-boost
Open

[k2] rpc client boost#1635
T-y-c-o-o-n wants to merge 20 commits into
masterfrom
n.siniachenko/k2/rpc-client-boost

Conversation

@T-y-c-o-o-n

Copy link
Copy Markdown
Contributor

No description provided.

@T-y-c-o-o-n T-y-c-o-o-n force-pushed the n.siniachenko/k2/rpc-client-boost branch from 156e9ec to 222adae Compare June 15, 2026 11:57
// prepare and send RPC request
// 'request_buf' will look like this:
// [ RpcExtraHeaders (optional) ] [ payload ]
if (const auto& [opt_new_extra_header, cur_extra_header_size]{kphp::rpc::regularize_extra_headers(tl_storer.view(), ignore_answer)}; opt_new_extra_header) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В новом коде нет вызова regularize_extra_headers(...)

const auto it_awaiter_task{rpc_client_instance_st.response_awaiter_tasks.find(request_id)};
if (it_awaiter_task == rpc_client_instance_st.response_awaiter_tasks.end()) [[unlikely]] {
kphp::log::warning("could not find rpc query with id {} in pending queries", queue_id);
const auto it_rpc_request_info{rpc_client_instance_st.rpc_requests_infos.find(request_id)};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

кажется, это не будет работать для ignore_answer запросов (если для них, вообще, вызывается rpc_queue_push)

Comment thread builtin-functions/kphp-light/stdlib/rpc.txt Outdated
Comment thread runtime-light/k2-platform/k2-header.h
Comment thread runtime-light/k2-platform/k2-header.h Outdated
Comment thread runtime-light/k2-platform/k2-header.h Outdated
Comment thread runtime-light/k2-platform/k2-header.h
Comment thread runtime-light/k2-platform/k2-header.h Outdated
Comment thread runtime-light/stdlib/rpc/rpc-api.cpp Outdated
Comment thread runtime-light/stdlib/rpc/rpc-api.cpp Outdated
if (!first_response_size) {
return std::unexpected{std::make_pair(TL_ERROR_INTERNAL, string{"error fetching rpc response"})};
}
string response{reinterpret_cast<char*>(k2::alloc(*first_response_size)), static_cast<string::size_type>(*first_response_size)};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can have a single buffer for RPC response to reuse

Comment thread runtime-light/stdlib/rpc/rpc-api.cpp Outdated
std::chrono::nanoseconds now_ns{now_instant.time_point_ns};
std::chrono::nanoseconds timeout{rpc_request_info.deadline - now_ns};
kphp::coro::io_scheduler& m_scheduler{kphp::coro::io_scheduler::get()};
switch (co_await m_scheduler.poll(rpc_request_info.rpc_d, kphp::coro::poll_op::read, timeout)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite hard to understand what's going on here. Can you please make it more human readable? For example, I think we don't need to directly use the scheduler's API here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to refactor and improve code readability:

  • k2-rpc-api logic refactored to separate kphp::rpc::query_handle class
  • time juggling moved to util functions

Comment thread runtime-light/stdlib/rpc/rpc-api.cpp Outdated
k2::TimePoint now_instant{};
k2::instant(std::addressof(now_instant));
std::chrono::nanoseconds now_ns{now_instant.time_point_ns};
std::chrono::nanoseconds timeout{rpc_request_info.deadline - now_ns};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if nobody will fetch response? I'm afraid we might hang in this case

@T-y-c-o-o-n T-y-c-o-o-n force-pushed the n.siniachenko/k2/rpc-client-boost branch from a342aa9 to e77636c Compare June 21, 2026 19:19
* `EAI_MEMORY` => max descriptors count achieved
* `EINVAL` => invalid `actor_name` or request, or connection pool is empty for this actor.
*/
int32_t k2_rpc_send(const char* actor_name, size_t actor_name_len, const void* request_ptr, size_t request_size, enum RpcKind rpc_kind, uint64_t* rpc_d);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do either:

  • rename k2_rpc_send -> k2_rpc_send_request
  • rename k2_rpc_fetch_response -> k2_rpc_fetch, k2_rpc_get_response_size -> k2_rpc_response_size

return k2_component_access(component_name.size(), component_name.data());
}

inline std::expected<uint64_t, int32_t> rpc_send_request(std::string_view actor_name, std::span<const std::byte> request_buffer) noexcept {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • we have k2::descriptor type that should be used here instead of uint64_t
  • shouldn't we add rpc_kind parameter?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put these functions to kphp::time namespace and name them like kphp::time::remaining and kphp::time::expires_at.

P.S. we try to not introduce util as it leads to a bunch of disparate functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants