2009年10月17日 星期六

64bit與32bit應用程式在64位元ubuntu下之效能比較


手邊最近剛好進來了一台i7搭配6G的PC,雖然裝了ubuntu 64bit-server的OS,但是我們的應用程式很多都還是32位元的,而且很好奇到底是64bit的application快,還是32bit的application快,於是我分別將unixbench編譯成32-bit和64-bit進行測試。
結果發現,即便是在64bit的OS下執行程式,32bit的效能不見得比64bit來的差,不是單純的將OS和硬體升級成64位元,電腦就會變快了,應用程式有沒有對64做最佳化也是非常重要的關鍵。

在讀寫方面,64位元小勝32位元。圖表為讀寫10sec所讀寫到的資料量,file system為ext3。

在一些演算法的運算下,各有小勝的項目。

在process的處理上,32bit勝出。


至於system call和pipe則64bit勝出。


檔案複製上,32bit勝出。(這點感覺還挺那悶的)

數值運算上,64bit小勝。

所有數據資料
  64-bit 32-bit  
Dhrystone 2 without register variables 22989948.3 15872890.4 lps
Dhrystone 2 using register variables 23031345.5 15525587.1 lps
Arithmetic Test (type = register) 3795084.9 3800669.2 lps
Arithmetic Test (type = short) 3792994 3475120.4 lps
Arithmetic Test (type = int) 3798887.6 3795243.4 lps
Arithmetic Test (type = long) 1361641.8 3797989.6 lps
Arithmetic Test (type = float) 2999814.7 1755172.6 lps
Arithmetic Test (type = double) 1908910.6 1755790.4 lps
System Call Overhead Test 5310434.8 4194268.7 lps
Pipe Throughput Test 2713396.7 2364773.8 lps
Pipe-based Context Switching Test N/A 421790.3  
Process Creation Test 13766.1 14274.1 lps
Execl Throughput Test 4028.2 4128.9 lps
File Read  (10 seconds) 8619286 7545589 KBps
File Write (10 seconds) 1519095 1453324 KBps
File Copy  (10 seconds) 79768 91090 KBps
File Write (30 seconds) 1515752 N/A KBps
File Copy  (30 seconds) 89420 N/A KBps
C Compiler Test 1826.8 1863 lpm
Shell scripts (1 concurrent) 8495.3 15928.3 lpm
Shell scripts (2 concurrent) 6293.3 12343.3 lpm
Shell scripts (4 concurrent) 4276.7 7584.6 lpm
Shell scripts (8 concurrent) 2818 5387 lpm
Dc: sqrt(2) to 99 decimal places 593737.4 625083.3 lpm
Recursion Test--Tower of Hanoi 244750.3 168275.4 lps
Arithmetic Test (type = double)         751 690.8  
Dhrystone 2 without register variables  1027.9 709.7  
Execl Throughput Test                   244.1 250.2  
File Copy  (30 seconds) 499.6 N/A  
Pipe-based Context Switching Test       0 319.9  
Shell scripts (8 concurrent)            704.5 1346.8  
下載unixbench:
http://www.tux.org/pub/tux/benchmarks/System/unixbench

2009年10月12日 星期一

KVM


KVM是Linux底下的Kernel-based Virtual Machine,而在用KVM前,要先知道CPU本身是否支援硬體VM,否則不能用KVM:
Intel CPU:
grep vmx /proc/cpuinfo
AMD CPU:
grep svm /proc/cpuinfo
如果沒有就不支援kvm啦,不過在執行的時候會被轉成qemu執行,並且出現以下錯誤:
open /dev/kvm: No such file or directory
Could not initialize KVM, will disable KVM support


接著載入kvm.ko,並且根據CPU是Intel還是AMD分別載入kvm-intel.ko或kvm-amd.ko。
相關的套件可以使用以下指令一次安裝:
sudo apt-get install kvm libvirt-bin ubuntu-vm-builder bridge-utils

接著使用kvm-img建立disk,或者直接使用硬碟的partition(/dev/sdaX)。
完整的指令如下:
/usr/bin/kvm -M pc -m 2000 -smp 8 -localtime -boot c -hda /var/lib/libvirt/images/linux.img -hdb /dev/sda2

接著就開始安裝您的guest OS嚕。


2009年10月8日 星期四

AJAX - Asynchronous JavaScript And XML


AJAX算是一個不算是一個新的技術,利用非同步的方式,提供互動式的網頁,AJAX面對最大的問題就是各個Browser之間對Java Script的標準與設計不一,常常寫好的能在FireFox上執行,在IE卻不能執行,所以在設計AJAX的時候最好考慮一下相容性的問題。
簡單的來說,AJAX提供XMLHttpRequest送出request給Web Server,接著等待回應,並處理回應的資料。

XMLHttpRequest

由於Browser之間對Java Script的標準與設計不一,所以下面的寫法可以用於大多數的形況。
// Provide the XMLHttpRequest class for IE 5.x-6.x: // Other browsers (including IE 7.x-8.x) ignore this // when XMLHttpRequest is predefined if (typeof(XMLHttpRequest) == "undefined") { XMLHttpRequest = function() { try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) {} try { return new ActiveXObject("Msxml2.XMLHTTP.4.0"); } catch(e) {} try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) {} try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} throw new Error("This browser does not support XMLHttpRequest."); }; } xmlHttpRequest = new XMLHttpRequest(); 有了XMLHttpRequest之後,我們就可以送出request並且處理資料

xmlHttpRequest.onreadystatechange = function () { //處理來自Server的回應 if(xmlHttpRequest.readyState==4) { alert(xmlHttpRequest.responseText); // Server回應的內容 // 如果回傳的是XML資料可以使用responseXML } } xmlHttpRequest.open("GET","my.php", true); // 設定送出的method(GET/POST), 以及對象(URL) // 基於安全考量,你不能呼叫不同網域的網頁。如果網域不同時會出現「權限不足,拒絕存取」的錯誤。 // 第三個參數設定此request是否不同步進行,如果設定為TRUE,則即使伺服器尚未回傳資料,也會繼續執行其餘的程式。 xmlhttp.send(null); // 送出request
StateDescription
0The request is not initialized
1The request has been set up
2The request has been sent
3The request is in process
4The request is complete



熱門文章