Skip to content

Instantly share code, notes, and snippets.

@pcn
Last active April 12, 2017 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcn/6d3928139a633c1f51d542a6643d1e6b to your computer and use it in GitHub Desktop.
Save pcn/6d3928139a633c1f51d542a6643d1e6b to your computer and use it in GitHub Desktop.
Looking up jids takes a lot longer than you'd think in salt
import salt.config
import salt.runner
import salt.client
import time
import cProfile
o = salt.config.client_config("/etc/salt/master")
l = salt.client.LocalClient()
rc = salt.runner.RunnerClient(o)
start_time = time.time()
jids = list()
for count in range(10, 20):
jids.append(l.cmd_async('saltmaster', 'cmd.run', ['sleep {}; date'.format(count)]))
print "adding jobs took {}".format(time.time() - start_time)
start_time = time.time()
print "jids are: {}".format(jids)
# pr = cProfile.Profile()
# pr.enable()
import salt.minion
mm = salt.minion.MasterMinion(o)
o.get('ext_job_cache')
start_time = time.time()
jc = o.get('master_job_cache')
for jid in jids:
mm.returners['{}.get_jid'.format(jc)](jid)
print "Looking up {} jobs via returner, took {}".format(len(jids), time.time() - start_time)
for jid in jids:
rc.cmd('jobs.lookup_jid', [jid])
#pr.disable()
print "Looking up {} jobs, took {}".format(len(jids), time.time() - start_time)
# pr.print_stats(sort='time')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment