Skip to content

Repository files navigation

distribution

This is the distribution library. When loaded, distribution introduces functionality supporting the distributed execution of programs. To download it:

Installation

$ npm i '@brown-ds/distribution'

This command downloads and installs the distribution library.

Testing

There are several categories of tests:

  • Regular Tests (*.test.js)
  • Scenario Tests (*.scenario.js)
  • Extra Credit Tests (*.extra.test.js)
  • Student Tests (*.student.test.js) - inside test/test-student

Running Tests

By default, all regular tests are run. Use the options below to run different sets of tests:

  1. Run all regular tests (default): $ npm test or $ npm test -- -t
  2. Run scenario tests: $ npm test -- -c
  3. Run extra credit tests: $ npm test -- -ec
  4. Run the non-distribution tests: $ npm test -- -nd
  5. Combine options: $ npm test -- -c -ec -nd -t

Usage

To import the library, be it in a JavaScript file or on the interactive console, run:

let distribution = require("@brown-ds/distribution");

Now you have access to the full distribution library. You can start off by serializing some values.

let s = distribution.util.serialize(1); // '{"type":"number","value":"1"}'
let n = distribution.util.deserialize(s); // 1

You can inspect information about the current node (for example its sid) by running:

distribution.local.status.get('sid', console.log); // 8cf1b

You can also store and retrieve values from the local memory:

distribution.local.mem.put({name: 'nikos'}, 'key', console.log); // {name: 'nikos'}
distribution.local.mem.get('key', console.log); // {name: 'nikos'}

You can also spawn a new node:

let node = { ip: '127.0.0.1', port: 8080 };
distribution.local.status.spawn(node, console.log);

Using the distribution.all set of services will allow you to act on the full set of nodes created as if they were a single one.

distribution.all.status.get('sid', console.log); // { '8cf1b': '8cf1b', '8cf1c': '8cf1c' }

You can also send messages to other nodes:

distribution.all.comm.send(['sid'], {node: node, service: 'status', method: 'get'}, console.log); // 8cf1c

Results and Reflections

...

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages