MyNixOS website logo
Description

High-level interface to CCTools' WorkQueue library.

This package provides a high-level Haskell interface to the WorkQueue library: http://www.nd.edu/~ccl/software/workqueue/

Work Queue is a framework for building large master-worker applications that span many computers including clusters, clouds, and grids. Work Queue applications are written in C, Perl, or Python using a simple API that allows users to define tasks, submit them to the queue, and wait for completion. Tasks are executed by a standard worker process that can run on any available machine. Each worker calls home to the master process, arranges for data transfer, and executes the tasks. Together, the master and worker handle a wide variety of failures, allowing for dynamically scalable and robust applications.

Example usage:

By default the master listens on 9123 on the localhost host. Start a worker:

$ work_queue_worker -d all localhost 9123

Now we can execute the following master program:

module Main where

import Control.Distributed.CCTools.WorkQueue

import Control.Applicative ((<$>))
import qualified Data.ByteString.Char8 as BS (pack, putStrLn)
import Foreign.C.String (newCStringLen)
import Control.Monad (forM_)



mktask :: Show a => a -> IO Task
mktask v = do
  let script = BS.pack . unlines $ [
              "t=$(echo $RANDOM % 10 | bc)"
            , "sleep $t"
            , "echo " ++ show v
            ]
  t <- task $ cmd "bash script.sh"
  specifyBuffer t script (remote "script.sh") False
  specifyTag    t $ show v
  return t

printStats :: WorkQueue -> IO ()
printStats q = do
  s <- getStats q
  print $ map ($ s) [tasksRunning, tasksWaiting, tasksComplete]

processResult :: WorkQueue -> Task -> IO ()
processResult q r = do
  putStrLn $ "Got: " ++ show (tag r)
  BS.putStrLn . output $ r
  delete r

main = do
  setDebugFlags [All]
  q  <- workqueue defaultQParams
  ts <- mapM mktask [1..10]
  forM_ ts (submit q)

  eventLoop q (seconds 1) printStats processResult

  putStrLn "Done!"
Metadata

Version

3.6.1.0.1.0.0.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows