10000 Implement memory detection override. (#11268) · arangodb/arangodb@72fa16d · GitHub
[go: up one dir, main page]

Skip to content

Commit 72fa16d

Browse files
authored
Implement memory detection override. (#11268)
1 parent f57786d commit 72fa16d

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

CHANGELOG

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
devel
22
-----
33

4-
4+
* Allow to override the detected total amount of memory via an environment
5+
variable ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY.
6+
57
* `splice-subqueries` optimization is not limited by any type of operation within the
68
subquery any more. It can now be applied on every subquery and will be by default.
79
However they may be a performance impact on some queries where splice-subqueries

lib/ApplicationFeatures/EnvironmentFeature.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ void EnvironmentFeature::prepare() {
246246
// file not found or value not convertible into integer
247247
}
248248

249+
// Report memory found:
250+
uint64_t ram = PhysicalMemory::getValue();
251+
std::string overriddenmsg;
252+
if (PhysicalMemory::overridden()) {
253+
overriddenmsg = " (overridden by environment variable)";
254+
}
255+
LOG_TOPIC("25362", INFO, Logger::MEMORY)
256+
<< "Available physical memory: " << ram << overriddenmsg;
257+
249258
// test local ipv6 support
250259
try {
251260
if (!basics::FileUtils::exists("/proc/net/if_inet6")) {

lib/Basics/PhysicalMemory.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "Basics/operating-system.h"
2424

2525
#include "Basics/PhysicalMemory.h"
26+
#include "Basics/StringUtils.h"
27+
#include "Basics/files.h"
2628

2729
#ifdef TRI_HAVE_UNISTD_H
2830
#include <unistd.h>
@@ -90,10 +92,32 @@ uint64_t physicalMemoryImpl() {
9092
#endif
9193
#endif
9294

93-
9495
struct PhysicalMemoryCache {
95-
PhysicalMemoryCache() : cachedValue(physicalMemoryImpl()) {}
96-
uint64_t const cachedValue;
96+
PhysicalMemoryCache() : cachedValue(physicalMemoryImpl()), overridden(false) {
97+
std::string value;
98+
if (TRI_GETENV("ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY", value)) {
99+
if (!value.empty()) {
100+
uint64_t multiplier = 1;
101+
if (value.back() == 'G' || value.back() == 'g') {
102+
multiplier = 1024*1024*1024;
103+
value.pop_back();
104+
} else if (value.back() == 'M' || value.back() == 'm') {
105+
multiplier = 1024 * 1024;
106+
value.pop_back();
107+
} else if (value.back() == 'K' || value.back() == 'k') {
108+
multiplier = 1024;
109+
value.pop_back();
110+
}
111+
uint64_t v = arangodb::basics::StringUtils::uint64(value) * multiplier;
112+
if (v != 0) {
113+
cachedValue = v;
114+
overridden = true;
115+
}
116+
}
117+
}
118+
}
119+
uint64_t cachedValue;
120+
bool overridden;
97121
};
98122

99123
PhysicalMemoryCache const cache;
@@ -104,3 +128,8 @@ PhysicalMemoryCache const cache;
104128
uint64_t arangodb::PhysicalMemory::getValue() {
105129
return ::cache.cachedValue;
106130
}
131+
132+
/// @brief return if physical memory size was overridden
133+
bool arangodb::PhysicalMemory::overridden() {
134+
return ::cache.overridden;
135+
}

lib/Basics/PhysicalMemory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace PhysicalMemory {
3030

3131
/// @brief return system's physical memory
3232
uint64_t getValue();
33+
bool overridden();
3334

3435
}
3536
} // namespace arangodb

lib/Logger/LogTopic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ LogTopic Logger::GRAPHS("graphs", LogLevel::INFO);
132132
LogTopic Logger::HEARTBEAT("heartbeat", LogLevel::INFO);
133133
LogTopic Logger::HTTPCLIENT("httpclient", LogLevel::WARN);
134134
LogTopic Logger::MAINTENANCE("maintenance", LogLevel::WARN);
135-
LogTopic Logger::MEMORY("memory", LogLevel::WARN);
135+
LogTopic Logger::MEMORY("memory", LogLevel::INFO);
136136
LogTopic Logger::MMAP("mmap");
137137
LogTopic Logger::PERFORMANCE("performance", LogLevel::WARN);
138138
LogTopic Logger::PREGEL("pregel", LogLevel::INFO);

0 commit comments

Comments
 (0)
0