Node.js block response

I have unpleasant situation when one of my "long" response in some way blocks another AJAX requests. I call simultaneously 3 different resources:

var list = ['/api/filters','/api/criteria/brands','/api/criteria/genders']  
list.forEach(function(item){$.post(item)})

On server side I could see the following times in logfile:

GET /api/filters 304 51ms
GET /api/criteria/genders 200 1ms
GET /api/criteria/brands 200 0ms

Thats look cool for me, but in browser the picture is absolutely different.

picture with google chrome network tab

So it looks like browser wait for answer on first ( long request ) and only afterwards receive last 2 results.

What could be the reason for this behavior?

Answers


Every browser just handles a specific amount of simultaneous requests at a time. If you fire 10 ajax requests at the same time, the browser put them on a stack and handles one after the other.

You can find more information about the concurrent requests (because that includes images, javascript, etc as well) in browsern in this question.


The node server runs is single threaded and any piece of code that uses CPU cycles blocks the entire process.

As a result, if GET /api/filters does a lot of CPU intensive computations, it will block any other requests till it completes. Adding some more information about what it actually does can help in putting together a better answer.

In case you have IO operations in there, then try to make them asynchronous. That will allow node to serve the other URLs while the first one is doing IO.


Need Your Help

Search filter null exception

android listview search adapter

Each listview column contain 5textview -ID,Initial, Date, Location, Ward.

multiple image store kinect with different name

c++ opencv save

I want to know how to change the default save folder to store differents images with differents names

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.