SessionMultiProxy: use stats to choose session proxy for a query
GitOrigin-RevId: fea88659f3634685b1e0bb1a1c13e98f68d2e4a8
This commit is contained in:
parent
1785a965d5
commit
9f9d429832
@ -41,7 +41,9 @@ void SessionMultiProxy::send(NetQueryPtr query) {
|
|||||||
if (query->session_rand()) {
|
if (query->session_rand()) {
|
||||||
pos = query->session_rand() % sessions_.size();
|
pos = query->session_rand() % sessions_.size();
|
||||||
} else {
|
} 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);
|
query->debug(PSTRING() << get_name() << ": send to proxy #" << pos);
|
||||||
|
@ -56,8 +56,10 @@ class SessionCallback : public Session::Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_result(NetQueryPtr query) override {
|
void on_result(NetQueryPtr query) override {
|
||||||
|
if (query->id() != 0) { // not an update
|
||||||
|
send_closure(parent_, &SessionProxy::on_query_finished);
|
||||||
|
}
|
||||||
G()->net_query_dispatcher().dispatch(std::move(query));
|
G()->net_query_dispatcher().dispatch(std::move(query));
|
||||||
send_closure(parent_, &SessionProxy::on_query_finished);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -105,6 +107,7 @@ void SessionProxy::start_up() {
|
|||||||
void SessionProxy::tear_down() {
|
void SessionProxy::tear_down() {
|
||||||
for (auto &query : pending_queries_) {
|
for (auto &query : pending_queries_) {
|
||||||
query->resend();
|
query->resend();
|
||||||
|
callback_->on_query_finished();
|
||||||
G()->net_query_dispatcher().dispatch(std::move(query));
|
G()->net_query_dispatcher().dispatch(std::move(query));
|
||||||
}
|
}
|
||||||
pending_queries_.clear();
|
pending_queries_.clear();
|
||||||
|
Reference in New Issue
Block a user