371

In Firefox 3, the answer is 6 per domain: as soon as a 7th XmlHttpRequest (on any tab) to the same domain is fired, it is queued until one of the other 6 finish.

What are the numbers for the other major browsers?

Also, are there ways around these limits without having my users modify their browser settings? For example, are there limits to the number of jsonp requests (which use script tag injection rather than an XmlHttpRequest object)?

Background: My users can make XmlHttpRequests from a web page to the server, asking the server to run ssh commands on remote hosts. If the remote hosts are down, the ssh command takes a few minutes to fail, eventually preventing my users from performing any further commands.

4

9 に答える 9

101

Browserscopeでのネットワークの結果は、一般的なブラウザーのホスト名ごとの接続数と最大接続数の両方を示します。データは「実際に」ユーザーに対してテストを実行することによって収集されるため、最新の状態が維持されます。

于 2010-08-30T03:27:17.083 に答える
7

www.browserscope.orgで確認したところ、IE9 と Chrome 24 では、1 つのドメインに対して 6 つの同時接続、複数のドメインに対して最大 17 の同時接続が可能です。

于 2013-01-29T13:20:35.447 に答える
6

IE 9によると– 変更点は? HttpWatch ブログでは、VPN 経由の場合、IE9 にはまだ 2 つの接続制限があります。

VPN を使用しても IE 9 のパフォーマンスが低下する

PC が VPN 接続を使用している場合、IE 8 での最大同時接続数の縮小について以前に報告しました。これは、ブラウザーのトラフィックがその接続を経由していない場合でも発生しました。

残念ながら、IE 9 は VPN 接続によって同じように影響を受けます。

于 2011-05-25T18:55:09.100 に答える
6

単一ファイルの AJAX テスターを作成しました。楽しめ!!!ホスティングプロバイダーに問題があったという理由だけで

<?php /*

Author:   Luis Siquot
Purpose:  Check ajax performance and errors
License:  GPL
site5:    Please don't drop json requests (nor delay)!!!!

*/

$r = (int)$_GET['r'];
$w = (int)$_GET['w'];
if($r) { 
   sleep($w);
   echo json_encode($_GET);
   die ();
}  //else
?><head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">

var _settimer;
var _timer;
var _waiting;

$(function(){
  clearTable();
  $('#boton').bind('click', donow);
})

function donow(){
  var w;
  var estim = 0;
  _waiting = $('#total')[0].value * 1;
  clearTable();
  for(var r=1;r<=_waiting;r++){
       w = Math.floor(Math.random()*6)+2;
       estim += w;
       dodebug({r:r, w:w});
       $.ajax({url: '<?php echo $_SERVER['SCRIPT_NAME']; ?>',
               data:    {r:r, w:w},
               dataType: 'json',   // 'html', 
               type: 'GET',
               success: function(CBdata, status) {
                  CBdebug(CBdata);
               }
       });
  }
  doStat(estim);
  timer(estim+10);
}

function doStat(what){
    $('#stat').replaceWith(
       '<table border="0" id="stat"><tr><td>Request Time Sum=<th>'+what+
       '<td>&nbsp;&nbsp;/2=<th>'+Math.ceil(what/2)+
       '<td>&nbsp;&nbsp;/3=<th>'+Math.ceil(what/3)+
       '<td>&nbsp;&nbsp;/4=<th>'+Math.ceil(what/4)+
       '<td>&nbsp;&nbsp;/6=<th>'+Math.ceil(what/6)+
       '<td>&nbsp;&nbsp;/8=<th>'+Math.ceil(what/8)+
       '<td> &nbsp; (seconds)</table>'
    );
}

function timer(what){
  if(what)         {_timer = 0; _settimer = what;}
  if(_waiting==0)  {
    $('#showTimer')[0].innerHTML = 'completed in <b>' + _timer + ' seconds</b> (aprox)';
    return ;
  }
  if(_timer<_settimer){
     $('#showTimer')[0].innerHTML = _timer;
     setTimeout("timer()",1000);
     _timer++;
     return;
  }
  $('#showTimer')[0].innerHTML = '<b>don\'t wait any more!!!</b>';
}


function CBdebug(what){
    _waiting--;
    $('#req'+what.r)[0].innerHTML = 'x';
}


function dodebug(what){
    var tt = '<tr><td>' + what.r + '<td>' + what.w + '<td id=req' + what.r + '>&nbsp;'
    $('#debug').append(tt);
}


function clearTable(){
    $('#debug').replaceWith('<table border="1" id="debug"><tr><td>Request #<td>Wait Time<td>Done</table>');
}


</script>
</head>
<body>
<center>
<input type="button" value="start" id="boton">
<input type="text" value="80" id="total" size="2"> concurrent json requests
<table id="stat"><tr><td>&nbsp;</table>
Elapsed Time: <span id="showTimer"></span>
<table id="debug"></table>
</center>
</body>

編集:
rは行を意味し、wは待ち時間を意味します。
最初に開始ボタンを押すと、80 (またはその他の数) の同時 ajax リクエストが JavaScript によって起動されますが、既知のように、それらはブラウザーによってスプールされます。また、それらはサーバーに並行して要求されます(特定の数に制限されています。これがこの質問の事実です)。ここで、リクエストはサーバー側でランダムな遅延 (w によって確立) で解決されます。開始時に、すべての ajax 呼び出しを解決するために必要なすべての時間が計算されます。テストが終了すると、合計時間の半分、3 分の 1、4 分の 1 など、サーバーへの呼び出しの並列処理を差し引いて確認できます。これは厳密でも正確でもありませんが、ajax 呼び出しがどのように完了するかをリアルタイムで確認できる (着信クロスを確認する) と便利です。そして、ajax の基本を示す非常に単純な自己完結型スクリプトです。
もちろん、これはサーバー側が追加の制限を導入していないことを前提としています。
できれば、firebug net パネル (またはお使いのブラウザーの同等のもの) と組み合わせて使用​​してください。

于 2011-04-12T22:42:35.517 に答える
4

私自身のテストを書きました。コードをstackoverflowでテストしたところ、正常に動作し、chrome / FFが6を実行できることがわかりました

var change = 0;
var simultanius = 0;
var que = 20; // number of tests

Array(que).join(0).split(0).forEach(function(a,i){
    var xhr = new XMLHttpRequest;
    xhr.open("GET", "/?"+i); // cacheBust
    xhr.onreadystatechange = function() {
        if(xhr.readyState == 2){
            change++;
            simultanius = Math.max(simultanius, change);
        }
        if(xhr.readyState == 4){
            change--;
            que--;
            if(!que){
                console.log(simultanius);
            }
        }
    };
    xhr.send();
});

さまざまなタイミングで readystate 変更イベントをトリガーできるほとんどの Web サイトで機能します。(別名:フラッシング)

node.js サーバーで、イベント/フラッシュをトリガーするために少なくとも 1025 バイトを出力する必要があることに気付きました。そうしないと、リクエストが完了したときにイベントが 3 つの状態すべてを一度にトリガーするだけなので、ここに私のバックエンドを示します。

var app = require('express')();

app.get("/", function(req,res) {
    res.write(Array(1025).join("a"));
    setTimeout(function() {
        res.end("a");
    },500);
});

app.listen(80);

アップデート

xhr と fetch api の両方を同時に使用している場合、最大 2x のリクエストを使用できるようになりました。

var change = 0;
var simultanius = 0;
var que = 30; // number of tests

Array(que).join(0).split(0).forEach(function(a,i){
    fetch("/?b"+i).then(r => {
        change++;
        simultanius = Math.max(simultanius, change);
        return r.text()
    }).then(r => {
        change--;
        que--;
        if(!que){
            console.log(simultanius);
        }
    });
});

Array(que).join(0).split(0).forEach(function(a,i){
    var xhr = new XMLHttpRequest;
    xhr.open("GET", "/?a"+i); // cacheBust
    xhr.onreadystatechange = function() {
        if(xhr.readyState == 2){
            change++;
            simultanius = Math.max(simultanius, change);
        }
        if(xhr.readyState == 4){
            change--;
            que--;
            if(!que){
                document.body.innerHTML = simultanius;
            }
        }
    };
    xhr.send();
});

于 2014-02-28T20:25:29.317 に答える