Skip to content

Commit 4a82fb5

Browse files
snaurysnaury
authored andcommitted
Delay monlib index SortPages until the next render
YDB динамически регистрирует страницы запускающихся акторов в некоторых сервисах, при этом страницы в индексе хочется иметь сортированными. При одновременной регистрации большого кол-ва акторов множественные вызовы SortPages приводят к тому, что их регистрация растёт квадратично. Мне кажется лучше откладывать сортировку страниц до следующего рендера. commit_hash:22e547b6c8d2ce0c1fabebe985793520ec932f30
1 parent 1f4c818 commit 4a82fb5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

library/cpp/monlib/service/pages/index_mon_page.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ void TIndexMonPage::Output(IMonHttpRequest& request) {
5252

5353
void TIndexMonPage::OutputIndex(IOutputStream& out, bool pathEndsWithSlash) {
5454
TGuard<TMutex> g(Mtx);
55+
if (SortPagesPending) {
56+
Pages.sort([](const TMonPagePtr& a, const TMonPagePtr& b) {
57+
return AsciiCompareIgnoreCase(a->GetTitle(), b->GetTitle()) < 0;
58+
});
59+
SortPagesPending = false;
60+
}
5561
for (auto& Page : Pages) {
5662
IMonPage* page = Page.Get();
5763
if (page->IsInIndex()) {
@@ -164,9 +170,7 @@ void TIndexMonPage::OutputBody(IMonHttpRequest& req) {
164170

165171
void TIndexMonPage::SortPages() {
166172
TGuard<TMutex> g(Mtx);
167-
Pages.sort([](const TMonPagePtr& a, const TMonPagePtr& b) {
168-
return AsciiCompareIgnoreCase(a->GetTitle(), b->GetTitle()) < 0;
169-
});
173+
SortPagesPending = true;
170174
}
171175

172176
void TIndexMonPage::ClearPages() {

library/cpp/monlib/service/pages/index_mon_page.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace NMonitoring {
1111
TPages Pages; // a list of pages to maintain specific order
1212
using TPagesByPath = THashMap<TString, TPages::iterator>;
1313
TPagesByPath PagesByPath;
14+
bool SortPagesPending = false;
1415

1516
TIndexMonPage(const TString& path, const TString& title)
1617
: IMonPage(path, title)

0 commit comments

Comments
 (0)