light-message
v0.1.1
Published
Light Message is a light-weight IPC & RPC library for node.js. Base on Axon, use tiny AMP prototol.
Downloads
2
Readme
Introduction
Light Message is a light-weight IPC & RPC library for node.js. Base on Axon, use tiny AMP prototol.
Installation
$ npm install light-message
Features
- inter-process communication
- remote procedure communication
- light-weight wire protocol
- support multiple types(string, number, boolean, object, array, buffer)
- mixed buffer in the object or array data
- unix domain socket support
- fast (~30 mb/s ~6,000 messages/s)
- without requiring higher level serialization libraries like msgpack or BSON.
How to use
create a server :
const LightMsg = require('light-message');
const server = new LightMsg.Server(8888, 'server id');
expose some methods :
server.expose('count', (num, reply) => {
reply(++num);
});
than create a client and send message to server :
const client = new LightMsg.Client();
// connect server
client.connect(8888);
// send message
client.send(5, (result) => {
console.log(`result is ${result}.`) // print 'result is 6'
});
Binding / Connecting
https://github.com/tj/axon#binding--connecting
In addition to passing a portno, binding to INADDR_ANY by default, you may also specify the url much like zmq via tcp://<hostname>:<portno>
, thus the following are equivalent:
server.bind(3000)
server.bind('tcp://0.0.0.0:3000')
client.connect(3000)
client.connect('tcp://0.0.0.0:3000')
Coverage
-------------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
-------------------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
light-message | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
light-message/lib | 100 | 100 | 100 | 100 | |
bufferMark.js | 100 | 100 | 100 | 100 | |
client.js | 100 | 100 | 100 | 100 | |
server.js | 100 | 100 | 100 | 100 | |
undefinedMark.js | 100 | 100 | 100 | 100 | |
utils.js | 100 | 100 | 100 | 100 | |
warn.js | 100 | 100 | 100 | 100 | |
-------------------|----------|----------|----------|----------|----------------|
=============================== Coverage summary ===============================
Statements : 100% ( 220/220 )
Branches : 100% ( 89/89 )
Functions : 100% ( 41/41 )
Lines : 100% ( 218/218 )
================================================================================
Performance
Last commit benchmark report:
Benchmark Report
2017-08-17 16:12:59
-------------
ENV
-------------
CPU : Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz
MEM : 97.897% / free361353216 / total17179869184
LOAD(1,5,15) : 3.13623046875, 2.6025390625, 2.0302734375
PLATFORM : darwin / 15.6.0
-------------
BENCHMARK
-------------
NAME : create server
TOTAL : 28960 ops in 5.04s
MEAN : 5792 ops / s
MIN : 3800 ops / s
MAX : 6815 ops / s
MEDIAN : 6175 ops / s
BASE ON 5 SAMPLES
NAME : create server(AXON original)
TOTAL : 29640 ops in 5s
MEAN : 5928 ops / s
MIN : 3560 ops / s
MAX : 6880 ops / s
MEDIAN : 6340 ops / s
BASE ON 5 SAMPLES
NAME : send 0.064 kb messages with single mode (ops)
TOTAL : 4415 ops in 5.065s
MEAN : 883 ops / s
MIN : 95 ops / s
MAX : 1305 ops / s
MEDIAN : 1190 ops / s
BASE ON 5 SAMPLES
NAME : send 0.064 kb messages with pool(5) mode (ops)
TOTAL : 26365 ops in 5.01s
MEAN : 5273 ops / s
MIN : 4190 ops / s
MAX : 6255 ops / s
MEDIAN : 5295 ops / s
BASE ON 5 SAMPLES
NAME : send 0.064 kb messages use AXON original (ops)
TOTAL : 39060 ops in 5.01s
MEAN : 7812 ops / s
MIN : 6265 ops / s
MAX : 9050 ops / s
MEDIAN : 7640 ops / s
BASE ON 5 SAMPLES
NAME : send 0.064 kb messages with pool(5) mode (through)
TOTAL : 1.92 mb in 5s
MEAN : 0.384 mb / s
MIN : 0.286 mb / s
MAX : 0.422 mb / s
MEDIAN : 0.41 mb / s
BASE ON 5 SAMPLES
NAME : send 0.064 kb messages use AXON original (through)
TOTAL : 2.5730000000000004 mb in 5s
MEAN : 0.5146000000000001 mb / s
MIN : 0.487 mb / s
MAX : 0.544 mb / s
MEDIAN : 0.515 mb / s
BASE ON 5 SAMPLES
NAME : send 1 kb messages with pool(5) mode (ops)
TOTAL : 18870 ops in 5.005s
MEAN : 3774 ops / s
MIN : 1880 ops / s
MAX : 5195 ops / s
MEDIAN : 4240 ops / s
BASE ON 5 SAMPLES
NAME : send 1 kb messages use AXON original (ops)
TOTAL : 23900 ops in 5s
MEAN : 4780 ops / s
MIN : 1670 ops / s
MAX : 6200 ops / s
MEDIAN : 5195 ops / s
BASE ON 5 SAMPLES
NAME : send 1 kb messages with pool(5) mode (through)
TOTAL : 20.42 mb in 5s
MEAN : 4.0840000000000005 mb / s
MIN : 3.455 mb / s
MAX : 4.95 mb / s
MEDIAN : 3.88 mb / s
BASE ON 5 SAMPLES
NAME : send 1 kb messages use AXON original (through)
TOTAL : 23.779999999999998 mb in 5s
MEAN : 4.755999999999999 mb / s
MIN : 2.36 mb / s
MAX : 5.93 mb / s
MEDIAN : 4.96 mb / s
BASE ON 5 SAMPLES
NAME : send 8 kb messages with pool(5) mode (ops)
TOTAL : 5035 ops in 5.01s
MEAN : 1007 ops / s
MIN : 615 ops / s
MAX : 1280 ops / s
MEDIAN : 1005 ops / s
BASE ON 5 SAMPLES
NAME : send 8 kb messages use AXON original (ops)
TOTAL : 6185 ops in 5.01s
MEAN : 1237 ops / s
MIN : 940 ops / s
MAX : 1760 ops / s
MEDIAN : 1115 ops / s
BASE ON 5 SAMPLES
NAME : send 8 kb messages with pool(5) mode (through)
TOTAL : 45.56 mb in 5s
MEAN : 9.112 mb / s
MIN : 7.4 mb / s
MAX : 11.36 mb / s
MEDIAN : 8.04 mb / s
BASE ON 5 SAMPLES
NAME : send 8 kb messages use AXON original (through)
TOTAL : 40.120000000000005 mb in 5.025s
MEAN : 8.024000000000001 mb / s
MIN : 1.12 mb / s
MAX : 12.72 mb / s
MEDIAN : 8.8 mb / s
BASE ON 5 SAMPLES
NAME : send 32 kb messages with pool(5) mode (through)
TOTAL : 72.64 mb in 5.005s
MEAN : 14.528 mb / s
MIN : 7.52 mb / s
MAX : 19.84 mb / s
MEDIAN : 15.2 mb / s
BASE ON 5 SAMPLES
NAME : send 32 kb messages use AXON original (through)
TOTAL : 70.72 mb in 5.02s
MEAN : 14.144 mb / s
MIN : 11.84 mb / s
MAX : 19.84 mb / s
MEDIAN : 12.32 mb / s
BASE ON 5 SAMPLES