Skip to content

Commit

Permalink
Merge pull request #2 from See-d-SAS/master
Browse files Browse the repository at this point in the history
Number of instances as arg
  • Loading branch information
theplatypus authored Aug 6, 2017
2 parents 38f1a63 + 50b5385 commit 9d3197a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ WORKDIR /srv/RExpress

RUN npm install
WORKDIR /srv/RExpress/lib
CMD node ./api.js
CMD ["sh", "-c", "node ./api.js ${NB_WORKERS}"]

EXPOSE 80
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ cd RExpress
npm install

cd ./lib
node ./api.js
node ./api.js # nb_workers = 4 * nb_threads
node ./api.js 4 # 4 workers

```

Expand Down Expand Up @@ -119,7 +120,10 @@ cd RExpress
docker build -t seed/RExpress .

# run image in a container
docker run -p 8080:80 seed/RExpress
docker run \
-p 8080:80 \
--env NB_WORKERS="4" \
seed/RExpress

# access RExpress at 192.168.99.100:8080 (your docker bridge0 addr)

Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.2.0
15 changes: 12 additions & 3 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ const bodyParser = require('body-parser');
const multer = require('multer'); // v1.0.5
const upload = multer(); // for parsing multipart/form-data

const os = require('os');

let app = express();
const text_parser = bodyParser.text();

const port = 80 ;

let verbose = false;
let verbose = false ;

// number of workers ; first arg or 4 * nb of cores (default)
const nb_workers = Number(process.argv[2]) ?
Number(process.argv[2])
: os.cpus().length * 4


const log = console.error.bind(console, "[api.js] ")
const trace = (blabla) => {
if(verbose) log(blabla);
Expand All @@ -26,14 +35,14 @@ fs.readdir('../R/', (err, files) =>{
if (file.endsWith('.R')) sources += 'source("../R/' + file + '")\n' ;
}
// builds the R interpreters pool -- 8 workers ; ../R folder
pool.init(8, sources, (err, res) => {
pool.init(nb_workers, sources, (err, res) => {
if(err) trace(err);
else trace('pool ready');
});
})

app.get('/', function (request, response) {
response.send('RExpress 0.1.1')
response.send('RExpress')
})
// call a function w/ form-data (safe)
.post('/R/:function', upload.array(), function (request, response) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"express": "^4.14.1",
"multer": "^1.3.0"
},
"devDependencies": {},
"devDependencies": {
},
"scripts": {
"test": "node ./api.js"
"start" : "cd ./lib && node api.js"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 9d3197a

Please sign in to comment.