Store separate size of query_list_.

This commit is contained in:
levlam 2021-08-10 12:50:02 +03:00
parent eafb9375d2
commit 60acf1e402
4 changed files with 8 additions and 2 deletions

View File

@ -32,6 +32,7 @@ struct SharedData {
std::atomic<int> next_verbosity_level_{-1};
// not thread-safe
size_t query_list_size_ = 0;
td::ListNode query_list_;
td::unique_ptr<td::KeyValueSyncInterface> webhook_db_;
td::unique_ptr<td::TQueue> tqueue_;

View File

@ -47,6 +47,7 @@ Query::Query(td::vector<td::BufferSlice> &&container, td::Slice token, bool is_t
if (shared_data_) {
shared_data_->query_count_++;
if (method_ != "getupdates") {
shared_data_->query_list_size_++;
shared_data_->query_list_.put(this);
}
}

View File

@ -110,6 +110,9 @@ class Query : public td::ListNode {
~Query() {
if (shared_data_) {
shared_data_->query_count_--;
if (!empty()) {
shared_data_->query_list_size_--;
}
}
}

View File

@ -144,13 +144,14 @@ static void dump_statistics(const std::shared_ptr<SharedData> &shared_data,
LOG(WARNING) << td::tag("buffer_mem", td::format::as_size(td::BufferAllocator::get_buffer_mem()));
LOG(WARNING) << td::tag("buffer_slice_size", td::format::as_size(td::BufferAllocator::get_buffer_slice_size()));
auto query_list_size = shared_data->query_list_size_;
auto query_count = shared_data->query_count_.load();
LOG(WARNING) << td::tag("pending queries", query_count);
LOG(WARNING) << td::tag("pending queries", query_count) << td::tag("pending requests", query_list_size);
td::uint64 i = 0;
bool was_gap = false;
for (auto end = &shared_data->query_list_, cur = end->prev; cur != end; cur = cur->prev, i++) {
if (i < 20 || i > query_count - 20 || i % (query_count / 50 + 1) == 0) {
if (i < 20 || i > query_list_size - 20 || i % (query_list_size / 50 + 1) == 0) {
if (was_gap) {
LOG(WARNING) << "...";
was_gap = false;