-->

Taking a long time to execute a saltstack command

2019-09-18 03:28发布

问题:

I was trying to execute this saltstack command cmd = "/usr/local/bin/salt -L 'target' cp.get_dir salt://allapps/V001 /u02/tomcat-8.0.24/8080/webapps/" output = os.popen(cmd).readlines() using python. I have started 8 threads in parallel to run this command, but each thread costs about 5 min to finish. But I run this command in terminal or python console standalone, it just takes me about 2-3 secs to complete. First I thought it was because of readlines() consuming lots of memory, but it still costs 5 min more to finish when I removed readlines() just to run the shell command with os.popen(). I have no idea why it takes so much time to run this command, any solutions to this? Thx guys

I have found that it consumes around 5 sec to execute output = os.popen("/usr/local/bin/salt -L 'target' cp.get_dir salt://allapps/V001 /u02/tomcat-8.0.24/8080/webapps/") other than output = os.popen(cmd). The variable cmd is exactly the same with "/usr/local/bin/salt -L 'target' cp.get_dir salt://allapps/V001 /u02/tomcat-8.0.24/8080/webapps/". Why there is so much difference?

回答1:

I'm not sure why that command is taking so long. Have you considered using Salt's python api? https://docs.saltstack.com/en/latest/ref/clients/index.html#python-api