Refer: http://stackoverflow.com/questions/19043355/how-to-use-request-js-node-js-module-pools http://nodejs.org/api/http.html#http_class_http_agent
Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.
Setup Create a directory
$ mkdir requestjs $ cd requestjs
Streaming
You can stream any response to a file stream.
request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))
You can also stream a file to a PUT or POST request. This method will also check the file extension against a mapping of file extensions to content-types (in this case application/json) and use the proper content-type in the PUT request (if the headers don’t already provide one).
fs.createReadStream('file.json').pipe(request.put('http://mysite.com/obj.json')) Request can also pipe to itself. When doing so, content-type and content-length are preserved in the PUT headers.
request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png'))
pool - A hash object containing the agents for these requests. If omitted this request will use the global pool which is set to node's default maxSockets.Generally the pool is a hash object that contains a number of http agent. it tries to reuse created sockets from "keep-alive" connection.
pool.maxSockets - Integer containing the maximum amount of sockets in the pool.
The pool option in request uses agent which is same as http.Agent from standard http library.
Pool keep certain number of sockets to be used by the program. The sockets are reused for different requests. So it reduces overhead of creating new sockets. It uses fewer sockets for requests, but consistently. It will not take up all sockets available. It maintains queue of requests. So there is implicit waiting time . It acts like both a cache and a throttle.The throttle effect will be more visible if you have more requests and lesser sockets The maxSockets property gives maximum concurrency possible. It increases the overall throughput/performance. Drawback is throttle effect is reduced. You cannot control peak overhead