Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into mybranch
Browse files Browse the repository at this point in the history
  • Loading branch information
helloshuangzi authored Oct 29, 2018
2 parents 4d9b9b2 + 3e472ac commit 2386315
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Other options can be found in [Build Napa.js](https://github.com/Microsoft/napaj

## Quick Start
```js
var napa = require('napajs');
var zone1 = napa.zone.create('zone1', { workers: 4 });
const napa = require('napajs');
const zone1 = napa.zone.create('zone1', { workers: 4 });

// Broadcast code to all 4 workers in 'zone1'.
zone1.broadcast('console.log("hello world");');
Expand Down
4 changes: 2 additions & 2 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ We got this report on environment below:

| Name | Value |
|-------------------|---------------------------------------------------------------------------------------|
|**Processor** |Intel(R) Xeon(R) CPU L5640 @ 2.27GHz, 8 virtual procesors |
|**Processor** |Intel(R) Xeon(R) CPU L5640 @ 2.27GHz, 8 virtual processors |
|**System Type** |x64-based PC |
|**Physical Memory**|16.0 GB |
|**OS version** |Microsoft Windows Server 2012 R2 |
Expand Down Expand Up @@ -90,7 +90,7 @@ Average overhead is around 0.06ms to 0.12ms for `zone.execute`.
## Transport overhead

The overhead of `transport.marshall` includes
1. overhead of needing replacer callback during JSON.stringify. (even empty callback will slowdown JSON.stringfiy significantly)
1. overhead of needing replacer callback during JSON.stringify. (even an empty callback will slow down JSON.stringify significantly)
2. traverse every value during JSON.stringify, to check value type and get `cid` to put into payload.
- a. If value doesn't need special care.
- b. If value is a transportable object that needs special care.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Napa.js follows [Node.js' convention](https://nodejs.org/api/modules.html) to su
4) API of creating C++ modules (addons) are similar. Napa.JS introduced macros that the same source code can be compiled to produce both Napa.js addon and Node.js addon.

But there are also differences:
1) C++ module that is designed/implemented for Napa.js can run on Node.JS (need different compile flags to produce '.napa' and '.node'). But not vice versa.
1) C++ module that is designed/implemented for Napa.js can run on Node.JS (need different compile flags to produce '.napa' and '.node'). But not vice versa.
2) Napa.js doesn't support all Node.js API. Node API are supported [incrementally](./node-api.md) on the motivation of adding Node.js built-ins and core modules that are needed for computation heavy tasks. You can access full capabilities of Node exposed via [Node zone](./zone.md#node-zone).
3) Napa.js doesn't provide `uv` functionalities, thus built-ins and core modules have its own implementation. To write async function in addon, methods `DoAsyncWork`/`PostAsyncWork` are introduced to work for both Napa.js and Node.js.
4) Napa.js supports embed mode. C++ modules need separate compilation between Node mode and embed mode.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Though very convenient, it's not recommended to use store to pass values within
Following APIs are exposed to create, get and operate upon stores.

### <a name="create"></a> create(id: string): Store
It creates a store by a string identifer that can be used to get the store later. When all references to the store from all JavaScript VMs are cleared, the store will be destroyed. Thus always keep a reference at global or module scope is usually a good practice using `Store`. Error will be thrown if the id already exists.
It creates a store by a string identifier that can be used to get the store later. When all references to the store from all JavaScript VMs are cleared, the store will be destroyed. Thus always keep a reference at global or module scope is usually a good practice using `Store`. Error will be thrown if the id already exists.

Example:
```js
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The source codes can be organized as the structure below.
## How to build and test ?
For the module examples, node-gyp or cmake-js build solution is provided for your reference.

Please make sure [node-gyp](https://github.com/nodejs/node-gyp#installation) or [cmake-js](https://github.com/cmake-js/cmake-js#installation) has been set up correctly at your client, then you could follow the below steps to build and test the module examples.
Please make sure [node-gyp](https://github.com/nodejs/node-gyp#installation) or [cmake-js](https://github.com/cmake-js/cmake-js#installation) has been set up correctly at your client, then you could follow the steps below to build and test the module examples.
```
1. go to the directory of a module example
2. run "npm install" to build the module
Expand Down
12 changes: 6 additions & 6 deletions examples/modules/async-number/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace {
std::atomic<uint32_t> _now(0);
}

/// <summary> It increases a number by a given parameter asynchronously and run a callback at the next execution loop. </summary>
/// <summary> It increases a number by a given parameter asynchronously and runs a callback at the next execution loop. </summary>
void Increase(const FunctionCallbackInfo<Value>& args) {
auto isolate = args.GetIsolate();

Expand All @@ -81,12 +81,12 @@ void Increase(const FunctionCallbackInfo<Value>& args) {

napa::module::PostAsyncWork(Local<Function>::Cast(args[1]),
[value]() {
// This runs at the separate thread.
// This runs in a separate thread.
_now += value;
return reinterpret_cast<void*>(static_cast<uintptr_t>(_now.load()));
},
[](auto jsCallback, void* result) {
// This runs at the same thread as one Increase() is called.
// This runs in the same thread as the one Increase() is called in.
auto isolate = Isolate::GetCurrent();

int32_t argc = 1;
Expand All @@ -98,7 +98,7 @@ void Increase(const FunctionCallbackInfo<Value>& args) {
);
}

/// <summary> It increases a number by a given parameter synchronously and run a callback at the next execution loop. </summary>
/// <summary> It increases a number by a given parameter synchronously and runs a callback at the next execution loop. </summary>
void IncreaseSync(const FunctionCallbackInfo<Value>& args) {
auto isolate = args.GetIsolate();

Expand All @@ -110,12 +110,12 @@ void IncreaseSync(const FunctionCallbackInfo<Value>& args) {

napa::module::DoAsyncWork(Local<Function>::Cast(args[1]),
[value](auto complete) {
// This runs at the same thread.
// This runs in the same thread.
_now += value;
complete(reinterpret_cast<void*>(static_cast<uintptr_t>(_now.load())));
},
[](auto jsCallback, void* result) {
// This runs at the same thread as one IncreaseSync() is called.
// This runs in the same thread as the one IncreaseSync() is called in.
auto isolate = Isolate::GetCurrent();

int32_t argc = 1;
Expand Down
12 changes: 6 additions & 6 deletions examples/modules/async-number/napa/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace {
std::atomic<uint32_t> _now(0);
}

/// <summary> It increases a number by a given parameter asynchronously and run a callback at the next execution loop. </summary>
/// <summary> It increases a number by a given parameter asynchronously and runs a callback at the next execution loop. </summary>
void Increase(const FunctionCallbackInfo<Value>& args) {
auto isolate = args.GetIsolate();

Expand All @@ -28,12 +28,12 @@ void Increase(const FunctionCallbackInfo<Value>& args) {

napa::zone::PostAsyncWork(Local<Function>::Cast(args[1]),
[value]() {
// This runs at the separate thread.
// This runs in a separate thread.
_now += value;
return reinterpret_cast<void*>(static_cast<uintptr_t>(_now.load()));
},
[](auto jsCallback, void* result) {
// This runs at the same thread as one Increase() is called.
// This runs in the same thread as the one Increase() is called in.
auto isolate = Isolate::GetCurrent();

int32_t argc = 1;
Expand All @@ -45,7 +45,7 @@ void Increase(const FunctionCallbackInfo<Value>& args) {
);
}

/// <summary> It increases a number by a given parameter synchronously and run a callback at the next execution loop. </summary>
/// <summary> It increases a number by a given parameter synchronously and runs a callback at the next execution loop. </summary>
void IncreaseSync(const FunctionCallbackInfo<Value>& args) {
auto isolate = args.GetIsolate();

Expand All @@ -57,12 +57,12 @@ void IncreaseSync(const FunctionCallbackInfo<Value>& args) {

napa::zone::DoAsyncWork(Local<Function>::Cast(args[1]),
[value](auto complete) {
// This runs at the same thread.
// This runs in the same thread.
_now += value;
complete(reinterpret_cast<void*>(static_cast<uintptr_t>(_now.load())));
},
[](auto jsCallback, void* result) {
// This runs at the same thread as one IncreaseSync() is called.
// This runs in the same thread as the one IncreaseSync() is called in.
auto isolate = Isolate::GetCurrent();

int32_t argc = 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/plus-number/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var obj = addon.createPlusNumber();

## Wrapped class

*plus-number.h* declares ths class with one constructor and one method, *Add()*.
*plus-number.h* declares the class with one constructor and one method, *Add()*.

```h
namespace napa {
Expand Down
8 changes: 4 additions & 4 deletions examples/tutorial/napa-runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Napa runner is an example to embed Napa.JS into a C++ program. It simply runs JavaScript with all Napa capability without Node dependency from command line.

## How to build
1. Go to napajs root directory, run "node build.js embed" to build napa library for embeded mode.
1. Go to napajs root directory, run "node build.js embed" to build napa library for embedded mode.

**NOTE**: This step may take about 30 mins, because it will build V8 libray from Node. We are using node v6.10.3, a stable version can build as a library. It is specified in [embedded.js](https://github.com/Microsoft/napajs/blob/master/scripts/embedded.js) and [napa-runner CMakeLists.txt](https://github.com/Microsoft/napajs/blob/master/examples/tutorial/napa-runner/CMakeLists.txt). Please update both of them if you want to use a different version of Node/V8.
**NOTE**: This step may take about 30 mins, because it will build V8 library from Node. We are using node v6.10.3, a stable version can build as a library. It is specified in [embedded.js](https://github.com/Microsoft/napajs/blob/master/scripts/embedded.js) and [napa-runner CMakeLists.txt](https://github.com/Microsoft/napajs/blob/master/examples/tutorial/napa-runner/CMakeLists.txt). Please update both of them if you want to use a different version of Node/V8.

2. Go to directory of "examples/tutorial/napa-runner", and run "cmake-js build" to build napa runner

**NOTE**: Build solution of napa-runner is provided only for linux system so far. Windows / Mac OS support will come in near future.

## How to use
1. Run "npm install" to intall required npm modules
2. Run "./bin/napa-runner emstimate-PI.js"
1. Run "npm install" to install required npm modules
2. Run "./bin/napa-runner estimate-PI.js"

2 changes: 1 addition & 1 deletion scripts/embedded.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ exports.build = function (buildType) {
}
else {
// TODO (asib): support other platforms
console.log("\x1b[1m\x1b[32m", "Napa build solution for embeded mode is not provided for ", os.platform(),'\x1b[0m');
console.log("\x1b[1m\x1b[32m", "Napa build solution for embedded mode is not provided for ", os.platform(),'\x1b[0m');
return;
}

Expand Down

0 comments on commit 2386315

Please sign in to comment.