在铬中有太多的xhr请求 [英] too many xhr requests in chrome
问题描述
我有一个通过xhr2获取PNG文件的紧密循环。在FF和IE10中正常工作。在Chrome中,当我列出的文件大约有5,500个时,我开始出现xhr错误。我喜欢async接口,因为我将这些请求与本地索引数据库存储请求交错。
I have a tight loop that fetches PNG files via xhr2. Works fine in FF and IE10. In Chrome when I list of files hits about 5,500 I start getting xhr errors. I like the async interface since I am interleaving these requests with local indexedDB store requests.
以下代码(我正在使用 xhr2lib 用于抓取, PouchDB 用于IndexedDB API)。
Code below (I am using xhr2lib for fetches and PouchDB for the IndexedDB API).
我知道这是XHR2失败,因为在Chrome中,所有XHR2调用都在SaveDB()调用之前处理。
I know that it is the XHR2 that is failing, since when this works, in Chrome, all the XHR2 calls are processed before the SaveDB() calls. When It fails, I never get the save calls.
function getBlobs(fileList) {
console.log("starting to fetch blobs");
$.each(fileList, function (i, val) {
var path = baseURL + val.id + "." + imageType;
$xhr.ajax({
url: path,
dataType: "blob",
success: function (data) { saveBlob(data, val.size, val.id); }
});
});
}
function saveBlob(blob, length, id) {
if (blob.size != length) {
console.error("Blob Length found: " + blob.size + " expected: " + length);
}
putBlob(blob, id);
++fetchCnt;
if (fetchCnt == manifest.files.length) {
setTimeout(fetchComplete, 0);
}
}
function fetchComplete() {
var startTime = vm.get("startTime");
var elapsed = new Date() - startTime;
var fetchTime = ms2Time(elapsed);
vm.set("fetchTime", fetchTime);
}
function putBlob(blob, id) {
var cnt;
var type = blob.type;
DB.putAttachment(id + "/pic", blob, type, function (err, response) {
if (err) {
console.error("Could store blob: error: " + err.error + " reason: " + err.reason + " status: " + err.status);
} else {
console.log("saved: ", response.id + " rev: " + response.rev);
cnt = vm.get("blobCount");
vm.set("blobCount", ++cnt);
if (cnt == manifest.files.length) {
setTimeout(storeComplete, 0);
}
}
});
}
推荐答案
铬族承认这是他们应该修正的问题: https://code.google.com/p / chromium / issues / detail?id = 244910 ,但同时我已经使用jquery defer / resolve来实现节流,以保持低线程数。
The chromium folks acknowledge this is something that they should fix: https://code.google.com/p/chromium/issues/detail?id=244910, but in the meantime I have implemented throttling using jquery defer/resolve to keep the number of threads low.
这篇关于在铬中有太多的xhr请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!