chef / ohai

Ohai profiles your system and emits JSON
https://docs.chef.io/ohai.html
Apache License 2.0
681 stars 452 forks source link

ohai extremely slow on VMware Fusion macOS VM with VMware Tools installed #1352

Open erikng opened 5 years ago

erikng commented 5 years ago

Description

When trying to run ohai under a macOS VM running VMware Fusion, it is extremely slow. This makes tools like kitchen converge and chef-client take several minutes when it should be just a few seconds during cookbook testing.

I have disabled a lot of plugins that are known to cause issues on macOS

ohai.disabled_plugins = [:Azure, :Cloud, :Cloudstack, :CloudV2, :EC2, :Eucalyptus, :GCE, :Joyent, :Linode, :Mdadm, :Openstack, :Passwd, :Rackspace, :Zpools]

Unfortunately ohai still takes over 60 seconds per run to finish.

real    1m6.914s
user    0m3.164s
sys    0m2.216s

Interestingly enough, once I bound this VM to an Active Directory domain, it's instantly faster.

real    0m5.054s
user    0m2.095s
sys 0m1.808s

I'm hoping you can lead me to the plugin that is having the issue.

Ohai Version

Ohai: 14.8.11

Platform Version

erikng commented 5 years ago

I think I might have found the culprit and it is the hostname plugin

[2019-04-22T09:20:15-07:00] TRACE: Plugin Hostname: ran 'hostname -s' and returned 0
[2019-04-22T09:20:15-07:00] TRACE: Plugin Hostname: ran 'hostname' and returned 0
[2019-04-22T09:20:15-07:00] TRACE: Plugin Hostname: ran 'hostname' and returned 0
[2019-04-22T09:20:45-07:00] TRACE: Plugin Hostname: hostname returned an empty string, retrying once.
[2019-04-22T09:20:45-07:00] TRACE: Plugin Hostname: ran 'hostname' and returned 0
[2019-04-22T09:21:15-07:00] TRACE: Plugin Hostname: hostname returned an empty string twice and willnot be set.
[2019-04-22T09:21:15-07:00] TRACE: Plugin Hostname took 0.02318400000000015 seconds to run.
erikng commented 5 years ago

Looks like it's this function: https://github.com/chef/ohai/blob/master/lib/ohai/plugins/hostname.rb#L47-L56

Perhaps this should have a timeout of 1-2 seconds?

erikng commented 5 years ago
vagrant-18E226:~ vagrant$ sudo scutil --get HostName     
vagrant-VM-564D8F6B
vagrant-18E226:~ vagrant$ sudo scutil --set HostName vagrant-VM-564D8F6B.test
vagrant-18E226:~ vagrant$ sudo scutil --get HostName
vagrant-VM-564D8F6B.test

so if I set the HostName (macs have ComputerName, LocalHostName and HostName) it instantly fixes the issue. These values may not be set by the user, so you definitely should write around this not existing.