GithubHelp home page GithubHelp logo

simudream / taskmaster Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dcramer/taskmaster

0.0 2.0 0.0 270 KB

A simple distributed queue designed for handling one-off tasks with large sets of tasks

License: Apache License 2.0

Makefile 0.11% Python 99.89%

taskmaster's Introduction

Taskmaster

Taskmaster is a simple distributed queue designed for handling large numbers of one-off tasks.

We built this at DISQUS to handle frequent, but uncommon tasks like "migrate this data to a new schema".

Why?

You might ask, "Why not use Celery?". Well the answer is simply that normal queueing requires (not literally, but it'd be painful without) you to buffer all tasks into a central location. This becomes a problem when you have a large amount of tasks, especially when they contain a large amount of data.

Imagine you have 1 billion tasks, each weighing in at 5k. Thats, uncompressed, at minimum 4 terabytes of storage required just to keep that around, and gains you very little.

Taskmaster on the other hand is designed to take a resumable iterator, and only pull in a maximum number of jobs at a time (using standard Python Queue's). This ensures a consistent memory pattern that can scale linearly.

Requirements

Requirements should be handled by setuptools, but if they are not, you will need the following Python packages:

  • progressbar
  • pyzmq (zeromq)
  • gevent
  • gevent_zeromq

A note on Gevent

Being that Taskmaster uses gevent for both its iterator task (master) and its consumers, your application will need to correctly implement non-blocking gevent compatible callers. In most cases this won't be a problem, but if you're using the network you'll need to look for a compatible library for your adapter. For example, there is an alternative version of psycopg2 designed for gevent called gevent-psycopg2.

Usage

Create an iterator, and callback:

# taskmaster/example.py
def get_jobs(last=0):
    # last would be sent if state was resumed
    # from a previous run
    for i in xrange(last, 100000000):
        # jobs yielded must be serializeable with pickle
        yield i

def handle_job(i):
    # this **must** be idempotent, as resuming the process may execute a job
    # that had already been run
    print "Got %r!" % i

Spawn a master:

$ tm-master taskmaster.example

You can also pass keyword arguments for the master:

$ tm-master taskmaster.example argument=value

Spawn a slave:

$ tm-slave taskmaster.example

Or spawn 8 slaves (each containing a threadpool):

$ tm-spawn taskmaster.example 8

Dont like the magical function discover for master/slave? Specify your own targets:

$ tm-master taskmaster.example:get_jobs
$ tm-slave taskmaster.example:handle_job

Maybe you simply need to run things on the same server?

$ tm-run taskmaster/example.py 8

Note

All arguments are optional, and the address will default to tcp://0.0.0.0:3050.

taskmaster's People

Contributors

alex avatar dcramer avatar lowks avatar randalldegges-okta-2 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.