Skip to main content

DEW

Overview​

DEW (Distributed Experiment Workflow) runs the steps of an experiment in order across several nodes. You describe who does what and when in one file, called a scenario, and DEW makes each node wait for the others where it has to: "node A starts a server; only once the server is up does node B connect to it."

Without DEW, ordering steps across machines means logging into each node by hand in the right order, or writing scripts that poll with sleep and until nc -z ... loops.

To draw the topology and deploy it from a browser, use the DEW Designer. This page is the dewctl tool that runs after the nodes exist.

You install DEW on your XDC. It never changes your experiment's topology or reservation; it only runs the commands you give it, on the nodes you already have.

How it works​

  • An agent runs on every experiment node, as a system service called dew-agent.
  • One node also runs a broker (RabbitMQ), a message bus all agents connect to.
  • From your XDC, dewctl run sends the scenario to every agent. Each agent runs only the tasks that name its own node.
  • When a task finishes (or starts, or fails), its agent emits an event. Tasks waiting on that event, on any node, then start.

There is no central scheduler: the nodes coordinate among themselves through events. Your XDC only starts the run, and watches it if you ask it to.

Setting up DEW​

Naming your nodes​

Two naming tips save work:

  • Call the node that will run the broker server. That is DEW's default broker name.
  • Call clients client1, client2, ... so scalable scenarios (see Scaling to many nodes) land on them with no extra mapping.

For example, this model works with every example on this page:

from mergexp import *

net = Network('dewdemo', addressing == ipv4, routing == static)
server = net.node('server')
client1 = net.node('client1')
client2 = net.node('client2')
net.connect([server, client1, client2])

experiment(net)

Installing DEW on your XDC​

Do this once. Your home directory is shared by all your XDCs, so DEW is available on any XDC you create later.

python3 -m venv ~/dewenv
~/dewenv/bin/pip install mrg-dew
echo 'export PATH="$HOME/dewenv/bin:$PATH"' | tee -a ~/.bashrc ~/.profile > /dev/null
export PATH="$HOME/dewenv/bin:$PATH"
dewctl --version
  • DEW is installed in its own Python environment, ~/dewenv. The package is mrg-dew; the command it gives you is dewctl.
  • The PATH lines make dewctl available in every new terminal, and in the current one.
  • The last command prints dewctl and the installed version.

Installing DEW on your experiment nodes​

Do this once per materialization, from the XDC:

dewctl deploy all --broker server
  • all finds your nodes from the materialization the XDC is attached to.
  • --broker server picks the node that runs the broker. Without it, DEW uses the first node and says so.
  • --dry-run shows the plan without changing anything.
  • --exclude <node> ... skips nodes, and you can list nodes yourself instead of all: dewctl deploy server client1 client2 --broker server.

You are asked for your password once per node. DEW uses it, up front, to allow passwordless sudo on each node (it adds /etc/sudoers.d/90-dew). Everything after that runs without prompts: the broker is installed first, then the agents on all other nodes in parallel.

It ends with a check of every node:

node agent broker resolves
client1 active ok ok
client2 active ok ok
server active ok ok

DEW ready. Broker: server
  • agent: the dew-agent service is running.
  • broker: the node can reach the broker's port.
  • resolves: the node can look up the broker's name.

It also saves the broker and node list in ~/.dewrc, so later commands never need them again. Running dewctl deploy again is safe.

Updating DEW​

~/dewenv/bin/pip install --upgrade mrg-dew
dewctl deploy all --broker server

The first line updates dewctl on your XDC; the second gives your nodes the new version. To use a specific version, install mrg-dew==<version> instead, then deploy.

Commands​

CommandWhat it does
dewctl deploy all --broker serverinstall or update DEW on every node
dewctl run <scenario.json>start a run and watch it until it finishes
dewctl run <a.json> <b.json> ...run several scenarios in order, each to completion; stops if one fails
dewctl run <scenario.json> --only <label>run only one labeled part of a scenario
dewctl run <scenario.json> --no-followstart a run and return immediately
dewctl stopstop everything DEW started, on every node
dewctl statuswhat each node did in the last run, read from the nodes' logs (-a for all runs)
dewctl collect <path>copy a file from every node into results/, as <node>-<filename>
dewctl expand <scenario.json>show a scalable scenario with its roles filled in, without running it
dewctl --versionthe installed DEW version

Stopping a run: press Ctrl-C in the terminal running dewctl run. Some XDC terminals ignore Ctrl-C; DEW says so when a run starts. In that case, run dewctl stop from a second terminal. Stopping kills every process DEW started on every node, including child processes.

Writing scenarios​

A scenario is a JSON file with three sections, plus an optional fourth:

SectionContents
Scenariothe tasks: who does what, and when
Bindingsthe shell command for each action, and the definition of each event
Constraintsroles, for scenarios that scale to many nodes ({} if none)
Labelsoptional named groups of tasks, to run one part at a time

Tasks​

Each entry in Scenario is one task:

[when <event>[, <event>...]] [wait <seconds>] <node> <action> [emit <event> ...]
PartMeaning
when a, bwait until all the listed events have happened (a comma after every event but the last)
wait 5then wait 5 more seconds
<node>the node that runs the task; must match a node name in your experiment
<action>a name defined in Bindings
emit xannounce event x; when it fires is set by its definition (below)

The parts must appear in this order. A task with no when starts as soon as the run starts. Task names (task1, t2, ...) are only labels: order comes from events, not from the order of the lines.

Bindings​

A binding maps an action name to the command the node runs:

"pingserver": "bash -c \"ping -c 5 server > /tmp/a.log 2>&1\""
  • Wrap anything that uses shell features (>, |, &&, cd, variables) in bash -c "...". Without it, the command runs directly, with no shell.
  • Inside JSON, write each " in the command as \".
  • Commands run as you (the user who ran dewctl deploy), starting in /. Use full paths, or cd inside bash -c.
  • To run a command as root, prefix it with sudo, for example "capture": "bash -c \"sudo tcpdump -i eth1 -w /tmp/cap.pcap\"". It works without a password after dewctl deploy.
  • What a command prints is not shown by dewctl run. The live view shows each task's state (started, finished rc=0) and each event, not the command's output. The output (stdout and stderr) is saved on the task's node in /tmp/dew-task-<n>.out, where <n> is the task's number on that node: 0 for the node's first task in the file, 1 for its second, and so on. It is the same number the live view shows as task0, task1, .... Copy those files to your XDC with dewctl collect /tmp/dew-task-0.out.

Events: when does emit fire?​

Every emit x names an event, x, that other tasks can wait for with when x. By default it fires when the action exits successfully (exit code 0). To fire it at a different moment, define the event in Bindings; the definition changes only when it fires, not its name:

Definition in BindingsEvent fires when the action...
"x": "success(action)"exits with code 0 (the default when there is no definition)
"x": "started(action)"starts; use this for servers and other programs that never exit
"x": "finished(action)"exits, whether it succeeded or failed
"x": "failed(action)"exits with a non-zero code, or cannot start

One task can emit several events; only the ones that apply fire. Stopping a run fires none of them.

The most common mistake is a plain emit on a program that never exits, such as a server. The event never fires and everything waiting on it waits forever. Use started():

{
"Scenario": {
"t1": "server serve emit up",
"t2": "when up client1 fetch"
},
"Bindings": {
"serve": "bash -c \"python3 -m http.server 8080\"",
"up": "started(serve)",
"fetch": "bash -c \"sleep 2; curl -s http://server:8080 > /tmp/page.html\""
},
"Constraints": {}
}

started() fires as soon as the process launches, which can be slightly before it is ready to accept connections; the sleep 2 covers that gap.

Handling failures​

To do something when a step fails, give it a failed() event and a task that waits on it:

{
"Scenario": {
"t1": "server start_web emit up emit down",
"t2": "when up client1 use_primary",
"t3": "when down server start_backup"
},
"Bindings": {
"start_web": "bash -c \"sudo systemctl start apache2 && curl -sf http://localhost -o /dev/null\"",
"up": "success(start_web)",
"down": "failed(start_web)",
"use_primary": "bash -c \"curl -s http://server > /tmp/page.html\"",
"start_backup": "bash -c \"echo 'primary failed' > /tmp/backup.log\""
},
"Constraints": {}
}

Exactly one of use_primary or start_backup runs.

Placeholders: node names, IP addresses and interfaces​

To use a node's name, IP address or network interface in a command, use these placeholders. Each node fills them in with its own values just before running the command:

PlaceholderBecomes
$nidthis node's name
$eid, $projectthe experiment and project names
$epochthe time (seconds since 1970) when the command starts
$expIP, $expeththis node's experiment-network IP address and interface
$IP(A)node A's IP address
$expIP(A), $expeth(A)this node's IP address and interface on the path toward node A
"capture": "bash -c \"sudo timeout 20 tcpdump -i $expeth(server) -w /tmp/${nid}.pcap\""
  • Only these exact names are replaced. Other $ uses, such as $HOME or $(date), are left for the shell.
  • Write ${nid}_run, not $nid_run, to put text right after a placeholder.
  • $ctlIP and $ctleth are not supported on SPHERE.

dewctl run checks placeholders before starting: a malformed one stops the run with an error, and a likely typo (such as $expeht) prints a warning.

Scaling to many nodes​

Instead of writing one task per client, write it once for a role and say how many there are:

{
"Constraints": { "c1": "client num 2" },
"Scenario": {
"task1": "server ping_client emit pinged",
"task2": "when pinged client ping_back emit done",
"task3": "when done* server allfinished"
},
"Bindings": {
"ping_client": "bash -c \"ping -c 3 {client} > /tmp/to-{client}.log 2>&1\"",
"ping_back": "bash -c \"ping -c 3 server > /tmp/from-{client}.log 2>&1\"",
"allfinished": "bash -c \"date > /tmp/all-done.txt\""
}
}
  • client num 2 means nodes client1 and client2. Change the number to scale up; the rest of the scenario stays the same.
  • A task whose node is a role runs once per instance. {client} in a binding becomes each instance's name.
  • An event emitted by a role task is numbered (done1, done2, ...); done* waits for all of them.
  • dewctl run fills in the roles automatically. dewctl expand <file> shows the result first.
  • If your nodes have other names, map the role to them: dewctl expand scale.json --map client=alpha,beta,gamma -o concrete.json, then run concrete.json.

Running part of a scenario​

Group tasks with Labels, then run one group with --only:

"Labels": { "setup": ["t1", "t2"], "experiment": ["t3"], "collect": ["t4"] }
dewctl run exp.json # everything
dewctl run exp.json --only experiment # just the experiment, e.g. to repeat it

--only ignores when events that come from outside the group, because it assumes the earlier part (here, setup) has already run.

You can also split an experiment into separate files and run them in order:

dewctl run setup.json run1.json run2.json collect.json

Each file runs to completion before the next starts, and the sequence stops if one fails.

Example scenario​

This scenario has client1 ping the server, and only once that finishes does the server ping back. It shows the basic pattern every scenario builds on: one task emits an event, and a task on another node waits for it.

{
"Scenario": {
"task1": "client1 pingserver emit c2sdone",
"task2": "when c2sdone server pingclient"
},
"Bindings": {
"pingserver": "bash -c \"ping -c 5 server > /tmp/a.log 2>&1\"",
"pingclient": "bash -c \"ping -c 5 client1 > /tmp/b.log 2>&1\""
},
"Constraints": {}
}
LineMeaning
"task1": "client1 pingserver emit c2sdone"client1 runs pingserver and, when it exits successfully, announces c2sdone
"task2": "when c2sdone server pingclient"server waits for c2sdone, then runs pingclient
"pingserver": "bash -c \"...\""the command behind pingserver; its output goes to /tmp/a.log on client1

Save it as ping.json and run it:

dewctl run ping.json

dewctl run stays attached and prints what every node does:

run 928558c7 published; nodes start in 5s (ctrl-c stops the run)
0.0s server task0 blocked pingclient -- waiting on c2sdone
0.0s client1 task0 declared pingserver
4.1s client1 task0 started pid=5123
8.2s client1 task0 finished rc=0
8.2s event c2sdone
8.2s server task0 started pid=5991
12.3s server task0 finished rc=0
run complete -- 2 task(s), 2 finished, 0 still running or blocked, 0 failure(s)

Every run waits five seconds before starting, so all nodes begin together. The event c2sdone line is the handoff from client1 to server. Afterwards, dewctl collect /tmp/a.log brings the ping output back to your XDC.

Results and troubleshooting​

Collecting results​

Have your commands write results to files, then copy them to the XDC:

dewctl collect /tmp/a.log

This creates results/client1-a.log, results/server-a.log, and so on, so files with the same name on different nodes do not overwrite each other. -o <dir> picks another folder.

When a task fails​

The live view prints a FAILURE line with the node, the command, and the end of its output:

4.3s FAILURE server exit rc=1 -- bash -c "..." :: output: some-error-output

The full output is on that node in /tmp/dew-task-<n>.out (see Bindings for what <n> is); fetch it with dewctl collect /tmp/dew-task-<n>.out.

A failed task stops everything that waits on it. Its default (success) event never fires, so the tasks waiting on it, and anything waiting on those, never start, and the run does not finish on its own; end it with Ctrl-C or dewctl stop. If the run should continue anyway, define the event as finished(<action>) (fires on any exit), or add a failed(<action>) event and a task that handles the failure (see Handling failures).

Common problems​

SymptomCauseFix
dewctl: command not found~/dewenv/bin is not on your PATHrun the two PATH lines from Installing DEW on your XDC
pika is not available ...DEW's Python environment is missing or brokenreinstall DEW (see Installing DEW on your XDC)
dewctl deploy all says mrg list xdcs returned nothingyou are not logged in on this XDCmrg login <username>, then deploy again; or list the nodes yourself
A task never runs, and nothing reports an errorits node name does not match any nodecheck the spelling against your experiment's node names
Everything after a server waits foreverthe server's event is a plain emit or success()define it as started(<action>)
A node shows DOWN in the live viewits agent stopped sending heartbeats (node rebooted or lost)when it is back, re-run the scenario or the affected part with --only
broker column is NO after deploythat node cannot reach the brokersee the note below on labs that change networking
Ctrl-C does nothingthe XDC terminal ignores Ctrl-Crun dewctl stop from another terminal
dewctl status shows unreachablethe node cannot be reached over ssh from the XDCcheck the node is up

Labs that change networking. If your experiment rewrites DNS or routing (for example a DNS or BGP lab), the nodes may lose the route or name for the broker. Put the broker on the control network: before dewctl deploy, add <broker-control-ip> <broker-name> to /etc/hosts on every node.

Limitations​

  • A node that reboots during a run forgets that run. Its agent restarts on its own, but its remaining tasks for that run do not run. Re-run the scenario, or the affected part with --only.
  • Node clocks are assumed to agree. The five-second start delay relies on it; on SPHERE the difference between nodes is a few milliseconds.
  • The broker uses a shared default login (dew/dew). It runs on one of your own experiment nodes, not on a public host. Set DEW_RABBITMQ_USER and DEW_RABBITMQ_PASS to change it.
  • Passwordless sudo stays on the nodes after dewctl deploy until they are reimaged. Delete /etc/sudoers.d/90-dew on a node to undo it.

Questions​

How do I make a task wait for two (or more) other tasks, even on different nodes? List the events after when, separated by commas: "t3": "when a_done, b_done server merge". The task starts only after all of them have fired, wherever they came from. See Tasks.

What is the difference between success(), started(), finished() and failed()? They set when an event fires: success(action) when the action exits with code 0 (the default), started(action) as soon as it starts, finished(action) when it exits either way, and failed(action) when it exits non-zero or cannot start. See Events.

My server task never finishes, so the task waiting on it never starts. Why? A plain emit fires when the command exits, and a server never exits. Define the event as started(<action>) so it fires as soon as the server starts. See Events.

How do I run a command as root? Prefix it with sudo inside the binding, e.g. "bash -c \"sudo systemctl restart nginx\"". After dewctl deploy, sudo needs no password. Commands otherwise run as you.

How do I put a node's IP address, name or interface into a command? Use placeholders: $IP(server) is the server's IP address, $expIP this node's experiment IP address, $expeth its experiment interface, $nid its name. For example "ping -c 3 $IP(server)". See Placeholders.

Can I use $ctlIP or $ctleth for the control network? No. They are not supported on SPHERE; a task that uses them fails instead of running.

How do I write one scenario for many clients, e.g. 10? Add "Constraints": { "c1": "client num 10" }, write tasks for the role client, use {client} inside bindings for each client's own name, and wait for all of them with when done*. Name the nodes client1 ... client10, or map other names with --map. See Scaling to many nodes.

Where does my command's output go, and how do I see it? Not to the dewctl run screen, which shows only task states and events. Each task's output is saved on its node in /tmp/dew-task-<n>.out, where <n> is the task's number on that node (0 for its first task). Bring the files to your XDC with dewctl collect /tmp/dew-task-0.out. Files your command writes itself stay wherever it writes them; collect them the same way.

What happens if one step fails? Everything waiting on it waits forever, and the run does not end on its own. Stop it with dewctl stop, or use finished() / failed() events so the run continues. See When a task fails.

Does DEW change my experiment or topology? No. It only runs commands on nodes that already exist. Nodes, links and addresses are unchanged.

Do I need DEW for a single node? Usually not. DEW is for steps that depend on what happens on other nodes.

Can I keep using my experiment while a scenario runs? Yes. DEW tasks run alongside anything you do over ssh.

Can I run the same scenario on a new materialization? Yes. Run dewctl deploy on the new materialization, then dewctl run the same file, as long as the node names match. Use roles and --map when they do not.

Which node should run the broker? Any node that every other node can reach, ideally one that does little else. It cannot be the XDC.

How do I update DEW? See Updating DEW.