Add an experimental option to delay get_channel_difference

This commit is contained in:
Andrea Cavalli 2021-03-21 00:27:18 +01:00
parent ebeaf7f90e
commit e1771fa7de
4 changed files with 31 additions and 3 deletions

View File

@ -30,6 +30,8 @@ We added some options:
* **delete_file_reference_after_seconds** (positive number) During cleanup, free the memory of the files that have not been touched for more than X seconds * **delete_file_reference_after_seconds** (positive number) During cleanup, free the memory of the files that have not been touched for more than X seconds
* **experiment_enable_file_reference_cleanup** (**true**/false) During cleanup, free the memory of the file references * **experiment_enable_file_reference_cleanup** (**true**/false) During cleanup, free the memory of the file references
* **experiment_enable_chat_access_hash_cleanup** (**true**/false) During cleanup, clean chats and channels access hash * **experiment_enable_chat_access_hash_cleanup** (**true**/false) During cleanup, clean chats and channels access hash
* **get_channel_difference_delay_milliseconds** (**0**) Delay get_channel_difference n milliseconds every ~3000pts (~300msg).
Don't modify this option unless you have a very large bot that struggles to keep up with start-up updates throughput.
## Custom API functions ## Custom API functions
### TdApi.OptimizeMemory ### TdApi.OptimizeMemory

View File

@ -35641,6 +35641,23 @@ class MessagesManager::GetChannelDifferenceLogEvent {
} }
}; };
void MessagesManager::get_channel_difference_delayed(DialogId dialog_id, int32 pts,
bool force, double delay_seconds, const char *source) {
if (delay_seconds <= 0.0) {
// Execute get_channel_difference immediatly
get_channel_difference(dialog_id,pts, force, "on_get_channel_difference");
} else {
// Schedule get_channel_difference
create_actor<SleepActor>(
"GetChannelDifferenceDelayedActor", delay_seconds,
PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, pts, force](Result<Unit> result) {
send_closure(actor_id, &MessagesManager::get_channel_difference, dialog_id, pts, force,
"on_get_channel_difference");
}))
.release();
}
}
void MessagesManager::get_channel_difference(DialogId dialog_id, int32 pts, bool force, const char *source) { void MessagesManager::get_channel_difference(DialogId dialog_id, int32 pts, bool force, const char *source) {
if (channel_get_difference_retry_timeout_.has_timeout(dialog_id.get())) { if (channel_get_difference_retry_timeout_.has_timeout(dialog_id.get())) {
LOG(INFO) << "Skip running channels.getDifference for " << dialog_id << " from " << source LOG(INFO) << "Skip running channels.getDifference for " << dialog_id << " from " << source
@ -36057,7 +36074,9 @@ void MessagesManager::on_get_channel_difference(
if (!is_final) { if (!is_final) {
LOG_IF(ERROR, timeout > 0) << "Have timeout in not final ChannelDifference in " << dialog_id; LOG_IF(ERROR, timeout > 0) << "Have timeout in not final ChannelDifference in " << dialog_id;
get_channel_difference(dialog_id, d->pts, true, "on_get_channel_difference"); auto delay_seconds = static_cast<double>(G()->shared_config()
.get_option_integer("get_channel_difference_delay_milliseconds", 0)) / 1000.0;
get_channel_difference_delayed(dialog_id, d->pts, true, delay_seconds, "on_get_channel_difference");
return; return;
} }

View File

@ -1646,8 +1646,8 @@ class MessagesManager : public Actor {
static constexpr int32 MAX_SEARCH_MESSAGES = 100; // server side limit static constexpr int32 MAX_SEARCH_MESSAGES = 100; // server side limit
static constexpr int32 MIN_SEARCH_PUBLIC_DIALOG_PREFIX_LEN = 4; // server side limit static constexpr int32 MIN_SEARCH_PUBLIC_DIALOG_PREFIX_LEN = 4; // server side limit
static constexpr int32 MIN_CHANNEL_DIFFERENCE = 10; static constexpr int32 MIN_CHANNEL_DIFFERENCE = 10;
static constexpr int32 MAX_CHANNEL_DIFFERENCE = 100; static constexpr int32 MAX_BOT_CHANNEL_DIFFERENCE = 1000000; // server side limit
static constexpr int32 MAX_BOT_CHANNEL_DIFFERENCE = 100000; // server side limit static constexpr int32 MAX_CHANNEL_DIFFERENCE = MAX_BOT_CHANNEL_DIFFERENCE;
static constexpr int32 MAX_RECENTLY_FOUND_DIALOGS = 30; // some reasonable value static constexpr int32 MAX_RECENTLY_FOUND_DIALOGS = 30; // some reasonable value
static constexpr size_t MAX_TITLE_LENGTH = 128; // server side limit for chat title static constexpr size_t MAX_TITLE_LENGTH = 128; // server side limit for chat title
static constexpr size_t MAX_DESCRIPTION_LENGTH = 255; // server side limit for chat description static constexpr size_t MAX_DESCRIPTION_LENGTH = 255; // server side limit for chat description
@ -2774,6 +2774,8 @@ class MessagesManager : public Actor {
void on_channel_get_difference_timeout(DialogId dialog_id); void on_channel_get_difference_timeout(DialogId dialog_id);
void get_channel_difference_delayed(DialogId dialog_id, int32 pts, bool force, double timeout, const char *source);
void get_channel_difference(DialogId dialog_id, int32 pts, bool force, const char *source); void get_channel_difference(DialogId dialog_id, int32 pts, bool force, const char *source);
void do_get_channel_difference(DialogId dialog_id, int32 pts, bool force, void do_get_channel_difference(DialogId dialog_id, int32 pts, bool force,

View File

@ -7462,6 +7462,11 @@ void Td::on_request(uint64 id, td_api::setOption &request) {
return; return;
} }
break; break;
case 'g':
if (set_integer_option("get_channel_difference_delay_milliseconds")) {
return;
}
break;
case 'i': case 'i':
if (set_boolean_option("ignore_background_updates")) { if (set_boolean_option("ignore_background_updates")) {
return; return;