salt icon indicating copy to clipboard operation
salt copied to clipboard

grains.get high cpu usage

Open Phomias opened this issue 10 years ago • 4 comments

Description of Issue/Question

Sometimes I find grains.get stuck at high CPU usage seemingly forever.

Below find stack traces.

Setup

Set up a salt master a few minions. On the master set up a cron job like this:

owner-grains-cache-cron:
  cron:
    - present
    - name: "salt '*' grains.get owner --out=json --static > '{{ app }}/owner-grains.json.partial' && chown apache:apache '{{ app }}/owner-grains.json.partial' && mv '{{ app }}/owner-grains.json.partial' '{{ app }}/owner-grains.json'"
    - user: root
    - minute: '*/10'
    - identifier: owner-grains-cache-cron

Steps to Reproduce Issue

Wait, a few days and you may find this, as I have:

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
12796 root      20   0  605m  29m    0 R 96.9  0.8  11822:39 /usr/bin/python2.6 /usr/bin/salt * grains.get owner --out=json --static

(note to myself, I used nc -l 9001 & pyrasite [pid] reverse_python_shell.py to connect to the unprepared python process and get some stacktraces with [(traceback.print_stack(stack),traceback.print_stack(stack)) for tid,stack in sys._current_frames().items()] )

Stacktrace:

  File "/usr/bin/salt", line 10, in <module>
    salt_main()
  File "/usr/lib/python2.6/site-packages/salt/scripts.py", line 349, in salt_main
    client.run()
  File "/usr/lib/python2.6/site-packages/salt/cli/salt.py", line 88, in run
    batch = salt.cli.batch.Batch(self.config, eauth=eauth, quiet=True)
  File "/usr/lib/python2.6/site-packages/salt/cli/batch.py", line 30, in __init__
    self.minions, self.ping_gen = self.__gather_minions()
  File "/usr/lib/python2.6/site-packages/salt/cli/batch.py", line 52, in __gather_minions
    for ret in ping_gen:
  File "/usr/lib/python2.6/site-packages/salt/client/__init__.py", line 658, in cmd_iter
    **kwargs):
  File "/usr/lib/python2.6/site-packages/salt/client/__init__.py", line 883, in get_iter_returns
    for raw in ret_iter:
  File "/usr/lib/python2.6/site-packages/salt/client/__init__.py", line 819, in get_returns_no_block
    raw = self.event.get_event(wait=0.01, tag='salt/job/{0}'.format(jid), tags_regex=tags_regex, full=True)
  File "/usr/lib/python2.6/site-packages/salt/utils/event.py", line 410, in get_event
    ret = self._get_event(wait, tag, tags_regex)
  File "/usr/lib/python2.6/site-packages/salt/utils/event.py", line 351, in _get_event
    socks = dict(self.poller.poll(wait * 1000))
  File "/usr/lib64/python2.6/site-packages/zmq/sugar/poll.py", line 101, in poll
    return zmq_poll(self.sockets, timeout=timeout)

Stacktrace a few minutes later:

  File "/usr/bin/salt", line 10, in <module>
    salt_main()
  File "/usr/lib/python2.6/site-packages/salt/scripts.py", line 349, in salt_main
    client.run()
  File "/usr/lib/python2.6/site-packages/salt/cli/salt.py", line 88, in run
    batch = salt.cli.batch.Batch(self.config, eauth=eauth, quiet=True)
  File "/usr/lib/python2.6/site-packages/salt/cli/batch.py", line 30, in __init__
    self.minions, self.ping_gen = self.__gather_minions()
  File "/usr/lib/python2.6/site-packages/salt/cli/batch.py", line 52, in __gather_minions
    for ret in ping_gen:
  File "/usr/lib/python2.6/site-packages/salt/client/__init__.py", line 658, in cmd_iter
    **kwargs):
  File "/usr/lib/python2.6/site-packages/salt/client/__init__.py", line 883, in get_iter_returns
    for raw in ret_iter:
  File "/usr/lib/python2.6/site-packages/salt/client/__init__.py", line 819, in get_returns_no_block
    raw = self.event.get_event(wait=0.01, tag='salt/job/{0}'.format(jid), tags_regex=tags_regex, full=True)
  File "/usr/lib/python2.6/site-packages/salt/utils/event.py", line 410, in get_event
    ret = self._get_event(wait, tag, tags_regex)
  File "/usr/lib/python2.6/site-packages/salt/utils/event.py", line 352, in _get_event
    if socks.get(self.sub) != zmq.POLLIN:

Versions Report

Provided by running salt --versions-report

           Salt: 2015.5.8
         Python: 2.6.9 (unknown, Dec 17 2015, 01:08:55)
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
 msgpack-python: 0.4.6
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 14.3.1
           RAET: Not Installed
            ZMQ: 3.2.5
           Mako: Not Installed
        Tornado: 4.1
        timelib: Not Installed
       dateutil: 2.1

Phomias avatar Mar 04 '16 10:03 Phomias

Do you have batch mode configured in your config? You shouldn't be hitting salt.cli.batch unless you do.

cachedout avatar Mar 04 '16 20:03 cachedout

I am not using -b. Is there another way to turn batch mode on?

Phomias avatar Mar 04 '16 21:03 Phomias

Ah, my fault. I forgot batch mode gets enabled by virtue of using --static

cachedout avatar Mar 04 '16 21:03 cachedout

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Apr 03 '18 21:04 stale[bot]