Napa.js: a multi-threaded JavaScript runtime
Перейти к файлу
Asi Bross 3ba6ad1f66 Find path to boost-lib cmake file 2017-06-26 16:05:05 -07:00
benchmark Merged PR 293569: Implement anonymous function execution. 2017-06-15 18:10:11 +00:00
docs Merged PR 297525: Add documentation for Napa modules. 2017-06-16 18:48:42 +00:00
examples Merged PR 301401: First round cleanup - remove msbuild files and unnecessary folders 2017-06-20 18:37:47 +00:00
inc Merged PR 297335: Replace timeout with ExecuteOptions in zone.execute. 2017-06-16 21:25:47 +00:00
lib Merged PR 301401: First round cleanup - remove msbuild files and unnecessary folders 2017-06-20 18:37:47 +00:00
node Merged PR 301401: First round cleanup - remove msbuild files and unnecessary folders 2017-06-20 18:37:47 +00:00
src Set _WIN32_WINNT=0x0501 to avoid boost asio compilation warning 2017-06-21 10:47:49 -07:00
test Merged PR 301401: First round cleanup - remove msbuild files and unnecessary folders 2017-06-20 18:37:47 +00:00
third-party Merged PR 199269: Merge dev/asib/cleanup to master 2017-03-03 23:02:57 +00:00
.gitignore Add npmrc file 2017-06-21 14:36:56 -07:00
.npmignore Remove non-used script and add tools folder to npmignore 2017-06-26 14:32:52 -07:00
CMakeLists.txt Find path to boost-lib cmake file 2017-06-26 16:05:05 -07:00
README.md Merged PR 297525: Add documentation for Napa modules. 2017-06-16 18:48:42 +00:00
package.json remove dependencies on cmake-js and boost-lib 2017-06-26 15:25:54 -07:00

README.md

Napa.JS

Napa.JS is a multi-threaded JavaScript runtime built on V8 and TypeScript, which was originally designed to develop highly iterative services with non-compromised performance in Bing. As it evolves, we find it useful to complement Node.JS in CPU-bound tasks, with the capability of executing JavaScript in multiple V8 isolates and communicating between them. Napa.JS is exposed as a Node.JS module, while it can also be embedded in a host process without Node.JS dependency.

Installation

npm install napajs

Quick Start

let napa = require('napajs');
let zone = napa.zone.create('zone1');

// Execute an anonymous function in any worker thread in 'zone1'.
zone.execute(
    (text: string) => {
        return text;
    }, 
    ['hello world'])
    .then((result: napa.zone.ExecuteResponse) => {
        console.log(result.value);
    });

Features

  • Multi-threaded JavaScript runtime
  • Node.JS compatible module architecture with NPM support
  • API for object transportation, object sharing and synchronization across JavaScript threads
  • API for pluggable logging, metric and memory allocator
  • Distributed as a Node.JS module, as well as supporting embed scenarios

Architecture

In Napa.JS, all works related to multi-threading are around the concept of Zone, which is the basic unit to define policies and execute JavaScript code. A process may contain multiple zones, each consists of multiple JavaScript Workers.

Architecture

Within a zone, all workers are symmetrical: they load the same code, serve zone.broadcast and zone.execute in an indistinguishable way. Basically, you cannot ask a zone to execute code on a specific worker.

Workers across different zones are asymmetrical: they may load different code, or load the same code but reinforce different policies, like heap size, security settings, etc. Applications may need multiple zones for work loads of different purposes or different policies.

Napa.JS provides API to access current or other zones in JavaScript, thus a parallelizable workflow can be easily described by zone.execute across workers or zones. Node.JS event loop is exposed as a single-worker 'virtual' zone. Thus code running in Napa.JS isolates can call to Node.JS world via zone.node.execute.

Documentation

Contribute