Skip to content

Commit

Permalink
Tests and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyksv committed Jan 25, 2012
1 parent 4e95517 commit de92ea7
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.swp
node_modules/
npm-debug.log
test/config.json
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# tinyhook - limited replacement of hook.io

[hook.io](https://github.com/hookio) is a distributed
EventEmitter built on node.js. In addition to providing a
minimalistic event framework, hook.io ALSO....

In fact hook.io is rather that ALSO than minimalistic event
framework. Now it can do lot of things like accepting messaging
from console, self restoring of mech network when master died,
mdns hooks discovery and so all. This all good, sounds like magic, but
we do belive that hook.io doesn't do its main thing - reliable and
lightweight dispatcing of events.

In contrast tinyhook is created with single goal to provide reliable
and lightweight distributed EventEmitter implementation. It follows
hook.io concept and in some cases it can transparently replace hook.io.

Reliable for us means that application should be able to consists from
dozens of processes running hooks and handle millions of messages a day
witout craching, hight CPU usage and hight memory consumption. On the
momemt of creation it was 2-4 times more effective for CPU usage, memory
consumption and latency of message delivery.

It will be honest to say that it is build with help of light weight nssocket
library which is build by authors of hook.io. I would say many thanks to them!

Enjoy!

## MIT License

Copyright (c) [PushOk Software](http://www.pushok.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 changes: 27 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
{
"name": "tinyhook"
, "version": "0.0.1"
, "private": true
, "main": "./hook"
"author": "Sergey Korotkov <sergeyksv@gmail.com>",
"name": "tinyhook",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "git://github.com/sergeyksv/tinyhook.git"
},
"contributors": [
{
"name": "Marak Squires",
"email": "marak.squires@gmail.com>"
}
],
"main": "./hook",
"engines": {
"node": ">= v0.4.x"
},
"dependencies": {
"eventemitter2": "0.4.x",
"optimist": "0.2.x",
"underscore": "1.3.x",
"nssocket": "0.3.x",
"async":"0.1.x",
"forever": "0.8.x"
},
"devDependencies": {
}
}
13 changes: 13 additions & 0 deletions test/memleaks/MemLeakChild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var Hook = require('../../hook').Hook;
var util = require('util');

var Slave = exports.Slave = function (options) {
self = this;
Hook.call(this, options);
this.on('hook::ready', function () {
this.on('*::someEvent', function (msg) {
})
});
}

util.inherits(Slave, Hook);
16 changes: 16 additions & 0 deletions test/memleaks/MemLeakMaster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var Hook = require('../../hook').Hook;

var hook = new Hook( {
name: 'MemLeakMaster',
silent: true,
local:true,
oneway:true
});

hook.on('hook::ready', function () {
hook.spawn([{src:'../MemLeakSlave.js',name:'MemLeakSlave', silent:true,oneway:true},
{src:'../MemLeakChild.js',name:'MemLeakChild', silent:true,oneway:true},
{src:'../MemLeakChild.js',name:'MemLeakChild', silent:true,oneway:true}]);
});

hook.start();
33 changes: 33 additions & 0 deletions test/memleaks/MemLeakSlave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var Hook = require('../../hook').Hook;
var util = require('util');

var RealMessage = function () {
this.bigData = "";
var i=0;
for (;i<1000;i++) {
this.bigData += "Some simulation of data";
}
}

var Slave = exports.Slave = function (options) {
self = this;
var count = 0;
Hook.call(this, options);

function emitEvent () {
count++;
self.emit("someEvent",new RealMessage());
if (count==100) {
count = 0;
console.log("--------------------------------------");
setTimeout(emitEvent,100);
} else
setTimeout(emitEvent,10);
}

this.on('hook::ready', function () {
emitEvent();
});
}

util.inherits(Slave, Hook);
1 change: 1 addition & 0 deletions test/memleaks/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit de92ea7

Please sign in to comment.