Add experimental options

This commit is contained in:
Andrea Cavalli 2021-01-04 12:00:33 +01:00
parent cf3cc7b1d3
commit 5686d574f8
2 changed files with 23 additions and 0 deletions

View File

@ -28,6 +28,8 @@ We added some options:
* **delete_chat_reference_after_seconds** (positive number) During cleanup, free the memory of the chats that have not been touched for more than X seconds * **delete_chat_reference_after_seconds** (positive number) During cleanup, free the memory of the chats that have not been touched for more than X seconds
* **delete_user_reference_after_seconds** (positive number) During cleanup, free the memory of the users that have not been touched for more than X seconds * **delete_user_reference_after_seconds** (positive number) During cleanup, free the memory of the users 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 * **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 (Experimental!)
* **experiment_debug_file_reference_cleanup** (true/false) During cleanup, print log messages about file references cleanup (Experimental!)
## Custom API functions ## Custom API functions
### TdApi.OptimizeMemory ### TdApi.OptimizeMemory

View File

@ -14,6 +14,7 @@
#include "td/telegram/MessagesManager.h" #include "td/telegram/MessagesManager.h"
#include "td/telegram/StickerSetId.h" #include "td/telegram/StickerSetId.h"
#include "td/telegram/StickersManager.h" #include "td/telegram/StickersManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/WebPagesManager.h" #include "td/telegram/WebPagesManager.h"
@ -372,35 +373,55 @@ void FileReferenceManager::reload_photo(PhotoSizeSource source, Promise<Unit> pr
} }
void FileReferenceManager::memory_cleanup() { void FileReferenceManager::memory_cleanup() {
if (!G()->shared_config().get_option_boolean("experiment_enable_file_reference_cleanup", false)) {
return;
}
auto print_debug_messages = G()->shared_config().get_option_boolean("experiment_debug_file_reference_cleanup", false);
if (print_debug_messages) LOG(ERROR) << "memory_cleanup begin";
auto file_source_it = file_sources_.begin(); auto file_source_it = file_sources_.begin();
while (file_source_it != file_sources_.end()) { while (file_source_it != file_sources_.end()) {
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop begin";
auto source_id = file_source_it->first; auto source_id = file_source_it->first;
auto file_nodes_it = nodes_.begin(); auto file_nodes_it = nodes_.begin();
auto remove = true; auto remove = true;
while (file_nodes_it != nodes_.end() && remove) { while (file_nodes_it != nodes_.end() && remove) {
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop begin";
auto elements = get_all_file_sources(file_nodes_it->first); auto elements = get_all_file_sources(file_nodes_it->first);
auto elements_it = elements.begin(); auto elements_it = elements.begin();
while (elements_it != elements.end()) { while (elements_it != elements.end()) {
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop begin";
if (source_id == (u_long) elements_it->get()) { if (source_id == (u_long) elements_it->get()) {
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop break";
remove = false; remove = false;
break; break;
} }
elements_it++; elements_it++;
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop next";
} }
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop end";
file_nodes_it++; file_nodes_it++;
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop next";
} }
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop end";
if (remove) { if (remove) {
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> remove element from file_source";
file_source_it = file_sources_.erase(file_source_it); file_source_it = file_sources_.erase(file_source_it);
} else { } else {
file_source_it++; file_source_it++;
} }
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop next";
} }
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop end";
if (print_debug_messages) LOG(ERROR) << "memory_cleanup end";
} }
void FileReferenceManager::memory_cleanup(NodeId node_id) { void FileReferenceManager::memory_cleanup(NodeId node_id) {