Increase maxSockets

suggest change

Basics

require('http').globalAgent.maxSockets = 25

// You can change 25 to Infinity or to a different value by experimenting

Since v0.12.0, http.globalAgent.maxSockets defaults to Infinity. Before that, the default was 5 (see v0.11.0), and further requests waited in a queue. Setting the property to 25 raises the old limit and lowers the current one.

Setting your own agent

The http API uses a global agent. You can supply your own:

const http = require('http')
const myGloriousAgent = new http.Agent({ keepAlive: true })
myGloriousAgent.maxSockets = Infinity

http.request({
  hostname: 'example.com',
  path: '/',
  agent: myGloriousAgent
}, function (res) {
  res.resume()
}).end()

Turning off Socket Pooling entirely

const http = require('http')
const options = {
  hostname: 'example.com',
  path: '/'
}

options.agent = false

const request = http.request(options)
request.end()

Pitfalls

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents