From 033d2bf2489845896671c8e7dfc1b8d749afb1a5 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 2 May 2023 16:55:03 +0200 Subject: [PATCH 1/2] Revert "Recommend to try libjemalloc to speed up reload" This reverts commit 0230883a51a57074ebe35ee17f70aef69c032e83. --- doc/15-troubleshooting.md | 62 +++------------------------------------ 1 file changed, 4 insertions(+), 58 deletions(-) diff --git a/doc/15-troubleshooting.md b/doc/15-troubleshooting.md index 67f2de65a..daf2b75e8 100644 --- a/doc/15-troubleshooting.md +++ b/doc/15-troubleshooting.md @@ -236,63 +236,9 @@ curl -k -s -S -i -u root:icinga -H 'Accept: application/json' \ ## Icinga starts/restarts/reloads very slowly -### Try swapping out the allocator +Optimise apply rules and group assign conditions. -Icinga performs a lot of memory allocations, especially during startup. -Swapping out the allocator may increase the startup performance. -The following instructions assume you run Linux and systemd. - -On RHEL or derivates add the EPEL repository first (if not already done). -Let your package manager search for package names containing "jemalloc". -Pick preferably one named "libjemalloc" followed by a number, -just "jemalloc" otherwise, and install it. - -Run `ldconfig -p |grep libjemalloc`. It should print something similar to: - -``` - libjemalloc.so.2 (libc6,x86-64) => /lib/x86_64-linux-gnu/libjemalloc.so.2 -``` - -I.e. a relative file name followed by an absolute one. Remember the latter. - -Measure how long Icinga needs to load its config without and with libjemalloc: - -```bash -time icinga2 daemon -C - -time env LD_PRELOAD=/lib/x86_64-linux-gnu/libjemalloc.so.2 icinga2 daemon -C -``` - -Replace `/lib/x86_64-linux-gnu/libjemalloc.so.2` with the absolute path -you actually got from `ldconfig -p`! - -Please do us a favor and share your results -[with us](https://community.icinga.com/t/icinga-reloads-config-slowly-try-jemalloc/11032). - -If it's faster with libjemalloc, do the following to persist the change. - -Run `systemctl edit icinga2.service`. This will open an editor. -Add the following, save the file and close the editor. - -``` -[Service] -Environment=LD_PRELOAD=/lib/x86_64-linux-gnu/libjemalloc.so.2 -``` - -Replace `/lib/x86_64-linux-gnu/libjemalloc.so.2` with the absolute path -you actually got from `ldconfig -p`! - -Restart Icinga. Verify whether your changes took effect and enjoy the speed: - -``` -# lsof -p `cat /var/run/icinga2/icinga2.pid` |grep libjemalloc -icinga2 7764 nagios mem REG 8,5 744776 2631636 /usr/lib/x86_64-linux-gnu/libjemalloc.so.2 -# -``` - -### Optimise apply rules and group assign conditions - -#### Remove actually unused apply rules +### Remove actually unused apply rules If `icinga2 daemon -C` warns you like shown below and the respective apply rule should indeed create no objects, consider removing it. At least comment it out. @@ -307,7 +253,7 @@ but you can disable apply rules (temporarily or permanently). Same for `assign where` conditions in groups. In this case removing just the `assign where` line(s) is enough if you'd like to keep the group itself. -#### Avoid creating single objects via apply rules +### Avoid creating single objects via apply rules If possible, replace constructs like the immediately following with the below one. @@ -339,7 +285,7 @@ object Host "firewall" { } ``` -#### Reduce `assign where` filter complexity +### Reduce `assign where` filter complexity If neither removals, nor flat objects, nor Icinga v2.13.6+ are an option, at least keep the filter as simple as possible. From c74d95c51d1fdf4746963122f9e4cebdbc499fa1 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 12 Apr 2021 12:12:55 +0200 Subject: [PATCH 2/2] Integrate jemalloc --- CMakeLists.txt | 8 ++++++++ icinga-app/CMakeLists.txt | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fce41f411..8abd15b47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -187,6 +187,14 @@ add_definitions(-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) link_directories(${Boost_LIBRARY_DIRS}) include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) +find_library(JEMALLOC_LIBRARIES NAMES jemalloc) + +if(JEMALLOC_LIBRARIES) + message(STATUS "Found jemalloc: ${JEMALLOC_LIBRARIES}") +else() + message(WARNING "Couldn't find jemalloc") +endif() + find_package(OpenSSL REQUIRED) include_directories(SYSTEM ${OPENSSL_INCLUDE_DIR}) diff --git a/icinga-app/CMakeLists.txt b/icinga-app/CMakeLists.txt index 01b4efc67..15af4ea29 100644 --- a/icinga-app/CMakeLists.txt +++ b/icinga-app/CMakeLists.txt @@ -70,6 +70,10 @@ add_executable(icinga-app target_link_libraries(icinga-app ${base_DEPS}) +if(JEMALLOC_LIBRARIES) + target_link_libraries(icinga-app ${JEMALLOC_LIBRARIES}) +endif() + set_target_properties ( icinga-app PROPERTIES FOLDER Bin