SessionMultiProxy: use stats to choose session proxy for a query

GitOrigin-RevId: fea88659f3634685b1e0bb1a1c13e98f68d2e4a8
This commit is contained in:
Arseny Smirnov 2019-03-15 21:37:01 +11:00
parent 1785a965d5
commit 9f9d429832
2 changed files with 7 additions and 2 deletions

View File

@ -41,7 +41,9 @@ void SessionMultiProxy::send(NetQueryPtr query) {
if (query->session_rand()) {
pos = query->session_rand() % sessions_.size();
} else {
pos = pos_++ % sessions_.size();
pos = std::min_element(sessions_.begin(), sessions_.end(),
[](const auto &a, const auto &b) { return a.queries_count < b.queries_count; }) -
sessions_.begin();
}
}
query->debug(PSTRING() << get_name() << ": send to proxy #" << pos);

View File

@ -56,9 +56,11 @@ class SessionCallback : public Session::Callback {
}
void on_result(NetQueryPtr query) override {
G()->net_query_dispatcher().dispatch(std::move(query));
if (query->id() != 0) { // not an update
send_closure(parent_, &SessionProxy::on_query_finished);
}
G()->net_query_dispatcher().dispatch(std::move(query));
}
private:
ActorShared<SessionProxy> parent_;
@ -105,6 +107,7 @@ void SessionProxy::start_up() {
void SessionProxy::tear_down() {
for (auto &query : pending_queries_) {
query->resend();
callback_->on_query_finished();
G()->net_query_dispatcher().dispatch(std::move(query));
}
pending_queries_.clear();