Skip to content

About

Distributed computing framework and demo in Jennifer: a master schedules prioritised tasks to auto-discovered worker nodes and combines their results.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

distributed

A framework for distributed computing in Jennifer, and a demo of it. A master schedules tasks from priority queues; workers find the master on the local network, take tasks for the queues they serve and return results; the master combines them into each job's result.

Start with docs/overview.md, or the academy talk Distributed computing in Jennifer.

Job kinds

A kind is the code for one type of job: how to split it into tasks, how to run a task, how to combine the results. Four come with the demo:

  • wordcount - word frequencies of a text file, map-reduce style: the master cuts the text into slices of whole lines, each task counts one slice.
  • pi - hexadecimal digits of pi from any position, by the Bailey-Borwein-Plouffe formula: every block of digits is an independent task. Endless unless told how many digits.
  • sleep - tasks that just wait a set time (-o seconds=5 or -o ms=250, -o tasks=20, 0 for endless): a steady workload for trying out the cluster.
  • exec - runs a script or program, once per task (-o script=job.sh -o tasks=8), only from the directory a worker was started with (--exec-dir), in that directory, in its own process group (killed whole at its timeout), with only PATH, HOME and LANG of the worker's environment. Extra arguments: -o args='a "b c"' (quoted as in a shell, nothing expanded) or a JSON list.

A new kind is one file in src/kinds/ registered in src/kinds.j; src/kind.j describes its option names and the six functions it provides. Unknown options are refused.

Requirements

Jennifer 0.28.0 or later (a 0.28.0 development build works), the full jennifer binary (networking is not available on jennifer-tiny).

Demo walkthrough

Four terminals on one machine (or the workers on other machines of the same network). Start the master, which shows its live screen:

./bin/distributed master

Give one worker a directory of programs it may run, then start two workers; they find the master by themselves and appear in its node list:

mkdir -p /tmp/jobs
printf '#!/bin/sh\necho "run $1 of $2 on $(uname -n)"\n' > /tmp/jobs/hello.sh
chmod +x /tmp/jobs/hello.sh
./bin/distributed worker --slots 2 --exec-dir /tmp/jobs -vv   # terminal 2
./bin/distributed worker --slots 2                            # terminal 3

In the fourth terminal, submit jobs and watch the master's screen:

# Count the words of the World English Bible™, uploaded with the job; --wait prints
# the result: 925038 words, "the" 67866 times.
./bin/distributed submit wordcount -f input=data/web.txt.gz -o top=5 --wait

# Hexadecimal digits of pi, endless: it keeps every slot busy. Its digits grow in
# var/jobs/j2/output.txt (243F6A8885A308D3...).
./bin/distributed submit pi

# Twenty 3-second tasks of the same priority: they share the slots with pi.
./bin/distributed submit sleep -o seconds=3 -o tasks=20

# A higher priority gets the next free slot.
./bin/distributed submit sleep -o seconds=3 -o tasks=4 --priority 5

# Run the script on the worker that has it, four times; output in task order.
./bin/distributed submit exec -o script=hello.sh -o tasks=4 --wait
cat var/jobs/j5/output.txt

On the master's screen: tab to the nodes, p pauses a worker (it finishes what it holds, takes nothing new), p again resumes it; tab back to the jobs, select the pi job and x then y cancels it. Press Ctrl-C in a worker's terminal: it drains and leaves; its tasks go to the other worker. Quit the master with q, y and start it again: the jobs carry on where they were, and the workers find it again.

--wait survives that restart too. To run a job without any of this, in one process: ./bin/distributed local pi -o digits=96.

Usage

./bin/distributed master                      # scheduler with its terminal UI
./bin/distributed worker --slots 4            # finds the master by UDP broadcast
./bin/distributed worker --master 10.0.0.5    # or is told where it is
./bin/distributed submit pi --priority 5      # add a job
./bin/distributed submit pi -o digits=1000 --wait     # ... and wait for its result
./bin/distributed submit wordcount -f input=data/web.txt.gz -o top=20 -w   # the demo corpus
./bin/distributed local pi -o digits=96       # run a job in this process
./bin/distributed local wordcount -o input=book.txt -o top=10
./bin/distributed --help                      # every option of every role

Workers find the master by UDP broadcast (port 7401) unless given --master; the master serves on TCP port 7400. A worker runs one task per slot (--slots, one per CPU by default). Stop a worker with Ctrl-C: it finishes the tasks it holds, then leaves; a second Ctrl-C leaves at once. The master keeps its state in var/ (or --data) and picks up where it stopped after a restart; each job's output and result are in var/jobs/<id>/. A worker run with -v logs each task it receives, -vv also each one it finishes, -vvv also their contents.

Jobs of a higher priority get the next free slot (running tasks are not interrupted); a job gains one priority level per ten minutes it waits (--aging). Jobs of the same level share the workers' slots, taking turns, so a long or endless job never holds up a later one of the same priority. Each task is sized from measurement to take about two seconds (--task-ms on the master).

In a terminal the master shows a live screen: totals, each kind's throughput and overhead, the jobs with their progress, and the nodes. tab switches between the job and node lists, up/down selects; on a node p pauses or resumes, d drains, l makes it leave; on a job x cancels, +/- change its priority; c clears ended jobs and gone nodes from the lists (their files stay); q quits. Its log then goes to var/master.log. With --headless, or when not on a terminal, it logs lines to stderr instead.

The shared secret is taken from --token or the DISTRIBUTED_TOKEN environment variable.

The demo corpus, data/web.txt.gz, is the World English Bible (public domain; see data/README.md for its source and how it was made).

Documentation

Development

sh scripts/check.sh              # the full gate: version, fmt, lint, tests, smoke
SKIP_SMOKE=1 sh scripts/check.sh # the same without the end-to-end run
sh scripts/smoke.sh              # end to end: workers killed, drained, master crashed
jennifer test src/cli_test.j     # one suite

Licence

LGPL-3.0-only; see LICENSE and LICENSE.GPL-3.0.

About

Distributed computing framework and demo in Jennifer: a master schedules prioritised tasks to auto-discovered worker nodes and combines their results.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages