Skip to content

Commit

Permalink
Merge pull request #14 from pelias/use-http-keep-alives
Browse files Browse the repository at this point in the history
Use HTTP keep-alives
  • Loading branch information
orangejulius authored Oct 24, 2017
2 parents d77a881 + daa5fcf commit 1a2332e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const http = require('http');
const request = require('superagent');
const _ = require('lodash');

Expand Down Expand Up @@ -47,6 +48,12 @@ module.exports = function setup(serviceConfig) {
}

logger.info(`using ${serviceConfig.getName()} service at ${serviceConfig.getBaseUrl()}`);

// create one HTTP agent with keep alives enabled per service instance
const agent = new http.Agent({
keepAlive: true
});

return (req, res, callback) => {
// only req was passed in so treat res as callback
if (_.isUndefined(callback)) {
Expand Down Expand Up @@ -74,6 +81,7 @@ module.exports = function setup(serviceConfig) {
.set(headers)
.timeout(serviceConfig.getTimeout())
.retry(serviceConfig.getRetries())
.agent(agent)
.accept('json')
.query(serviceConfig.getParameters(req, res))
.on('error', (err) => {
Expand Down

0 comments on commit 1a2332e

Please sign in to comment.