Why yum_package resource is so slow?

Compared to just executing yum command it is very slow. Here is an example:

doing this in the cookbook:

['lvm2', 'wget', 'nano', 'mc', 'iptraf', 'tcpdump', 'curl', 'sysstat', 'vim', 'ntp', 'nfs-utils'].each do |x|
  yum_package x do
    action :install

results in execution time of 31 seconds. But doing this:

execute 'yum' do
  command 'yum install lvm2 wget nano mc iptraf tcpdump curl sysstat vim ntp nfs-utils -y'
  action :run

results in execution time of 12 seconds! Is it still this bug?

Playing with flush_cache property didn't help. Is there any fix besides using "execute" instead of "yum package"? BTW it was tested on CentOS 7.


yum_package ['lvm2', 'wget', 'nano', 'mc', 'iptraf', 'tcpdump', 'curl', 'sysstat', 'vim', 'ntp', 'nfs-utils'] do
  action :install

In the first example you are creating 11 yum_package resources and each one is going to have at least a little bit of overhead (both in ruby/chef and in yum executable). Not sure if this will be as fast as the execute resource alone (since this is going to be checking whether the packages are installed before taking action) but it should be at least somewhat faster than the original.

Thanks! It seems that you're right :slight_smile: Doing it the way that you described makes it much much faster, almost as fast as doing "execute yum install", but the difference now is small.