Any advantage of using Salt commands vs cmd.run?

83 views
Skip to first unread message

mike r

unread,
Jun 24, 2015, 11:50:47 AM6/24/15
to salt-...@googlegroups.com
Wondering if execution time is faster using built in salt cmds vs cmd.run

salt target123 file.makedirs "/opt/mydir"  vs   salt target123 cmd.run "mkdir /opt/mydir"

is there any benefit of using salt cmd over native os cmds?

Boris FELD

unread,
Jun 24, 2015, 11:54:05 AM6/24/15
to salt-...@googlegroups.com
Salt commands are platform and OS agnostics.

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mike r

unread,
Jun 24, 2015, 12:08:37 PM6/24/15
to salt-...@googlegroups.com
gotcha thanks Boris. Is there any execution time benefit or is it a direct translator into a native OS cmd?

David Boucha

unread,
Jun 24, 2015, 12:31:55 PM6/24/15
to salt users list
Salt uses Python's os.mkdir.  So that's what you could compare against.

Seth Miller

unread,
Jun 24, 2015, 12:37:28 PM6/24/15
to salt-...@googlegroups.com
I guess that would depend on the command but I would say that any performance penalty for the abstracted Salt version would be minimal. A few more operations for conditionals and the like may have some impact won't make much of a difference.

Doing a very un-scientific test by timing the same operation in 2 different ways on the same minion come in nearly identical.

Personally, I try to always use the abstracted version if possible to avoid a re-write should I want to re-use a state for another OS. A minor performance penalty (even if there is one) is worth the abstraction to me.


~ $ time sudo salt 'REDACTED' file.makedirs '/tmp/test1/'
REDACTED:
   
None


real
0m0.645s
user
0m0.481s
sys
0m0.057s


~ $ time sudo salt 'REDACTED' cmd.run "mkdir /tmp/test2"
REDACTED:


real
0m0.642s
user
0m0.495s
sys
0m0.042s

Andrew Hammond

unread,
Jun 24, 2015, 7:55:18 PM6/24/15
to salt-...@googlegroups.com
For cases where salt is just running some python code, it's likely to be faster since it doesn't have the additional overhead of starting another process. However I think that worrying about execution time is a distraction when compared to and reliability. Also, if you're doing it right (using states), the real gain comes from the ability to _not_ execute commands.

A
Reply all
Reply to author
Forward
0 new messages