Search code examples
ajaxperformancehtmlxmlhttprequestweb-worker

Ajax Limits in Web Worker


My HTML5 application uses web workers to analyze an image's pixel data from a canvas context. Once the worker has analyzed the data, it makes 3 XHR calls back to my server to update my model. When I was testing the application, I was able to start and run as may workers as I tried, and each worker only made one XHR call back to the server. Everything worked fine.

Now that I attempt to make three async calls from a single worker, I get problems. Looking at Chrome's developer tools, I can see that all 3 calls get fired, but they all get cancelled, except for the last one. This happens if I make any or all of the calls async or not. However, if I use a timer (setTimeout) to fire each call about 500 milliseconds apart from each other, they all work fine.

Any ideas?

In short, my questions are:

1. How many ajax calls can be make at the same time inside a worker?

2. Why did ajax calls get cancelled inside my worker? (solved)

3. Slightly unrelated to my problem at hand, but what is the max number of workers you can start in a single page? Should I stop a worker once I know I won't be sending it any messages?

Thanks

Update: Turns out I solved the problem I was having with async calls getting canceled. The problem was that I had created my own simple ajax class to use inside the worker, and instead of instantiating it for each call, I was using the same instance of this object. So when I made subsequent calls through it after an earlier call had been made, the first call would get cancelled if it hadn't returned before the new call was made. Hope that makes sense.


Solution

  • I have tried with 6 diff ajax calls with no setTimeouts, it works fine for me.

    Do you still get the same error in the latest chrome/safari browser?

    Could be a server behavior. Also, did you try without web worker?