Skip to content

Commit

Permalink
Polishing the docker example
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Nov 28, 2016
1 parent 3fee180 commit 03f3a84
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ MAINTAINER Jordi Moraleda <[email protected]>
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

ADD package.json /usr/src/app/package.json

# Native dependencies
RUN apk --update add --no-cache make git g++ python zeromq-dev \
&& npm install -g nodemon \
&& git clone https://github.com/TvrboPro/TinyZmq.git . \
&& npm install --production \
&& apk del --purge g++ python

ADD . /usr/src/app

CMD nodemon -L -d 2 example.broker.js
#CMD nodemon -L -d 2 example.worker.js
#CMD nodemon -L -d 2 example.client.js
# uncomment the appropriate command below

CMD nodemon -L -d 1 example.broker.js
#CMD nodemon -L -d 1 example.worker.js
#CMD nodemon -L -d 1 example.client.js
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ To register a client, add this code to the component that places requests:
console.log("THE CLIENT GOT BACK:", response);
});

## Parameterization

The internal behavior can be tuned by using environment variables at run time.

* ```TINY_ZMQ_DEBUG```: By default, disabled when ```NODE_ENV='production'``` and ```true``` otherwise. When set to true, provides extra logging information.
* ```TINY_ZMQ_PING_BASE_INTERVAL```: The client will periodically ping the worker to assert that it is still alive. By default, every ```500``` milliseconds.
* ```TINY_ZMQ_INACTIVITY_TIMEOUT```: After no pingback response from either the client or the worker, the connection will be retried again. By default, the timeout is ```5000``` milliseconds.
* ```TINY_ZMQ_CLIENT_INSTANCES```: The number of client instances running on the environment. This helps to better adjust the actual rate of pings between nodes.
* ```TINY_ZMQ_WORKER_INSTANCES```: The number of worker instances running on the environment.

## Utilities

To get an example of a container running the broker, worker or client on a Linux + NodeJS + ZMQ environment, refer to the ```Dockerfile```.
Expand Down
10 changes: 5 additions & 5 deletions balancing.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const uuid = require('uuid');
const config = require('./config.js');
const procSignals = ['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGTERM'/*, 'SIGUSR2'*/];

const PING_INTERVAL = Math.floor(config.PING_BASE_INTERVAL * config.MATCHER_INSTANCES / config.API_INSTANCES) - 10;
const PING_INTERVAL = Math.floor(config.PING_BASE_INTERVAL * config.WORKER_INSTANCES / config.CLIENT_INSTANCES) - 10;

// STATE

Expand Down Expand Up @@ -159,7 +159,7 @@ function connect(uri){
}

// READY
requester.connect(config.MATCHER_CLIENT_URI);
requester.connect(brokerURI);

// return the method to call us to the client
return sendRequest;
Expand Down Expand Up @@ -199,7 +199,7 @@ function reconnect(){
}

// READY
requester.connect(config.MATCHER_CLIENT_URI);
requester.connect(brokerURI);
}, 50);
}

Expand All @@ -209,8 +209,8 @@ function onTerminate(code){
terminating = true;
if(requester) {
try {
// requester.disconnect(config.MATCHER_CLIENT_URI);
requester.close(config.MATCHER_CLIENT_URI);
// requester.disconnect(brokerURI);
requester.close(brokerURI);
}
catch(e){ ; }
}
Expand Down
10 changes: 2 additions & 8 deletions config-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@

module.exports = {
DEBUG: true,
COMPONENT_NAME: 'TWINS LIB',

PING_BASE_INTERVAL: 500,
INACTIVITY_TIMEOUT: 5000,

MATCHER_CLIENT_PORT: 5559,
MATCHER_WORKER_PORT: 5560,
MATCHER_CLIENT_URI: 'tcp://localhost:5559',
MATCHER_WORKER_URI: 'tcp://localhost:5560',

// Cluster aware
API_INSTANCES: 2,
MATCHER_INSTANCES: 4
CLIENT_INSTANCES: 2,
WORKER_INSTANCES: 4
};
2 changes: 1 addition & 1 deletion example.broker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const broker = require('tiny-zmq').broker;
const broker = require('.').broker;

broker.bind({
clientsPort: 5559,
Expand Down
2 changes: 1 addition & 1 deletion example.client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const client = require('tiny-zmq').client;
const client = require('.').client;

const sendRequest = client.connect('tcp://localhost:5559');

Expand Down
2 changes: 1 addition & 1 deletion example.worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const worker = require('tiny-zmq').worker;
const worker = require('.').worker;

worker.connect('tcp://localhost:5560', function(parameters, doneCallback){
console.log("THE WORKER GOT", parameters);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "tiny-zmq",
"version": "1.0.1",
"version": "1.0.2",
"description": "A NodeJS package that provides simple load balanced messaging on distributed environments",
"main": "index.js",
"keywords": ["zmq", "messaging", "tvrbo", "ventilator", "clustering", "cluster", "load", "balancing", "broker", "worker", "client"],
"keywords": [ "zmq", "messaging", "tvrbo", "ventilator", "clustering", "cluster", "load", "balancing", "broker", "worker", "client" ],
"author": "Jordi Moraleda <[email protected]>",
"repository": {
"type": "git",
Expand Down

0 comments on commit 03f3a84

Please sign in to comment.