Actually now that I look at the Agent code, it looks like it sets maxSockets on a per domain basis in an Agent:
1 Agent.prototype.addRequest = function(req, host, port) { 2 var name = host + ':' + port; 3 if (!this.sockets[name]) { 4 this.sockets[name] = []; 5 } 6 if (this.sockets[name].length < this.maxSockets) { 7 // If we are under maxSockets create a new one. 8 req.onSocket(this.createSocket(name, host, port)); 9 } else {10 // We are over limit so we'll add it to the queue.11 if (!this.requests[name]) {12 this.requests[name] = [];13 }14 this.requests[name].push(req);15 }16 };
上面的意思就是如果你在代理对象上设置了 maxSockets 这个属性,那对于每一个域名下的 sockets 数量就应该≤ 这个数目,有新的req进来,看看有没有超,没超过,就加进去,超了,就先放放在这个域名下的队列里。