Pass max_resource_limit as parameter to ResourceManager.
This commit is contained in:
parent
3886e9e644
commit
0bc767f943
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
#include "td/telegram/files/FileLoadManager.h"
|
#include "td/telegram/files/FileLoadManager.h"
|
||||||
|
|
||||||
|
#include "td/telegram/ConfigShared.h"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/net/DcId.h"
|
#include "td/telegram/net/DcId.h"
|
||||||
#include "td/telegram/TdParameters.h"
|
#include "td/telegram/TdParameters.h"
|
||||||
@ -22,17 +23,20 @@ FileLoadManager::FileLoadManager(ActorShared<Callback> callback, ActorShared<> p
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileLoadManager::start_up() {
|
void FileLoadManager::start_up() {
|
||||||
upload_resource_manager_ =
|
if (G()->shared_config().get_option_boolean("is_premium")) {
|
||||||
create_actor<ResourceManager>("UploadResourceManager", !G()->parameters().use_file_db /*tdlib_engine*/
|
max_resource_limit_ *= 8;
|
||||||
? ResourceManager::Mode::Greedy
|
}
|
||||||
: ResourceManager::Mode::Baseline);
|
upload_resource_manager_ = create_actor<ResourceManager>("UploadResourceManager", max_resource_limit_,
|
||||||
|
!G()->parameters().use_file_db /*tdlib_engine*/
|
||||||
|
? ResourceManager::Mode::Greedy
|
||||||
|
: ResourceManager::Mode::Baseline);
|
||||||
}
|
}
|
||||||
|
|
||||||
ActorOwn<ResourceManager> &FileLoadManager::get_download_resource_manager(bool is_small, DcId dc_id) {
|
ActorOwn<ResourceManager> &FileLoadManager::get_download_resource_manager(bool is_small, DcId dc_id) {
|
||||||
auto &actor = is_small ? download_small_resource_manager_map_[dc_id] : download_resource_manager_map_[dc_id];
|
auto &actor = is_small ? download_small_resource_manager_map_[dc_id] : download_resource_manager_map_[dc_id];
|
||||||
if (actor.empty()) {
|
if (actor.empty()) {
|
||||||
actor = create_actor<ResourceManager>(
|
actor = create_actor<ResourceManager>(
|
||||||
PSLICE() << "DownloadResourceManager " << tag("is_small", is_small) << tag("dc_id", dc_id),
|
PSLICE() << "DownloadResourceManager " << tag("is_small", is_small) << tag("dc_id", dc_id), max_resource_limit_,
|
||||||
ResourceManager::Mode::Baseline);
|
ResourceManager::Mode::Baseline);
|
||||||
}
|
}
|
||||||
return actor;
|
return actor;
|
||||||
@ -172,7 +176,7 @@ void FileLoadManager::update_downloaded_part(QueryId id, int64 offset, int64 lim
|
|||||||
if (node == nullptr) {
|
if (node == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
send_closure(node->loader_, &FileLoaderActor::update_downloaded_part, offset, limit);
|
send_closure(node->loader_, &FileLoaderActor::update_downloaded_part, offset, limit, max_resource_limit_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileLoadManager::hangup() {
|
void FileLoadManager::hangup() {
|
||||||
|
@ -75,6 +75,7 @@ class FileLoadManager final : public Actor {
|
|||||||
ActorShared<Callback> callback_;
|
ActorShared<Callback> callback_;
|
||||||
ActorShared<> parent_;
|
ActorShared<> parent_;
|
||||||
std::map<QueryId, NodeId> query_id_to_node_id_;
|
std::map<QueryId, NodeId> query_id_to_node_id_;
|
||||||
|
int64 max_resource_limit_ = 1 << 21;
|
||||||
bool stop_flag_ = false;
|
bool stop_flag_ = false;
|
||||||
|
|
||||||
void start_up() final;
|
void start_up() final;
|
||||||
|
@ -72,12 +72,12 @@ void FileLoader::update_local_file_location(const LocalFileLocation &local) {
|
|||||||
loop();
|
loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileLoader::update_downloaded_part(int64 offset, int64 limit) {
|
void FileLoader::update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) {
|
||||||
if (parts_manager_.get_streaming_offset() != offset) {
|
if (parts_manager_.get_streaming_offset() != offset) {
|
||||||
auto begin_part_id = parts_manager_.set_streaming_offset(offset, limit);
|
auto begin_part_id = parts_manager_.set_streaming_offset(offset, limit);
|
||||||
auto new_end_part_id = limit <= 0 ? parts_manager_.get_part_count()
|
auto new_end_part_id = limit <= 0 ? parts_manager_.get_part_count()
|
||||||
: narrow_cast<int32>((offset + limit - 1) / parts_manager_.get_part_size()) + 1;
|
: narrow_cast<int32>((offset + limit - 1) / parts_manager_.get_part_size()) + 1;
|
||||||
auto max_parts = narrow_cast<int32>(ResourceManager::MAX_RESOURCE_LIMIT / parts_manager_.get_part_size());
|
auto max_parts = narrow_cast<int32>(max_resource_limit / parts_manager_.get_part_size());
|
||||||
auto end_part_id = begin_part_id + td::min(max_parts, new_end_part_id - begin_part_id);
|
auto end_part_id = begin_part_id + td::min(max_parts, new_end_part_id - begin_part_id);
|
||||||
VLOG(file_loader) << "Protect parts " << begin_part_id << " ... " << end_part_id - 1;
|
VLOG(file_loader) << "Protect parts " << begin_part_id << " ... " << end_part_id - 1;
|
||||||
for (auto &it : part_map_) {
|
for (auto &it : part_map_) {
|
||||||
|
@ -38,7 +38,7 @@ class FileLoader : public FileLoaderActor {
|
|||||||
void update_resources(const ResourceState &other) final;
|
void update_resources(const ResourceState &other) final;
|
||||||
|
|
||||||
void update_local_file_location(const LocalFileLocation &local) final;
|
void update_local_file_location(const LocalFileLocation &local) final;
|
||||||
void update_downloaded_part(int64 offset, int64 limit) final;
|
void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) final;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void set_ordered_flag(bool flag);
|
void set_ordered_flag(bool flag);
|
||||||
|
@ -22,10 +22,10 @@ class FileLoaderActor : public NetQueryCallback {
|
|||||||
virtual void update_priority(int8 priority) = 0;
|
virtual void update_priority(int8 priority) = 0;
|
||||||
virtual void update_resources(const ResourceState &other) = 0;
|
virtual void update_resources(const ResourceState &other) = 0;
|
||||||
|
|
||||||
// TODO: existence of these three functions is a dirty hack. Refactoring is highly appreciated
|
// TODO: existence of these two functions is a dirty hack. Refactoring is highly appreciated
|
||||||
virtual void update_local_file_location(const LocalFileLocation &local) {
|
virtual void update_local_file_location(const LocalFileLocation &local) {
|
||||||
}
|
}
|
||||||
virtual void update_downloaded_part(int64 offset, int64 limit) {
|
virtual void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ void ResourceManager::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto active_limit = resource_state_.active_limit();
|
auto active_limit = resource_state_.active_limit();
|
||||||
resource_state_.update_limit(MAX_RESOURCE_LIMIT - active_limit);
|
resource_state_.update_limit(max_resource_limit_ - active_limit);
|
||||||
LOG(INFO) << tag("unused", resource_state_.unused());
|
LOG(INFO) << tag("unused", resource_state_.unused());
|
||||||
|
|
||||||
if (mode_ == Mode::Greedy) {
|
if (mode_ == Mode::Greedy) {
|
||||||
|
@ -21,7 +21,7 @@ namespace td {
|
|||||||
class ResourceManager final : public Actor {
|
class ResourceManager final : public Actor {
|
||||||
public:
|
public:
|
||||||
enum class Mode : int32 { Baseline, Greedy };
|
enum class Mode : int32 { Baseline, Greedy };
|
||||||
explicit ResourceManager(Mode mode) : mode_(mode) {
|
ResourceManager(int64 max_resource_limit, Mode mode) : max_resource_limit_(max_resource_limit), mode_(mode) {
|
||||||
}
|
}
|
||||||
// use through ActorShared
|
// use through ActorShared
|
||||||
void update_priority(int8 priority);
|
void update_priority(int8 priority);
|
||||||
@ -29,10 +29,10 @@ class ResourceManager final : public Actor {
|
|||||||
|
|
||||||
void register_worker(ActorShared<FileLoaderActor> callback, int8 priority);
|
void register_worker(ActorShared<FileLoaderActor> callback, int8 priority);
|
||||||
|
|
||||||
static constexpr int64 MAX_RESOURCE_LIMIT = 1 << 21;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int64 max_resource_limit_ = 0;
|
||||||
Mode mode_;
|
Mode mode_;
|
||||||
|
|
||||||
using NodeId = uint64;
|
using NodeId = uint64;
|
||||||
struct Node final : public HeapNode {
|
struct Node final : public HeapNode {
|
||||||
NodeId node_id = 0;
|
NodeId node_id = 0;
|
||||||
|
@ -168,9 +168,10 @@ Status NetQueryDispatcher::wait_dc_init(DcId dc_id, bool force) {
|
|||||||
int32 slow_net_scheduler_id = G()->get_slow_net_scheduler_id();
|
int32 slow_net_scheduler_id = G()->get_slow_net_scheduler_id();
|
||||||
|
|
||||||
auto raw_dc_id = dc_id.get_raw_id();
|
auto raw_dc_id = dc_id.get_raw_id();
|
||||||
int32 upload_session_count = raw_dc_id != 2 && raw_dc_id != 4 ? 8 : 4;
|
bool is_premium = G()->shared_config().get_option_boolean("is_premium");
|
||||||
int32 download_session_count = 2;
|
int32 upload_session_count = (raw_dc_id != 2 && raw_dc_id != 4) || is_premium ? 8 : 4;
|
||||||
int32 download_small_session_count = 2;
|
int32 download_session_count = is_premium ? 8 : 2;
|
||||||
|
int32 download_small_session_count = is_premium ? 8 : 2;
|
||||||
dc.main_session_ = create_actor<SessionMultiProxy>(PSLICE() << "SessionMultiProxy:" << raw_dc_id << ":main",
|
dc.main_session_ = create_actor<SessionMultiProxy>(PSLICE() << "SessionMultiProxy:" << raw_dc_id << ":main",
|
||||||
session_count, auth_data, raw_dc_id == main_dc_id_, use_pfs,
|
session_count, auth_data, raw_dc_id == main_dc_id_, use_pfs,
|
||||||
false, false, is_cdn, need_destroy_key);
|
false, false, is_cdn, need_destroy_key);
|
||||||
|
Loading…
Reference in New Issue
Block a user