a0c478b8c7 | ||
---|---|---|
benchmark | ||
cpp-test | ||
docs | ||
examples | ||
inc | ||
lib | ||
node | ||
src | ||
test | ||
third-party | ||
.gitignore | ||
.npmignore | ||
CMakeLists.txt | ||
README.md | ||
package.json |
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.Result) => {
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
.
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
.