salt icon indicating copy to clipboard operation
salt copied to clipboard

TCP tests show performance degredation over time

Open cachedout opened this issue 11 years ago • 15 comments

When running the test suite with --transport tcp and -m on the HEAD of the 2015.8 branch, some troubling slowdowns begin to occur midway through the test run, eventually slowing to 5+ seconds between tests, with some failing. These slowdowns and failures do not occur with the ZeroMQ tests.

When tailing '/tmp/salt-runtests.log`, this type of error begins to become very frequent around the time the tests begin to slow:

14:45:02,558 [salt.minion                             :1272][WARNING ] The minion failed to return the job information for job 20150805144402014451. This is often due to the master being shut down or overloaded. If the master is running consider increasing the worker_threads value.

By default, the test runner starts up a master with worker_threads: 3. (As specified in salt/tests/integration/files/conf/master. However, any attempt to increase the number of threads beyond three seems to prevent the minions from connecting initally at all, and thusly, the test suite does not even run. It simply hangs for two minutes prior to the module and state sync and then times out and exits.

I have attempted to adjust the value of the backlog variable up from 5 (which does not seem to be supported by *NIX systems) and downward toward zero. Moving it upward has no effect and moving it downwards seems to make the above warning message appear earlier and more frequently, though this is only a casual observation.

At present, the slowdowns are siginficant enough to prevent the entire test suite from completing in under three hours, while the ZeroMQ side takes about twenty-five to thirty minutes.

No performance degredation is observed when simply using Salt via the CLI.

cc: @jacksontj, @thatch45

cachedout avatar Aug 05 '15 21:08 cachedout

Something is blocking the IOLoop from doing it's job...

s0undt3ch avatar Aug 06 '15 14:08 s0undt3ch

Is this still the case? I'm not back from vacation, and can look into these sorts of things :) I know @cachedout was working on some of this, not sure if they were actually related or not

jacksontj avatar Sep 03 '15 15:09 jacksontj

@jacksontj Sadly, I got pulled away from this and so far as I am aware, this is still the case. I won't be able to peek at it today, but can get any info you need if you have time to start looking. I would love to get TCP automated tests going again in Jenkins. That would be sweet!

cachedout avatar Sep 03 '15 16:09 cachedout

Committed for Boron

meggiebot avatar Sep 16 '15 20:09 meggiebot

Two cents' worth; normally when I use threading in python (in any way...) I end up with problems in high performance environments... (think GIL). For high performance parallelism I often fork (CPU intensive tasks) and for concurrency I use greenlets (I/O intensive tasks).

Greenlets really shine in network programming where interactions with one socket can occur independently of interactions with other sockets. This is a classic example of concurrency. Because each greenlet runs in its own context, you can continue to use synchronous APIs without threading. This is good because threads are very expensive in terms of virtual memory and kernel overhead, so the concurrency you can achieve with threads is significantly less. Additionally, threading in Python is more expensive and more limited than usual due to the GIL. Explanation from; http://stackoverflow.com/a/15596277

Since salt is very I/O intensive it's worth looking at greenlets in general and in the TCP transport in particular.

A toy example;

#!/usr/bin/env python

import gevent
import random
import timeit

def task(pid):
    task_sleep = random.random() * 5
    print('Task %s sleep: %s' % (pid, task_sleep))
    gevent.sleep(task_sleep)
    print('Task %s done' % pid)

def synchronous():
    for i in range(10):
        task(i)

def asynchronous():
    threads = [gevent.spawn(task, i) for i in range(10)]
    gevent.joinall(threads)


print('Synchronous:')
wall_time = timeit.timeit(synchronous, number=1) 
print('Time taken: %f' % wall_time)


print('Asynchronous:')
wall_time =timeit.timeit(asynchronous, number=1) 
print('Time taken: %f' % wall_time)

Please ignore me when I'm out of line,

Regards, Onno

anonymouz avatar Nov 04 '15 09:11 anonymouz

Greenlets where actually the runner-up when considering an async framework for salt. As you mentioned salt is quite IO intensive, so we needed some form of async controls. We ended chosing tornado for two basic reasons:

(1) it plays nice with other libraries. Gevent is based on implicit instead of explicit yields, as such it needs to monkey-patch libraries to yield in various places. Although this works in general-- for a plugin based system such as salt this introduces a lot of weird problems for module writers. Primary of which is what will socket look like in my module? Some of these problems could be worked around, but at the end of the day to get a lot of the benefit from gevent we'd have to do quite a bit of magic.

(2) It's where python is going The new asyncio (tulip) upstream was heavily based on tornado (and in python 3, tornado is just a thin wrapper). Since this the direction python is going for async coroutine-style activities, it seems to make sense to follow suit.

Now you did mention that threads don't perform well in parallel in python-- which is true. That is why salt uses a combination of coroutines and processes to accomplish concurrent tasks. AFAIK the only threads we support are the reactor (just until we move it all to coroutines) and the minion (if you disable multiprocessing-- IIRC that seems to be good for Windows people or something?).

jacksontj avatar Nov 04 '15 15:11 jacksontj

For some additional clarification, I've ported your example to coroutines:

#!/usr/bin/env python

import tornado.ioloop
import tornado.gen
import random
import time

@tornado.gen.coroutine
def task(pid):
    task_sleep = random.random() * 5
    print('Task %s sleep: %s' % (pid, task_sleep))
    yield tornado.gen.sleep(task_sleep)
    print('Task %s done' % pid)

def sync_task(pid):
    task_sleep = random.random() * 5
    print('Task %s sleep: %s' % (pid, task_sleep))
    time.sleep(task_sleep)
    print('Task %s done' % pid)

def synchronous():
    for i in range(10):
        sync_task(i)

@tornado.gen.coroutine
def asynchronous():
    futures = [task(i) for i in range(10)]
    yield futures


print('Synchronous:')
start = time.time()
tornado.ioloop.IOLoop.current().run_sync(synchronous)
wall_time = time.time() - start
print('Time taken: %f' % wall_time)


print('Asynchronous:')
start = time.time()
tornado.ioloop.IOLoop.current().run_sync(asynchronous)
wall_time = time.time() - start
print('Time taken: %f' % wall_time)

As you can see above we are still yielding execution within the process to other tasks (coroutines), so at the end of the day its quite similar. The real difference is explicit vs. implicit yields.

jacksontj avatar Nov 04 '15 15:11 jacksontj

The test case I included above does not exhibit the slowdown after the fix by @skizunov in #28614. Marking as 'Fixed Pending Verification'.

cachedout avatar Nov 05 '15 21:11 cachedout

@jacksontj Thanks for the explanation! The "It's where python is going" argument is a particular strong one in this case. Your ported example is great, thanks for that.

I'll take your considerations and example as input for future considerations! (and probably use it!)

Thanks, Onno

anonymouz avatar Nov 06 '15 08:11 anonymouz

@cachedout can you start a run of the tests in jenkins to see if they still exhibit the slowdown? If not we can probably close this out, otherwise we'll have to keep digging :).

jacksontj avatar Nov 06 '15 16:11 jacksontj

We need to backport some stuff to 2015.8 since that's where the TCP tests are and then I'll get them back up. Though, my local test results thus far have been very encouraging.

On Fri, Nov 6, 2015 at 9:00 AM, Thomas Jackson [email protected] wrote:

@cachedout https://github.com/cachedout can you start a run of the tests in jenkins to see if they still exhibit the slowdown? If not we can probably close this out, otherwise we'll have to keep digging :).

— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/26051#issuecomment-154448037.

cachedout avatar Nov 06 '15 17:11 cachedout

If you are backporting, then I suggest both these pull requests are important: #28530, #28614.

skizunov avatar Nov 06 '15 18:11 skizunov

Thanks, @skizunov. I got one but missed the other. We'll get it in right away.

On Fri, Nov 6, 2015 at 11:45 AM, skizunov [email protected] wrote:

If you are backporting, then I suggest both these pull requests are important: #28530 https://github.com/saltstack/salt/pull/28530, #28614 https://github.com/saltstack/salt/pull/28614.

— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/26051#issuecomment-154498543.

cachedout avatar Nov 06 '15 18:11 cachedout

The TCP tests are now fully back online and passing. Closing issue. Thanks everyone.

cachedout avatar Nov 12 '15 22:11 cachedout

:balloon: :+1: :tada:

rallytime avatar Nov 12 '15 23:11 rallytime