2012年7月6日 星期五

傳統ASP字串效能改善(A Fast String Builder Class For Classic ASP)

我寫了一支資料匯出的程式, 資料量才 988 筆, 可是居然花了60秒才跑的完, trace 程式後發現是大量字串相加造成的問題.


程式修改之前, 資料 979到987 就需要花掉1秒中,
即1秒只能處理 9筆資料.


程式修改之前, 第1秒可以處理 93筆資料, 
由於字串變大而且重覆相加造成效能變差.


在不修改架構的情況下, 只修改字串相加的地方改用字串物件,
第1秒可以處理到 141筆資料, 而且對於後續資料處理的速度滿固定的,
 每秒都可以處理 140筆左右.


修改架構, 不透過 function 傳回字串, 而是所有的程式存取同一個字串物件,
處理速度可以到1秒 208筆資料, 原本處理60秒才能跑完的 988筆資料,
修改後5秒內可以跑完.




使用 Asp String Builder Object 來處理, ASP的程式範例:

    dim oString
    Set oString = New ASPStringBuilder
    oString.Append "要相加的字串內容"
    myString = oString.ToString()
    set oString = nothing


在 asp 改用 .net 的StringBuilder 來處理, 速度上差不多,  也是5秒內跑完:
心得:
字串處理, 的問題應該解決了, 要克服其他的(程式流程或寫法), 才能讓反應速度再上去...



使用.net 的StringBuilder 來處理, ASP的程式範例:

    dim oString
    Set oString = Server.CreateObject("Max.StringBuilderObject")
    oString.Append "要相加的字串內容"
    myString = oString.ToString()
    set oString = nothing





相關文章:
A Fast String Builder Class For Classic ASP

字串物件 source code 下載:


google keyword:
classic asp stringbuilder


附註: 
應該有其他更好的解決辦法....

2012年7月4日 星期三

pop-up 的子視窗修改父視窗 select box 的方法

直接修改會出錯, 重點在要透過 window.opener.document.createElement 在父視窗做處理即可. 分享相關的 javascript 如下:


// empty Topics select list content
function clearTopicList(select) {
    while (select.length > 0) {
        select.remove(select.length-1);
    }
}

// add item to select element the less
// elegant, but compatible way.
function appendToSelect(select, value, content) {
    var opt;
    //opt = document.createElement("option");
    opt = window.opener.document.createElement("option");
    opt.value = value;
    //var theData = document.createTextNode(content);
    var theData = window.opener.document.createTextNode(content);
    opt.appendChild(theData);
    select.appendChild(opt);
}

    clearTopicList(window.opener.document.reg.your_field);
    appendToSelect(window.opener.document. your_form .your_field ,"your_value","your_text");

分享 asp 副程式 檢查 字串是否為 html tag


'// purpose: 用 "本文內容" 自動判斷文章是 html or text, text 時把 enter 換 <br/>
'// ex: ret = htmlMessage(str)
function htmlMessage(byval str)
    str = trim("" & str)
   
    dim isHtmlContentFlag
    isHtmlContentFlag = IsHtmlContent(str)
    'response.write "<h1>isHtmlContentFlag:" & isHtmlContentFlag & "</h1>" & vbcrlf
   
    if isHtmlContentFlag then
        '// do nothing
    else
        '// do convert.
        str = replace(str,vbCRLF&vbCRLF,"<P>")
        str = replace(str,vbCRLF,"<BR>")
        str = replace(str,chr(10),"<BR>")
    end if
    htmlMessage = str
end function


'// purpose: 檢查 字串是否為 html tag.
'// PS: 其實也可以用 pattern 來做 match 應該會更好.
'// ex: ret = checkIsHtmlContent(str)
'// return:
'//     True: html
'//     False: text
function IsHtmlContent(byval str)
    dim isHtmlContentFlag
    isHtmlContentFlag = not True
   
    if instr(1, str,"<P ",1)>0 or instr(1, str,"<P>",1)>0  or instr(1, str,"<P/>",1)>0 then
        isHtmlContentFlag = True
    end if
    if instr(1, str,"<BR ",1)>0 or instr(1, str,"<BR>",1)>0 or instr(1, str,"<BR/",1)>0 then
        isHtmlContentFlag = True
    end if
    if instr(1, str,"<td",1)>0 and instr(1, str,"</td",1)>0 then
        isHtmlContentFlag = True
    end if
    if instr(1, str,"<ul",1)>0 and instr(1, str,"</ul",1)>0 then
        isHtmlContentFlag = True
    end if
    if instr(1, str,"<div",1)>0 and instr(1, str,"</div",1)>0 then
        isHtmlContentFlag = True
    end if
    IsHtmlContent = isHtmlContentFlag
end function

2012年6月29日 星期五

IIS6 遇到 URL 太長造成 Bad Request (Request Header Too Long)


IIS 7 (Windows Server 2008) 的話是有 GUI 可以設定, IIS 6 (Windows Server 2003) 的話, 好像要過 Regedit 修改註冊檔來完成.

錯誤的畫面如下:


IIS 7 解法:

Error message when you visit a Web site that is hosted on a server that is running Internet Information Services 7.0: "HTTP Error 404.10 - REQUEST_HEADER_TOO_LONG"


http://support.microsoft.com/kb/942077/


IIS 4 + IIS5 解法:

Description of the MaxClientRequestBuffer Registry Value


http://support.microsoft.com/kb/260694


IIS6 (Windows Server 2003) 透過增加2個 key:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters\MaxRequestBytes
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters\MaxFieldLength



再輸入:
net stop http
net stop w3svc
net stop iisadmin


net start http
net start w3svc
net start iisadmin

結果, 居然可行, 成功了... 但URL 的資料量再上去, 就還是收不到值,
結論: 還是乖乖透過 POST 來傳料好了.


2012年6月27日 星期三

firefox 的 window.opener 相容性問題

有一個專案, 需要使用 pop-up 出新視窗來選擇某一些資料, 用 IE + chrome 都正常, 在測試到 firefox 時居然出現下列的錯誤訊息:

說明: user 是 opener 的 form name.


解法很簡單, 多加一個 document 在.user 前問題就解決了, 實測 IE+chrome+ firefox 都正常. Ex: window.opener.document.user.


2012年6月21日 星期四

Background Intelligent Transfer Service 找不到指定的模組,解決辦法

公司有一台主機, 無法使用 IE 進行 Windows Update, 也無法做任何 Windows Update, 原因我猜應該是 Background Intelligent Transfer Service 無法正常啟動, 在系統事件Log 裡, 看到的訊息如下: 找不到指令的模組.



經過執行一連串的指令和重啟Windows 後, 這個服務終於被啟動啦.


長期以來, 高優先順序的更新已累積到 102個, 升級中的畫面如下:



相關文章:
1. google keyword: Background Intelligent Transfer Service 找不到指定的模組

2. 系統更新失敗 BITS無法正常啟用
http://blog.udn.com/bravoboy/4714494

3. 我如何重設 Windows Update 元件?
http://support.microsoft.com/kb/971058/zh-tw

4. [Windows 7_Updated] Win7無法更新,主因:BITS 無法啟動成功
http://www.dotblogs.com.tw/nobel12/archive/2010/04/08/14464.aspx

5. win7無法更新,bits無法啟動(windows 無法啟動 本機電腦的 Background Intelligent Transfer Service 服務。__錯誤126:找不到指定的模組)
http://answers.microsoft.com/zh-hant/windows/forum/windows_other-windows_update/win7%E7%84%A1%E6%B3%95%E6%9B%B4%E6%96%B0bits/54688db3-2cc3-464d-b3e7-9ef02388f97d

2012年6月19日 星期二

anita 提供的 jQuery 版的廣告輪播

我套了一個 jQuery 版本的廣告輪播, 在 google 下 keyword: jQuery slider 就可以查到很多漂亮的 silder, 像是:


  • Agile-Carousel
  • Beautiful jQuery slider-example
  • blaze-slide-show-for-wordpress
  • easyslider1.7
  • JQAdCarousel
  • jqGalScroll.2.1
  • jQueryBlinds
  • jquery-plugins.jquery.com
  • simple-jquery-slideshow
  • slideJS
  • viljamis-ResponsiveSlides.js

最後我用的是超有才華的同事 Anita 提供的版本, 套完的畫面如下:
說明: 上面是套出來的半成品, 實際最後還要等 UI 設計師調整風格來符合目前的網站.


之前用 flash 套出來的畫面如下:


經過 UI 大師 annie 的巧手之後, 就變這樣子啦,超厲害的:



說明: 

  • 通常 UI 設計師 提供的 javascript 範例通常有點亂, 還會有不相關的javascript code 在裡面, 需要 trace 一下才能拿到精簡後的 javascript code.
  • jQuery 版本和 flash 版本的差異在, jQuery 的 UI 要調整比較方便, 而且彈性高, 要增加功能, 也比較方便(例如: 增加是否另外新視窗, 還是原視窗開啟超連結), 而且不支援Flash 的平台(例如: Apple 或低階的Andriod 平台) 上也可以看的UI.



Facebook 留言板