Commit c3a3661f authored by Christos Stavrakakis's avatar Christos Stavrakakis

cyclades: Speed up reconciliation

Speed up reconciliation by using mulitprocessing to get in parallel
the instances from all Ganeti backends.
parent ac04235f
......@@ -78,7 +78,8 @@ INSTALL_REQUIRES = [
'astakosclient',
'snf-django-lib',
'snf-branding',
'snf-webproject'
'snf-webproject',
'multiprocessing',
]
EXTRAS_REQUIRES = {
......
......@@ -32,6 +32,8 @@
# or implied, of GRNET S.A.
import json
import multiprocessing
import itertools
from django.conf import settings
from django.db import transaction
......@@ -641,13 +643,25 @@ def set_firewall_profile(vm, profile):
os_name=os_name)
def get_instances(backend, bulk, queue):
with pooled_rapi_client(backend) as client:
instances = client.GetInstances(bulk=bulk)
queue.put(instances)
def get_ganeti_instances(backend=None, bulk=False):
instances = []
for backend in get_backends(backend):
with pooled_rapi_client(backend) as client:
instances.append(client.GetInstances(bulk=bulk))
return reduce(list.__add__, instances, [])
backends = get_backends(backend)
queue = multiprocessing.Queue()
processes = []
for backend in backends:
p = multiprocessing.Process(target=get_instances,
args=(backend, bulk, queue))
processes.append(p)
p.start()
[p.join() for p in processes]
[instances.extend(queue.get()) for p in processes]
return instances
def get_ganeti_nodes(backend=None, bulk=False):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment