aboutsummaryrefslogtreecommitdiffstats
path: root/util/system
diff options
context:
space:
mode:
authorsvkrasnov <svkrasnov@yandex-team.com>2023-01-12 20:28:20 +0300
committersvkrasnov <svkrasnov@yandex-team.com>2023-01-12 20:28:20 +0300
commitb168b15511a5b04b8d6aababf3ec9a3fba1e9924 (patch)
treec03a10ada9bb7d9af632f7e887bbf7ecb897450e /util/system
parent8779e0af5f7fe453a9c4e6cc1eea9ca0c7353352 (diff)
downloadydb-b168b15511a5b04b8d6aababf3ec9a3fba1e9924.tar.gz
introduce NumberOfMillicores() function based on refactored CgroupCpus() returning double value
Diffstat (limited to 'util/system')
-rw-r--r--util/system/info.cpp32
-rw-r--r--util/system/info.h2
2 files changed, 29 insertions, 5 deletions
diff --git a/util/system/info.cpp b/util/system/info.cpp
index 5cd5f0d815..9b0fbced85 100644
--- a/util/system/info.cpp
+++ b/util/system/info.cpp
@@ -2,6 +2,7 @@
#include "error.h"
+#include <cmath>
#include <cstdlib>
#if defined(_linux_) || defined(_cygwin_)
@@ -45,32 +46,44 @@ static int getloadavg(double* loadavg, int nelem) {
This function olny works properly if you apply correct setting to your nanny/deploy project
In nanny - Runtime -> Instance spec -> Advanced settings -> Cgroupfs settings: Mount mode = Read only
+
+In deploy - Stage - Edit stage - Box - Cgroupfs settings: Mount mode = Read only
*/
-static inline size_t CgroupCpus() {
+static inline double CgroupCpus() {
try {
- auto q = FromString<ssize_t>(StripString(TFileInput("/sys/fs/cgroup/cpu/cpu.cfs_quota_us").ReadAll()));
+ double q = FromString<int32_t>(StripString(TFileInput("/sys/fs/cgroup/cpu/cpu.cfs_quota_us").ReadAll()));
if (q <= 0) {
return 0;
}
- auto p = FromString<ssize_t>(StripString(TFileInput("/sys/fs/cgroup/cpu/cpu.cfs_period_us").ReadAll()));
+ double p = FromString<int32_t>(StripString(TFileInput("/sys/fs/cgroup/cpu/cpu.cfs_period_us").ReadAll()));
if (p <= 0) {
return 0;
}
- return Max<ssize_t>(1, (q + p / 2) / p);
+ return q / p;
} catch (...) {
return 0;
}
}
#endif
+size_t NSystemInfo::NumberOfMillicores() {
+#if defined(_linux_)
+ return CgroupCpus() * 1000;
+#else
+ // fallback behaviour if cgroupfs is not available
+ // returns number of millicores which is a multiple of an integer number of cpus
+ return NSystemInfo::NumberOfCpus() * 1000;
+#endif
+}
+
size_t NSystemInfo::NumberOfCpus() {
#if defined(_linux_)
if (auto res = CgroupCpus(); res) {
- return res;
+ return Max<ssize_t>(1, std::llround(res));
}
#endif
@@ -172,6 +185,7 @@ size_t NSystemInfo::LoadAverage(double* la, size_t len) {
}
static size_t NCpus;
+static size_t NMillicores;
size_t NSystemInfo::CachedNumberOfCpus() {
if (!NCpus) {
@@ -181,6 +195,14 @@ size_t NSystemInfo::CachedNumberOfCpus() {
return NCpus;
}
+size_t NSystemInfo::CachedNumberOfMillicores() {
+ if (!NMillicores) {
+ NMillicores = NumberOfMillicores();
+ }
+
+ return NMillicores;
+}
+
size_t NSystemInfo::GetPageSize() noexcept {
#if defined(_win_)
SYSTEM_INFO sysInfo;
diff --git a/util/system/info.h b/util/system/info.h
index 73ebe48a9a..9e6fa2fb3d 100644
--- a/util/system/info.h
+++ b/util/system/info.h
@@ -4,7 +4,9 @@
namespace NSystemInfo {
size_t NumberOfCpus();
+ size_t NumberOfMillicores();
size_t CachedNumberOfCpus();
+ size_t CachedNumberOfMillicores();
size_t LoadAverage(double* la, size_t len);
size_t GetPageSize() noexcept;
size_t TotalMemorySize();