title: Performance of NodeJS with large amount of callbacks
body: <p>I am working on a NodeJS application. There is a specific RESTful API (GET) that, when triggered by the user, it requires the server to do about 10-20 network operations to pull information from different sources. All these network operations are async callbacks, and once they ALL are finished, the result is consolidated by the nodejs app and sent back to the client. All these operations are started in parallel via async.map function.</p>
  
  <p>I just want to understand, since nodejs is single threaded, and it does not make use of multi-core machines (at least not without clustering), how does node scale when it has many callbacks to process? Does the actual processing of callbacks depend on node's single thread being idle, or are callbacks processed in parallel as well as the main thread?</p>
  
  <p>The reason why I ask is, I see the performance of my 20 callbacks deteriorate from the first callback to the last one. For example, the first network operation (out of the 10-20) takes 141ms to complete, whereas the last one takes about 4 seconds (measured as the time from when the function is executed, until the callback of the function returns a value or an error). They are all the same network operation hitting the same data source, so the data source is not the bottleneck). I know for a fact that the data source takes no more than 200ms to respond to a single request.</p>
  
  <p>I found this <a href="https://stackoverflow.com/questions/18080953/nodejs-callback-mechanism-which-thread-handles-the-callback">thread</a>, so it looks to me that the one single thread needs to address all callbacks AND new requests coming up.</p>
  
  <p>So my question is, for operations that will trigger many callbacks, what is the best practice in optimizing their performance?</p>