Skip to content

Commit

Permalink
adding option to set containers based on workers memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Naor Livne committed Feb 13, 2019
1 parent 3019c74 commit 52b981a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ can help

* Fork the latest branch of the component you want to contribute to
* Make sure you have a [GitHub account](https://github.com/signup/free)
* Use virtualenv to install all requirements from the requirements.txt file
* Fix the issue you \ add a feature
* 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.
* Fix the issue you want \ add a feature
* Create a pull request

## Design philosophy
Expand Down
14 changes: 13 additions & 1 deletion functions/misc/server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import multiprocessing, os, sys
import multiprocessing, os, sys, psutil


# return numbers of cores
Expand All @@ -10,3 +10,15 @@ def get_number_of_cpu_cores():
print >> sys.stderr, e
print("error getting the number of cpu core")
os._exit(2)


# return numbers of cores
def get_total_memory_size_in_mb():
try:
memory_in_bytes = psutil.virtual_memory()
total_memory_in_mb = int(memory_in_bytes.total / 1024 / 1024)
return total_memory_in_mb
except Exception as e:
print >> sys.stderr, e
print("error getting the number of cpu core")
os._exit(2)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ freeze==1.0.10
idna==2.7
ipaddress==1.0.22
NebulaPythonSDK==2.0.0
psutil==5.5.0
requests==2.20.0
retrying==1.3.3
six==1.11.0
Expand Down
5 changes: 5 additions & 0 deletions worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def containers_required(app_json):
for scale_type, scale_amount in app_json["containers_per"].iteritems():
if scale_type == "cpu":
containers_needed = int(cpu_cores * scale_amount)
elif scale_type == "memory" or scale_type == "mem":
containers_needed = int(total_memory_size_in_mb / scale_amount)
elif scale_type == "server" or scale_type == "instance":
containers_needed = int(scale_amount)
return containers_needed
Expand Down Expand Up @@ -214,6 +216,9 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
# get number of cpu cores on host
cpu_cores = get_number_of_cpu_cores()

# get total memory on the host in mb
total_memory_size_in_mb = get_total_memory_size_in_mb()

# work against docker socket
docker_socket = DockerFunctions()

Expand Down

0 comments on commit 52b981a

Please sign in to comment.