Commit 35ca156d authored by Sergios Aftsidis's avatar Sergios Aftsidis
Browse files

Use gevent.pool and limit active greenlets

parent fa8d1f59
......@@ -7,7 +7,13 @@ from django.conf import settings
from network.models import Ifce
from rg.models import Graph
import gevent
# import gevent
from gevent.pool import Pool
pool = Pool(CONCURRECY)
def last_x_rec(x):
......@@ -86,10 +92,15 @@ def get_load_for_interfaces(ifces, key, start=None, end=None):
def get_load_for_links(ifces, start=None, end=None):
response = {}
threads = []
spawned = 0
for key, val in ifces.iteritems():
# response.update(get_load_for_interfaces(val, key, start, end))
threads.append(gevent.spawn(get_load_for_interfaces, val, key, start, end))
threads.append(pool.spawn(get_load_for_interfaces, val, key, start, end))
spawned += 1
if spawned == CONCURRECY:
for thread in threads:
if thread.value:
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