I saw the PHP of the Chinese cabbage core to implement multi-thread. For a time, it feels useful to change an ASP version. . Oh, thank you here! (Http://blog.9cbs.net/wapweb/archive/2004/08/16/76319.aspx)
Principle experiment
The principles are of course the same, using the web server to support multithreading, send multiple HTTP requests to the server to the server to complete our work. More detailed analysis, watch the big cabbage core. In the PHP, the ASP is of course XMLHTTP with a package.
Still first experiment, write 2 TXT files at the same time, compare the difference in write time. code show as below:
<%
Startime = Timer ()
'' ---------- ASP implements multi-thread --------- ''
Function Runthread ()
DIM HTTP
SET http = server.createObject ("msxml2.xmlhttp")
Http.open "get", "http://127.0.0.1/thread.asp?action=b", FALSE
Http.send ()
END FUNCTION
Function a ()
DIM Content, Filepath, Myfile
Content = now () & chr (30) & Timer ()
Filepath = server.mappath ("a.txt")
SET FSO = CreateObject ("scripting.filesystemObject")
Set myfile = fso.createtextfile (filepath, true)
MyFile.Write (Content)
Myfile.close
END FUNCTION
Function B ()
DIM Content, Filepath, Myfile
Content = now () & chr (30) & Timer ()
FilePath = Server.mappath ("B.TXT")
SET FSO = CreateObject ("scripting.filesystemObject")
Set myfile = fso.createtextfile (filepath, true)
MyFile.Write (Content)
Myfile.close
END FUNCTION
Request.QueryString ("Action") = "") THEN
Runthread ()
a ()
Else
b ()
END IF
%>
Script Execution Time: <% = FIX ((Timer () - STARTIME) * 1000)%> MS
The result of the run shows:
The time in the A file and the B file is basically the same.
2. Actual application comparison
For example, I also grabbed the HTML code of 2 pages, a SOHU home, one is the SINA home page, use 2 ways: one is the regular order code execution, single thread execution, one is the multi-thread execution here, the comparison page is completed Time, the code is as follows:
Testspeed1.asp:
<%
Startime = Timer ()
Function gethttppage (URL)
ON Error ResMe next
DIM HTTP
Set http = server.createObject ("msxml2.xmlhttp") http.open "pos", URL, FALSE
Http.send ()
IF http.readystate <> 4 THEN EXIT FUNCTION
geternal = BYTES2BSTR (http.responsebody)
Contents = gethttppage
Response.write "
Response.write (Contents)
Response.write " xmp>"
Set http = Nothing
if Err.Number <> 0 Then Err.Clear
END FUNCTION
Function Bytes2bstr (VIN)
DIM STRRETURN
Dim I, thischarcode, Nextcharcode
Strreturn = ""
For i = 1 to lenb (vin)
Thischarcode = ASCB (MIDB (Vin, I, 1))
IF thischarcode <& h80 then
Strreturn = strreturn & chr (thischarcode)
Else
Nextcharcode = ASCB (MIDB (VIN, I 1, 1))
Strreturn = strreturn & chr (thischarcode) * & H100 cint (nextcharcode))
i = i 1
END IF
NEXT
BYTES2BSTR = STRRETURN
END FUNCTION
Gethttppage ("http://www.sohu.com/")
gethttppage ("http://www.sina.com.cn/")
%>
Script Execution Time: <% = FIX ((Timer () - STARTIME) * 1000)%> MS
Testspeed2.asp:
<%
Startime = Timer ()
Function gethttppage (URL)
ON Error ResMe next
DIM HTTP
SET http = server.createObject ("msxml2.xmlhttp")
HTTP.Open "Post", URL, FALSE
Http.send ()
IF http.readystate <> 4 THEN EXIT FUNCTION
geternal = BYTES2BSTR (http.responsebody)
Contents = gethttppage
Response.write "
Response.write (Contents)
Response.write " xmp>"
Set http = Nothing
if Err.Number <> 0 Then Err.Clear
END FUNCTION
Function Bytes2bstr (VIN)
DIM STRRETURN
Dim I, thischarcode, Nextcharcode
Strreturn = ""
For i = 1 to lenb (vin)
Thischarcode = ASCB (MIDB (Vin, I, 1))
IF thischarcode <& h80 trenstrreturn = Strreturn & Chr (thischarcode)
Else
Nextcharcode = ASCB (MIDB (VIN, I 1, 1))
Strreturn = strreturn & chr (thischarcode) * & H100 cint (nextcharcode))
i = i 1
END IF
NEXT
BYTES2BSTR = STRRETURN
END FUNCTION
Function Runthread ()
DIM HTTP
SET http = server.createObject ("msxml2.xmlhttp")
Http.open "get", "http://127.0.0.1/thread.asp?action=b", FALSE
Http.send ()
END FUNCTION
Function a ()
Gethttppage ("http://www.sohu.com/")
END FUNCTION
Function B ()
gethttppage ("http://www.sina.com.cn/")
END FUNCTION
Request.QueryString ("Action") = "") THEN
Runthread ()
a ()
Else
b ()
END IF
%>
Script Execution Time: <% = FIX ((Timer () - STARTIME) * 1000)%> MS
Running time results:
Testspeed1 running time MS testspeed2.asp runtime MS 1 15593 13078 2 13343 14375 3 12828 12515 4 12434 12125 5 12109 11734 6 12281 12140 7 12703 12062 8 13468 12656 9 12328 12187 10 12343 12156 The above 10 times is another page after another One page is executed. Whoever is also arbitrary after anyone. There is a record exception. In order to avoid the network, the following 5 times will test address change cost http://127.0.0.1 11 109 46 12 62 46 13 62 48 14 78 64 15 62 46 or more 5 times is another page after another page implemented. Whoever is also arbitrary after anyone.
Result: It seems to be a little bit. . . . . . . . . . .
Appendix: Attai brother released a "XMLHTTP bulk to grab remote information", intended to talk to him, modify this idea, release it, estimate is to wait.