|
1 | 1 | # MRQ |
2 | 2 |
|
3 | | -Mongo Redis Queue - A distributed worker task queue in Python |
| 3 | +[MRQ](http://pricingassistant.github.io/mrq) is a distributed task queue for python built on top of mongo, redis and gevent. |
4 | 4 |
|
5 | | -Full documentation is available on [readthedocs]() |
| 5 | +Full documentation is available on [readthedocs](http://mrq.readthedocs.org/en/latest/) |
6 | 6 |
|
7 | 7 | /!\ MRQ is not yet ready for public use. Soon! |
8 | 8 |
|
9 | 9 | # Why? |
10 | 10 |
|
11 | | -MRQ is an opinionated task queue. It aims to be simple and beautiful like http://python-rq.org while having performance close to http://celeryproject.org |
| 11 | +MRQ is an opinionated task queue. It aims to be simple and beautiful like [RQ](http://python-rq.org) while having performances close to [Celery](http://celeryproject.org) |
12 | 12 |
|
13 | | -MRQ was first developed at http://pricingassistant.com and its initial feature set matches the needs of worker queues with heterogenous jobs (IO-bound & CPU-bound, lots of small tasks & a few large ones). |
| 13 | +MRQ was first developed at [Pricing Assistant](http://pricingassistant.com) and its initial feature set matches the needs of worker queues with heterogenous jobs (IO-bound & CPU-bound, lots of small tasks & a few large ones). |
14 | 14 |
|
15 | | -The main features of MRQ are: |
| 15 | +# Main Features |
16 | 16 |
|
17 | 17 | * **Simple code:** We originally switched from Celery to RQ because Celery's code was incredibly complex and obscure ([Slides](http://www.slideshare.net/sylvinus/why-and-how-pricing-assistant-migrated-from-celery-to-rq-parispy-2)). MRQ should be as easy to understand as RQ and even easier to extend. |
18 | | - * **Great dashboard:** Have visibility and control on everything: queued jobs, current jobs, worker status, ... |
| 18 | + * **Great [dashboard](dashboard.md):** Have visibility and control on everything: queued jobs, current jobs, worker status, ... |
19 | 19 | * **Per-job logs:** Get the log output of each task separately in the dashboard |
20 | 20 | * **Gevent worker:** IO-bound tasks can be done in parallel in the same UNIX process for maximum throughput |
21 | 21 | * **Supervisord integration:** CPU-bound tasks can be split across several UNIX processes with a single command-line flag |
22 | 22 | * **Job management:** You can retry, requeue, cancel jobs from the code or the dashboard. |
23 | 23 | * **Performance:** Bulk job queueing, easy job profiling |
24 | | - * **Easy configuration:** Every aspect of MRQ is configurable through command-line flags or a configuration file |
| 24 | + * **Easy [configuration](configuration.md):** Every aspect of MRQ is configurable through command-line flags or a configuration file |
25 | 25 | * **Job routing:** Like Celery, jobs can have default queues, timeout and ttl values. |
26 | | - * **Thorough testing:** Edge-cases like worker interrupts, Redis failures, ... are tested inside a Docker container. |
| 26 | + * **Thorough [testing](tests.md):** Edge-cases like worker interrupts, Redis failures, ... are tested inside a Docker container. |
27 | 27 | * **Builtin scheduler:** Schedule tasks by interval or by time of the day |
28 | 28 | * **Greenlet tracing:** See how much time was spent in each greenlet to debug CPU-intensive jobs. |
29 | 29 | * **Integrated memory leak debugger:** Track down jobs leaking memory and find the leaks with objgraph. |
30 | 30 |
|
31 | | - |
32 | | -# Dashboard Screnshots |
| 31 | +# Dashboard Screenshots |
33 | 32 |
|
34 | 33 |  |
35 | 34 |
|
36 | 35 |  |
37 | 36 |
|
38 | 37 | # Get Started |
39 | 38 |
|
40 | | - |
| 39 | + - Make sure you have installed the [dependencies](https://mrq.readthedocs.org/en/latest/dependencies/) : Redis and Mongo |
| 40 | + - Install MRQ with `pip install mrq` |
| 41 | + - Start a mongo server with `mongod &` |
| 42 | + - Start a redis server with `redis-server &` |
| 43 | + |
| 44 | + |
| 45 | +Create a sample project and write a simple task : |
| 46 | +``` |
| 47 | + $ mkdir test-mrq && cd test-mrq |
| 48 | + $ touch __init__.py |
| 49 | + $ vim tasks.py |
| 50 | +``` |
| 51 | + |
| 52 | + |
| 53 | + from mrq.task import Task |
| 54 | + import urllib2 |
| 55 | + |
| 56 | + class Fetch(Task): |
| 57 | + def run(self, params): |
| 58 | + f = urllib2.urlopen(params.get("url")) |
| 59 | + t = f.read() |
| 60 | + f.close() |
| 61 | + return len(t) |
| 62 | + |
| 63 | +You can now run it using `mrq-run` : |
| 64 | +``` |
| 65 | +$ mrq-run tasks.Fetch url http://www.google.com |
| 66 | +
|
| 67 | +2014-12-18 15:44:37.869029 [DEBUG] mongodb_jobs: Connecting to MongoDB at 127.0.0.1:27017/mrq... |
| 68 | +2014-12-18 15:44:37.880115 [DEBUG] mongodb_jobs: ... connected. |
| 69 | +2014-12-18 15:44:37.880305 [DEBUG] Starting tasks.Fetch({'url': 'http://www.google.com'}) |
| 70 | +2014-12-18 15:44:38.158572 [DEBUG] Job None success: 0.278229s total |
| 71 | +17655 |
| 72 | +``` |
| 73 | + |
| 74 | +You can also enqueue a few tasks with |
| 75 | +``` |
| 76 | +$ mrq-run --async --queue fetches tasks.Fetch url http://www.google.com && |
| 77 | + mrq-run --async --queue fetches tasks.Fetch url http://www.yahoo.com && |
| 78 | + mrq-run --async --queue fetches tasks.Fetch url http://www.wordpress.com |
| 79 | +
|
| 80 | +2014-12-18 15:49:05.688627 [DEBUG] mongodb_jobs: Connecting to MongoDB at 127.0.0.1:27017/mrq... |
| 81 | +2014-12-18 15:49:05.705400 [DEBUG] mongodb_jobs: ... connected. |
| 82 | +2014-12-18 15:49:05.729364 [INFO] redis: Connecting to Redis at 127.0.0.1... |
| 83 | +5492f771520d1887bfdf4b0f |
| 84 | +2014-12-18 15:49:05.957912 [DEBUG] mongodb_jobs: Connecting to MongoDB at 127.0.0.1:27017/mrq... |
| 85 | +2014-12-18 15:49:05.967419 [DEBUG] mongodb_jobs: ... connected. |
| 86 | +2014-12-18 15:49:05.983925 [INFO] redis: Connecting to Redis at 127.0.0.1... |
| 87 | +5492f771520d1887c2d7d2db |
| 88 | +2014-12-18 15:49:06.182351 [DEBUG] mongodb_jobs: Connecting to MongoDB at 127.0.0.1:27017/mrq... |
| 89 | +2014-12-18 15:49:06.193314 [DEBUG] mongodb_jobs: ... connected. |
| 90 | +2014-12-18 15:49:06.209336 [INFO] redis: Connecting to Redis at 127.0.0.1... |
| 91 | +5492f772520d1887c5b32881 |
| 92 | +``` |
| 93 | + |
| 94 | +Now start the dasbhoard with `mrq-dashboard &` and go check your newly created queue and job on [localhost:5555](http://localhost:5555/#jobs) |
| 95 | + |
| 96 | +Instanciate a worker with `mrq-worker` and you can follow it on the dashboard as it executes in parallel all the enqueued jobs |
| 97 | + |
| 98 | +``` |
| 99 | +$ mrq-worker --gevent 10 fetches |
| 100 | +
|
| 101 | +2014-12-18 15:52:57.362209 [INFO] Starting Gevent pool with 10 worker greenlets (+ report, logs, adminhttp) |
| 102 | +2014-12-18 15:52:57.388033 [INFO] redis: Connecting to Redis at 127.0.0.1... |
| 103 | +2014-12-18 15:52:57.389488 [DEBUG] mongodb_jobs: Connecting to MongoDB at 127.0.0.1:27017/mrq... |
| 104 | +2014-12-18 15:52:57.390996 [DEBUG] mongodb_jobs: ... connected. |
| 105 | +2014-12-18 15:52:57.391336 [DEBUG] mongodb_logs: Connecting to MongoDB at 127.0.0.1:27017/mrq... |
| 106 | +2014-12-18 15:52:57.392430 [DEBUG] mongodb_logs: ... connected. |
| 107 | +2014-12-18 15:52:57.523329 [INFO] Fetching 10 jobs from ['fetches'] |
| 108 | +2014-12-18 15:52:57.537570 [DEBUG] Starting tasks.Fetch({u'url': u'http://www.google.com'}) |
| 109 | +2014-12-18 15:52:57.567311 [DEBUG] Starting tasks.Fetch({u'url': u'http://www.google.com'}) |
| 110 | +2014-12-18 15:52:57.567747 [DEBUG] Starting tasks.Fetch({u'url': u'http://www.yahoo.com'}) |
| 111 | +2014-12-18 15:52:57.568080 [DEBUG] Starting tasks.Fetch({u'url': u'http://www.wordpress.com'}) |
| 112 | +2014-12-18 15:52:57.798167 [INFO] Fetching 6 jobs from ['fetches'] |
| 113 | +2014-12-18 15:52:58.432574 [INFO] Fetching 6 jobs from ['fetches'] |
| 114 | +2014-12-18 15:52:58.670492 [DEBUG] Job 5492f771520d1887bfdf4b0f success: 1.135268s total |
| 115 | +2014-12-18 15:52:59.344227 [DEBUG] Job 5492f74b520d1887a38dd7c8 success: 1.816439s total |
| 116 | +2014-12-18 15:52:59.912086 [INFO] Fetching 8 jobs from ['fetches'] |
| 117 | +2014-12-18 15:53:00.685727 [DEBUG] Job 5492f772520d1887c5b32881 success: 3.149119s total |
| 118 | +2014-12-18 15:53:01.578981 [INFO] Fetching 9 jobs from ['fetches'] |
| 119 | +2014-12-18 15:53:01.897873 [DEBUG] Job 5492f771520d1887c2d7d2db success: 4.361895s total |
| 120 | +2014-12-18 15:53:03.415555 [INFO] Fetching 10 jobs from ['fetches'] |
| 121 | +``` |
41 | 122 |
|
42 | 123 | # More |
43 | 124 |
|
| 125 | +Full documentation is available on [readthedocs](http://mrq.readthedocs.org/en/latest/) |
0 commit comments