瀏覽代碼

Documented stresstest suite

Ask Solem 12 年之前
父節點
當前提交
2367ca669f
共有 2 個文件被更改,包括 117 次插入1 次删除
  1. 105 0
      funtests/stress/README.rst
  2. 12 1
      funtests/stress/stress.py

+ 105 - 0
funtests/stress/README.rst

@@ -0,0 +1,105 @@
+=========================
+ Celery Stresstest Suite
+=========================
+
+.. contents::
+    :local:
+
+Introduction
+============
+
+These tests will attempt to break the worker in different ways.
+
+The worker must currently be started separately, and it's encouraged
+to run the stresstest with different configuration values.
+
+Ideas include:
+
+1)  Frequent maxtasksperchild, single process
+
+::
+
+    $ celery -A stress worker -c 1 --maxtasksperchild=1
+
+2) Frequent scale down & maxtasksperchild, single process
+
+::
+
+    $ AUTOSCALE_KEEPALIVE=0.01 celery -A stress worker --autoscale=1,0 \
+                                                       --maxtasksperchild=1
+
+3) Frequent maxtasksperchild, multiple processes
+
+::
+
+    $ celery -A stress worker -c 8 --maxtasksperchild=1``
+
+4) Default, single process
+
+::
+
+    $ celery -A stress worker -c 1
+
+5) Default, multiple processes
+
+::
+
+    $ celery -A stress worker -c 8
+
+6) Processes termianted by time limits
+
+::
+
+    $ celery -A stress worker --time-limit=1
+
+7) Frequent maxtasksperchild, single process with late ack.
+
+::
+
+    $ celery -A stress worker -c1 --maxtasksperchild=1 -- celery.acks_late=1
+
+
+It's a good idea to include the ``--purge`` argument to clear out tasks from
+previous runs.
+
+Note that the stress client will probably hang if the test fails, so this
+test suite is currently not suited for automatic runs.
+
+Running the client
+------------------
+
+After the worker is running you can start the client to run the complete test
+suite::
+
+    $ python stress.py
+
+You can also specify which tests to run:
+
+    $ python stress.py revoketermfast revoketermslow
+
+Or you can start from an offset, e.g. to skip the two first tests use
+``--offset=2``::
+
+    $ python stress.py --offset=2
+
+See ``python stress.py --help`` for a list of all available options.
+
+
+Options
+=======
+
+Using a different result backend
+--------------------------------
+
+You can set the environment variable ``CSTRESS_BACKEND`` to change
+the result backend used::
+
+    $ CSTRESS_BACKEND='amqp://' celery -A stress worker #...
+    $ CSTRESS_BACKEND='amqp://' python stress.py
+
+Using a custom queue
+--------------------
+
+A queue named ``c.stress`` is created and used by default,
+but you can change the name of this queue using the ``CSTRESS_QUEUE``
+environment variable.

+ 12 - 1
funtests/stress/stress.py

@@ -9,6 +9,7 @@ import sys
 
 from time import time, sleep
 
+from kombu import Exchange, Queue
 from kombu.utils.compat import OrderedDict
 
 from celery import Celery, group, VERSION_BANNER
@@ -47,12 +48,22 @@ Celery stress-suite v{version}
 {toc}
 """
 
+CSTRESS_QUEUE = os.environ.get('CSTRESS_QUEUE_NAME', 'c.stress')
+CSTRESS_BACKEND = os.environ.get('CSTRESS_BACKEND', 'redis://')
+
 app = Celery(
-    'stress', broker='amqp://', backend='redis://',
+    'stress', broker='amqp://', backend=CSTRESS_BACKEND,
     set_as_current=False,
 )
 app.conf.update(
     CELERYD_PREFETCH_MULTIPLIER=10,
+    CELERY_DEFAULT_QUEUE=CSTRESS_QUEUE,
+    CELERY_QUEUES=(
+        Queue(CSTRESS_QUEUE,
+              exchange=Exchange(CSTRESS_QUEUE, durable=False),
+              routing_key=CSTRESS_QUEUE,
+              durable=False, auto_delete=True),
+    ),
 )