校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁(yè) > 知識(shí)庫(kù) > 用ASP開(kāi)多線程

用ASP開(kāi)多線程

熱門標(biāo)簽:成都銷售外呼系統(tǒng)公司 土地證宗地圖標(biāo)注符號(hào) 鎮(zhèn)江云外呼系統(tǒng)怎么樣 電話機(jī)器人銷售公司嗎 vue 地圖標(biāo)注拖拽 電話機(jī)器人案例 自動(dòng)外呼系統(tǒng)怎么防止封卡 保定電銷機(jī)器人軟件 客服外呼系統(tǒng)呼叫中心

在網(wǎng)上找到一個(gè)用ASP開(kāi)的假線程,發(fā)現(xiàn)和我以前做的一個(gè)程序不謀而合,只不過(guò)以前用的是VB,摘下來(lái),儲(chǔ)備.

1.原理實(shí)驗(yàn) 原理當(dāng)然都一樣,利用web服務(wù)器支持多線程,在同一頁(yè)面里向服務(wù)器發(fā)多個(gè)http請(qǐng)求來(lái)完成我們的工作。還是先實(shí)驗(yàn)一下,在一個(gè)頁(yè)面里同時(shí)寫2個(gè)txt文件,比較寫入時(shí)間的差異。代碼如下: %

startime=timer()
''----------asp實(shí)現(xiàn)多線程----------''
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
if(Request.QueryString("action")="") then
runThread()
a()
else
b()
end if
%> Script Execution Time:%=fix((timer()-startime)*1000)%>ms 運(yùn)行后的結(jié)果顯示: a文件和b文件中的時(shí)間是基本相同的。 2.實(shí)際應(yīng)用比較 比如我同時(shí)抓取2個(gè)頁(yè)面的html代碼,一個(gè)sohu首頁(yè),一個(gè)是sina首頁(yè),用2種方式:一個(gè)是常規(guī)的順序的代碼執(zhí)行,單線程執(zhí)行,一個(gè)是這里的多線程執(zhí)行,比較頁(yè)面完成時(shí)間,代碼如下: testspeed1.asp: %
startime=timer()
function getHTTPPage(url)
on error resume next
dim http
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "POST",url,false
Http.send()
if Http.readystate>4 then exit function
getHTTPPage=bytes2BSTR(Http.responseBody)
contents = getHTTPPage
Response.Write "xmp>"
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(CLng(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 resume next
dim http
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "POST",url,false
Http.send()
if Http.readystate>4 then exit function
getHTTPPage=bytes2BSTR(Http.responseBody)
contents = getHTTPPage
Response.Write "xmp>"
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(CLng(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
if(Request.QueryString("action")="") then
runThread()
a()
else
b()
end if
%> Script Execution Time:%=fix((timer()-startime)*1000)%>ms 運(yùn)行的時(shí)間結(jié)果: 次數(shù) Testspeed1運(yùn)行時(shí)間ms Testspeed2.asp運(yùn)行時(shí)間ms 1 15593 13078 2 13343 14375 3 12828 12515 4 12437 12125 5 12109 11734 6 12281 12140 7 12703 12062 8 13468 12656 9 12328 12187 10 12343 12156 以上10次是一個(gè)頁(yè)面完后另一個(gè)頁(yè)面再執(zhí)行的。誰(shuí)先誰(shuí)后也是任意的。有一條記錄異常。 為了避免網(wǎng)絡(luò)的原因,以下5次將測(cè)試地址改成本機(jī)http://127.0.0.1 11 109 46 12 62 46 13 62 48 14 78 64 15 62 46 以上5次是一個(gè)頁(yè)面完后另一個(gè)頁(yè)面再執(zhí)行的。誰(shuí)先誰(shuí)后也是任意的。 結(jié)果:好象是要快一點(diǎn)哦。。。。。。。。。。。

標(biāo)簽:公主嶺 重慶 懷化 臺(tái)灣 麗江 天津 內(nèi)江 成都

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《用ASP開(kāi)多線程》,本文關(guān)鍵詞  用,ASP,開(kāi)多,線程,用,ASP,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《用ASP開(kāi)多線程》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于用ASP開(kāi)多線程的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 丹寨县| 醴陵市| 罗山县| 宕昌县| 沧源| 九龙城区| 靖西县| 荃湾区| 报价| 泉州市| 河南省| 永昌县| 孟津县| 兴隆县| 抚顺县| 北流市| 柞水县| 天台县| 通州区| 梧州市| 景宁| 周至县| 怀远县| 册亨县| 基隆市| 西丰县| 长武县| 县级市| 星子县| 龙岩市| 吉林省| 通道| 平湖市| 铅山县| 恩平市| 改则县| 哈尔滨市| 出国| 林甸县| 蕲春县| 文化|