Skip to content

Commit

Permalink
Add configuration option to enable/disable migration at checkout
Browse files Browse the repository at this point in the history
This commit adds support for a configuration setting called
migration_limit that makes migration at checkout optional. Additionally,
logging is added to report a VM parent host when it is checked out. Without this
change vmpooler assumes that migration at checkout is always enabled.
If this setting is not present, or if the setting is 0, then migration
at checkout will be disabled. If the setting is greater than 0 then that
setting will be used to enforce a limit for the number of simultaneous
migrations that will be evaluated.

Documentation of this configuration option is added to the
vmpooler.yaml.example file.
  • Loading branch information
mattkirby committed Oct 28, 2016
1 parent 9b9ecec commit ff46bfc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
38 changes: 27 additions & 11 deletions lib/vmpooler/pool_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -468,20 +468,36 @@ def migrate_vm(vm, pool)
def _migrate_vm(vm, pool)
$redis.srem('vmpooler__migrating__' + pool, vm)
vm_object = find_vsphere_pool_vm(pool, vm)
host = $vsphere[pool].find_least_used_compatible_host(vm_object)
parent_host = vm_object.summary.runtime.host
parent_host_name = parent_host.name
if host == parent_host
$logger.log('s', "[ ] [#{pool}] No migration required for '#{vm}'")
# Check if migration_limit is set
migration_limit = $config[:config]['migration_limit']
# Ensure migration is disabled when migration_limit is set to 0
migration_limit = nil unless migration_limit != 0

if not migration_limit
$logger.log('s', "[ ] [#{pool}] '#{vm}' is running on #{parent_host_name}")
else
start = Time.now
$vsphere[pool].migrate_vm_host(vm_object, host)
finish = '%.2f' % (Time.now - start)
$metrics.timing("migrate.#{vm['template']}", finish)
checkout_to_migration = '%.2f' % (Time.now - Time.parse($redis.hget('vmpooler__vm__' + vm, 'checkout')))
$redis.hset('vmpooler__vm__' + vm, 'migration_time', finish)
$redis.hset('vmpooler__vm__' + vm, 'checkout_to_migration', checkout_to_migration)
$logger.log('s', "[>] [#{pool}] '#{vm}' migrated from #{parent_host_name} to #{host.name} in #{finish} seconds")
migration_count = $redis.smembers('vmpooler__migration').size
if migration_count >= migration_limit
$logger.log('s', "[ ] [#{pool}] '#{vm}' is running on #{parent_host_name}. No migration will be evaluated since the migration_limit has been reached")
else
$redis.sadd('vmpooler__migration', vm)
host = $vsphere[pool].find_least_used_compatible_host(vm_object)
if host == parent_host
$logger.log('s', "[ ] [#{pool}] No migration required for '#{vm}'")
else
start = Time.now
$vsphere[pool].migrate_vm_host(vm_object, host)
finish = '%.2f' % (Time.now - start)
$metrics.timing("migrate.#{vm['template']}", finish)
checkout_to_migration = '%.2f' % (Time.now - Time.parse($redis.hget('vmpooler__vm__' + vm, 'checkout')))
$redis.hset('vmpooler__vm__' + vm, 'migration_time', finish)
$redis.hset('vmpooler__vm__' + vm, 'checkout_to_migration', checkout_to_migration)
$logger.log('s', "[>] [#{pool}] '#{vm}' migrated from #{parent_host_name} to #{host.name} in #{finish} seconds")
end
$redis.srem('vmpooler__migration', vm)
end
end
end

Expand Down
7 changes: 7 additions & 0 deletions vmpooler.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@
# If set, prefixes all created VMs with this string. This should include
# a separator.
# (optional; default: '')
#
# - migration_limit
# When set to any value greater than 0 enable VM migration at checkout.
# When enabled this capability will evaluate a VM for migration when it is requested
# in an effort to maintain a more even distribution of load across compute resources.
# The migration_limit ensures that no more than n migrations will be evaluated at any one time
# and greatly reduces the possibilty of VMs ending up bunched together on a particular host.

# Example:

Expand Down

0 comments on commit ff46bfc

Please sign in to comment.