mirror of
https://github.com/PaiGramTeam/telegram-bot-api.git
synced 2024-11-22 23:42:28 +00:00
Improve limit for active queries.
This commit is contained in:
parent
ed0532bcf7
commit
48a5609de2
@ -4070,9 +4070,11 @@ void Client::start_up() {
|
||||
void Client::send(PromisedQueryPtr query) {
|
||||
if (!query->is_internal()) {
|
||||
query->set_stat_actor(stat_actor_);
|
||||
if (!parameters_->local_mode_ && !is_local_method(query->method())) {
|
||||
const BotStatActor *stat = stat_actor_.get_actor_unsafe();
|
||||
if (stat->get_active_request_count() > 5000) {
|
||||
if (!parameters_->local_mode_ && !is_local_method(query->method()) &&
|
||||
td::Time::now() > parameters_->start_time_ + 10 * 60) {
|
||||
BotStatActor *stat = stat_actor_.get_actor_unsafe();
|
||||
auto update_per_minute = static_cast<int64>(stat->get_minute_update_count(td::Time::now()) * 60);
|
||||
if (stat->get_active_request_count() > 500 + update_per_minute) {
|
||||
LOG(INFO) << "Fail a query, because there are too many active queries: " << *query;
|
||||
return query->set_retry_after_error(60);
|
||||
}
|
||||
@ -4080,7 +4082,7 @@ void Client::send(PromisedQueryPtr query) {
|
||||
LOG(INFO) << "Fail a query, because the total size of active file uploads is too big: " << *query;
|
||||
return query->set_retry_after_error(60);
|
||||
}
|
||||
if (stat->get_active_file_upload_count() > 500 && !query->files().empty()) {
|
||||
if (stat->get_active_file_upload_count() > 100 + update_per_minute / 5 && !query->files().empty()) {
|
||||
LOG(INFO) << "Fail a query, because there are too many active file uploads: " << *query;
|
||||
return query->set_retry_after_error(60);
|
||||
}
|
||||
|
@ -160,6 +160,15 @@ double BotStatActor::get_score(double now) {
|
||||
return result;
|
||||
}
|
||||
|
||||
double BotStatActor::get_minute_update_count(double now) {
|
||||
auto minute_stat = stat_[2].stat_duration(now);
|
||||
double result = minute_stat.first.update_count_;
|
||||
if (minute_stat.second != 0) {
|
||||
result /= minute_stat.second;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
td::int64 BotStatActor::get_active_request_count() const {
|
||||
return active_request_count_;
|
||||
}
|
||||
|
@ -182,10 +182,13 @@ class BotStatActor final : public td::Actor {
|
||||
}
|
||||
|
||||
td::vector<StatItem> as_vector(double now);
|
||||
|
||||
td::string get_description() const;
|
||||
|
||||
double get_score(double now);
|
||||
|
||||
double get_minute_update_count(double now);
|
||||
|
||||
td::int64 get_active_request_count() const;
|
||||
|
||||
td::int64 get_active_file_upload_bytes() const;
|
||||
|
Loading…
Reference in New Issue
Block a user