Yield to another greenthread when some time-consuming task finished.

Partially addresses bug #1045152

On a heavily loaded compute node, it can be observed that periodic tasks
take so long to run that the report_state() looping call can be blocked from
running long enough that the scheduler thinks the host is dead.

Reduce the chance of this happening by yielding to another greenthread
after each periodic task has completed and each loop in some methods
that has linear relationship with the number of instances.

Change-Id: If2b125708da8298b20497e2e08e52280c102f1e1
This commit is contained in:
TianTian Gao
2012-09-04 12:01:41 +08:00
committed by Alan Pevec
parent 2e75689c7c
commit 47dabb30dc
3 changed files with 10 additions and 1 deletions

View File

@@ -189,6 +189,7 @@ Stephanie Reese <reese.sm@gmail.com>
Sumit Naiksatam <snaiksat@cisco.com> Sumit Naiksatam <snaiksat@cisco.com>
Takaaki Suzuki <suzuki@midokura.com> Takaaki Suzuki <suzuki@midokura.com>
Thierry Carrez <thierry@openstack.org> Thierry Carrez <thierry@openstack.org>
TianTian Gao <gtt116@126.com>
Tim Simpson <tim.simpson@rackspace.com> Tim Simpson <tim.simpson@rackspace.com>
Todd Willey <todd@ansolabs.com> Todd Willey <todd@ansolabs.com>
Tomoe Sugihara <tomoe@midokura.com> Tomoe Sugihara <tomoe@midokura.com>

View File

@@ -53,6 +53,8 @@ This module provides Manager, a base class for managers.
""" """
import eventlet
from nova.db import base from nova.db import base
from nova import flags from nova import flags
from nova import log as logging from nova import log as logging
@@ -153,6 +155,9 @@ class Manager(base.Base):
try: try:
task(self, context) task(self, context)
# NOTE(tiantian): After finished a task, allow manager to
# do other work (report_state, processing AMPQ request etc.)
eventlet.sleep(0)
except Exception as e: except Exception as e:
if raise_on_error: if raise_on_error:
raise raise

View File

@@ -1777,6 +1777,8 @@ class LibvirtConnection(driver.ComputeDriver):
total += 1 total += 1
else: else:
total += len(vcpus[1]) total += len(vcpus[1])
# NOTE(gtt116): give change to do other task.
greenthread.sleep(0)
return total return total
def get_memory_mb_used(self): def get_memory_mb_used(self):
@@ -2337,7 +2339,8 @@ class LibvirtConnection(driver.ComputeDriver):
except exception.InstanceNotFound: except exception.InstanceNotFound:
# Instance was deleted during the check so ignore it # Instance was deleted during the check so ignore it
pass pass
# NOTE(gtt116): give change to do other task.
greenthread.sleep(0)
# Disk available least size # Disk available least size
available_least_size = dk_sz_gb * (1024 ** 3) - instances_sz available_least_size = dk_sz_gb * (1024 ** 3) - instances_sz
return (available_least_size / 1024 / 1024 / 1024) return (available_least_size / 1024 / 1024 / 1024)