Skip to content

Commit 52b981a

Browse files
author
Naor Livne
committed
adding option to set containers based on workers memory
1 parent 3019c74 commit 52b981a

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

CONTRIBUTING

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ can help
77

88
* Fork the latest branch of the component you want to contribute to
99
* Make sure you have a [GitHub account](https://github.com/signup/free)
10-
* Use virtualenv to install all requirements from the requirements.txt file
11-
* Fix the issue you \ add a feature
10+
* Use virtualenv to install all requirements from the requirements.txt file, this will require having GCC compiler, python2-dev & linux-headers depending on your environment setup due to psutil requiring compilation on some OS.
11+
* Fix the issue you want \ add a feature
1212
* Create a pull request
1313

1414
## Design philosophy

functions/misc/server.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import multiprocessing, os, sys
1+
import multiprocessing, os, sys, psutil
22

33

44
# return numbers of cores
@@ -10,3 +10,15 @@ def get_number_of_cpu_cores():
1010
print >> sys.stderr, e
1111
print("error getting the number of cpu core")
1212
os._exit(2)
13+
14+
15+
# return numbers of cores
16+
def get_total_memory_size_in_mb():
17+
try:
18+
memory_in_bytes = psutil.virtual_memory()
19+
total_memory_in_mb = int(memory_in_bytes.total / 1024 / 1024)
20+
return total_memory_in_mb
21+
except Exception as e:
22+
print >> sys.stderr, e
23+
print("error getting the number of cpu core")
24+
os._exit(2)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ freeze==1.0.10
88
idna==2.7
99
ipaddress==1.0.22
1010
NebulaPythonSDK==2.0.0
11+
psutil==5.5.0
1112
requests==2.20.0
1213
retrying==1.3.3
1314
six==1.11.0

worker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ def containers_required(app_json):
156156
for scale_type, scale_amount in app_json["containers_per"].iteritems():
157157
if scale_type == "cpu":
158158
containers_needed = int(cpu_cores * scale_amount)
159+
elif scale_type == "memory" or scale_type == "mem":
160+
containers_needed = int(total_memory_size_in_mb / scale_amount)
159161
elif scale_type == "server" or scale_type == "instance":
160162
containers_needed = int(scale_amount)
161163
return containers_needed
@@ -214,6 +216,9 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
214216
# get number of cpu cores on host
215217
cpu_cores = get_number_of_cpu_cores()
216218

219+
# get total memory on the host in mb
220+
total_memory_size_in_mb = get_total_memory_size_in_mb()
221+
217222
# work against docker socket
218223
docker_socket = DockerFunctions()
219224

0 commit comments

Comments
 (0)