XMLHTTP has the maximum concurrency. Ajax design should consider [zz]

Source: Internet
Author: User

This seriously tested the XMLHTTP concurrent behavior of the three browsers (ie/Firefox/opera), and found that if the user sends a lot of XMLHTTP asynchronous requests at the same time, in this case, the browser does not send requests completely, but has a maximum number of concurrent requests. My machine test found that IE and FF are 2, and opera is 4.

Therefore, it is wise to load dozens of XMLHTTP requests simultaneously on an Ajax page when designing a site. While reducing interface coupling, we should also consider speed issues. In fact, some refined designs can be used to bind multiple requests to send them together for optimization.

The following is my test code:

<? PHP // server ajaxserver. php

Function _ getmicrotime ()
{
List ($ USEC, $ Sec) = explode ("", microtime ());
Return (float) $ USEC + (float) $ Sec );
}
Function _ exit ($ MSG)
{
Echo ("$ MSG/N ");
Exit ();
}

$ Mode = $ _ Get ["Mode"];

$ F = fopen ("$ mode. log", "A + ");
If (! $ F) _ exit ();

$ Begin = _ getmicrotime ();
$ STR = "$ begin/t". $ _ Get ["flag"]. "/t begin/N ";
Fwrite ($ F, "$ Str ");
Fclose ($ F );
Echo ($ Str );

Sleep (2 );

$ F = fopen ("$ mode. log", "A + ");
If (! $ F) _ exit ();
$ End = _ getmicrotime ();
$ STR = "$ end/t". $ _ Get ["flag"]. "/t end/N ";
Fwrite ($ F, "$ Str ");
Fclose ($ F );
Echo ($ Str );

?>

// This Is The. html webpage code: <! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> new document </title>
<Script language = "JavaScript">
<! --
Function $ (ID)
{
Return document. getelementbyid (ID );
}
Function ajax_object (){

VaR;
Try {
A = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
A = new activexobject ("Microsoft. XMLHTTP ");
} Catch (OC ){
A = NULL;
}
}
If (! A & typeof XMLHttpRequest! = "Undefined ")
A = new XMLHttpRequest ();

Return;
}

Function doit (FLAG)
{
VaR uri = "ajaxserver. php? Mode = opera & flag = "+ flag;
VaR x = ajax_object ();

X. Open ("get", Uri, true );
Function callback ()
{
If (X. readystate! = 4)
Return;
If (X. Status = 200)
{
$ ("Result"). Value + = x. responsetext;
}
}
If ("[XMLHttpRequest]" = x. constructor)
{
X. onload = callback;
}
Else
{
X. onreadystatechange = callback;
}
X. Send (null );
}

Function doajax ()
{
Doit (1 );
Doit (2 );
Doit (3 );
Doit (4 );
Doit (5 );
}

 

// -->
</SCRIPT>
</Head>

<Body>
<Input type = "button" value = "doajax" onclick = "doajax ();">
<Textarea Cols = "80" rows = "60" id = "result"> </textarea>
</Body>
</Html>

**************************************** ********
The test result is as follows:
IE test results:
1157288179.03 2 begin
1157288179.03 1 begin
1157288181.03 1 end
1157288181.04 2 end
1157288181.05 3 begin
1157288181.06 4 begin
1157288183.05 3 end
1157288183.06 5 begin
1157288183.09 4 end
1157288185.09 5 end

Test results of Firefox
1157288092.36 1 begin
1157288092.38 2 begin
1157288094.36 1 end
1157288094.38 2 end
1157288094.39 3 begin
1157288094.39 4 begin
1157288096.4 4 end
1157288096.42 3 end
1157288096.42 5 begin
1157288098.43 5 end

Test results of Opera:
1157288410.88 1 begin
1157288410.89 4 begin
1157288410.89 2 begin
1157288410.89 3 begin
1157288412.89 1 end
1157288412.89 2 end
1157288412.92 5 begin
1157288412.92 4 end
1157288412.92 5 begin
1157288412.92 3 end
1157288414.93 5 end
1157288414.95 5 end cited: http://sithere.net/article.asp? Id = 729 & page = 3

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.