Skip to content

Slow Knife? Speed up with Knife rehash

The Chef DK includes a tool called Knife. This is primarily used for interaction with remote resources in Chef, such as the Chef Server and Chef managed nodes, but can be used for managing other remote systems too. Here’s the description from the Chef Docs.

knife is a command-line tool that provides an interface between a local chef-repo and the Chef server.

It’s a great tool and a vital part of any Chef administration tasks. Unfortunately Ruby on Windows is slower than Linux and so Windows users sometimes experience performance issues. Check out the result of the following running on my top-spec Ultrabook running Windows 10:

A wait of 6 seconds every time I want to run the commonly used knife node list is not ideal. Fortunately a knife command that comes with the Chef DK by default is available to address this issue.

Using knife rehash we can create a cache of the local knife sub commands on disk. When knife runs it no longer builds a tree of available sub commands, which reduces execution time.

After creating the cache the knife node list command performance is greatly improved.

There are some caveats:

  • If you install a new Knife gem or plugin you need to re-run knife rehash.
  • The same applies for a chef DK update- don’t forget knife rehash!
  • If you get strange output with Knife it’s worth trying a knife rehash before debugging further.

Finally, if you want to stop using the cache just delete the JSON file. On Windows it’s here: C:/Users/<username>/.chef/plugin_manifest.json

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *