简体   繁体   中英

Benchmarking the time of AJAX Requests gets added up when interval between them is to low

I'm using jQuery to benchmark the time API Requests take. For this, i'll run the same request repeated in a specific interval. Everything runs just fine.

BUT if I reduce the interval to be significant lower than the time the API Request takes to return, the benchmarked time will add up.

Try to decrease the Interval in the JSBin Example to 100 and you'll see what I mean:

Reduced JSBin Example: http://jsbin.com/azuqUho/4/edit

I've visualized this here: 间隔足够高间隔到低

Since I can't pass the now variable to the success function of getJSON, i'm not sure how to solve this problem.

Any suggestions?

Thanks, Simon

its the browsers connection limit

A browser only do x requests at a time. If you run the intervall too fast, then the requests that runs parallel is greater then x. Lets say x=5 and you run 6 requests. The first 5 requests will return nearly at the same time, the 6. request will take ~double the time (it have to wait until one of the first 5 request is finished)

To prove it I do only 5 requests at a time if(requests<6) { and we see the time stays the same http://jsbin.com/azuqUho/12/edit

使用servlet进行基准测试可以避免计算等待时间,因为浏览器可以发送的请求数量有限。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM