2015-10-04

WordPress Replication

手上有兩台異地不同 Public IP 主機,在 CloudFlare 設定 DNS Round Robin,又運行著 WordPress,下面解說如何設定兩台主機同步。讓兩台主機都能登入,且新文章能互相同步。

MySQL 資料庫

參考 MySQL Replication 設定。要注意的是因為做的是 DNS Round Robin,所以隨機兩台主機都要設定 master-slave 兩種角色同時運行,我參考 Digital Ocean 的文章完成。

同步腳本

因為 WordPress 要處理 cache、files 資料夾,腳本請參閱 FTP Replication。

FTP Replication

我有兩台異地不同 Public IP 主機,在 Cloud Flare 設定 Round Robin,運行著 nginx。此文講解使用兩個腳本同步檔案。

我的 H0 機器讓人 FTP 上傳檔案,監控程式偵測有檔案異動及開始 rsync 到 H1。示意圖如下:



H0


L3 ~ L6: 因為 web root 權限需要,所以使用 sudo 提高權限。
L8: H0 & H1 透過 ssh 加密傳輸,得事先加信任公鑰。 L14 ~ L15: inotifywait 排除掉不想監控的檔案 ([Tt]hunms.db),接著只監控特定事件 (delete, moved_to, close_write, create)。為了記錄過程我把時間戳一並寫出,log 的樣子會長這樣:
15/10/04 21:37:05 CREATE /var/www/example.com/index.html
L9: 在 H1 機器上有個 pool 目錄放置這些需要同步的檔案,原因不想讓 rsync 直接寫到 web root,權限過大危險。
L21: 移除前綴字,避免同步路徑錯誤。
L24: 移除檔案名稱,讓 rsync 同步資料夾,而非單一檔案。
L26: rsync + ssh 同步資料夾到 H1。

H1


L3 ~ L6: 因為要寫入到 web root,要求得是 root 。
L13 ~ L26: 做的事情和 H0 一樣,只是來源和目的互換。

已知問題

刪除

inotifywait 遇到刪除檔案或目錄,只會出現 OPEN,ISDIR,接著就沒了,所以也無法偵測到 DELETE 事件。rsync 直到下個時間才會把上個未刪除的工作做完。


2015-10-02

GoDaddy 註冊系統有安全疑慮

GoDaddy 註冊系統只接受最長 11 個字的 local-part,而 Email 地址的規範 RFC 5322 明確指出最長可以到 64 個字。

緣由

我在 GoDaddy 註冊了一個帳號,我的 Email local-part 有 30 個字,因為某個原因我需要重新登錄網站,結果就無法登錄。查了 Whois 發現 GoDaddy 把我的 Email 縮短了,而且是沒有規則。

客服

0. 官網沒有文字客服

GoDaddy 不知緣由為何,停止了文字客服,只剩電話客服。因為擔心英文口說無法順利解決我的問題,且如此長的國際電話肯定所費不貲。最後讓我找到了 @GoDaddyHelp。

1. 英譯證件

GoDaddy 客服來信要求我提供英文翻譯的官方證件,原先試著自己 PS 將身分證翻譯成英文版本,但是客服不接受這種翻譯。後來我提供了護照,但是由於當初註冊使用的名字不是漢語拼音,而是沒有法律效力的自取英文名字。我在信中和對方表明當初我沒有想到註冊會失敗,且我的自取英文名字和漢語拼音的用處。客服人員基於保護客戶帳號安全,提供了三個方式:

0. 試著聯繫 Whois 上面錯誤的 Email。
1. 透過 ICANN 投訴。
2.  法院傳票要回。

2. 將錯就錯

GoDaddy 客服拒絕我的護照證明後,我在信中嚴厲的反應這是網站註冊系統的瑕疵,造成我的困擾。客服根本不想回應我的理由,因為他有理由可以假設我是壞人,透過如此手段竊取別人的域名,想想也是有道理,就不在此爭端,徒勞罷。

我讀了 ICANN 投訴的方式,根據 2015-03-01 發佈的 Rules for Uniform Domain Name Dispute Resolution Policy,投訴方得負擔所有調查的費用,看了 GODADDY SUBPOENA POLICY/ATTORNEY TIPS 光研究每小時就得付 75 USD,這已經超出我的域名購買費用,不划算。

最後,我想到了將錯就錯的伎倆,去申請 Whois 錯誤的 Email。因為是 Gmail 所以可以隨意申請,果真行得通,重置密碼的信件順利收到,把登入權限給拿回來了!


安全疑慮

一拿到登入權限後,試著在後台變更 Email 為 30 個字的帳號,發現依然不行,然後聯繫 @GoDaddyHelp,得到的答案是:

I was not able to duplicate this in another account. You may want to try using an alternate email address.

這種回答讓我對 GoDaddy 灰心,工程文化沒落實完全,如此簡單的註冊瑕疵能用這麼簡單的方式拿回權限,如果今天我就是壞人呢?

2015-09-01

事件捕捉進化

最近寫網頁爬蟲用到並行的方法,因為 golang 接收 channel 是外層包一個 for loop,觀察到這樣會讓一個邏輯 CPU 使用率滿載,這個寫法是 busy waiting,認為這麼做耗電很浪費資源。或許 golang 採用 CSP channel 就是決定得走 busy waiting。

找到一篇 Haskell 討論 select(2) 或 poll(2) 捕捉方法,有人提出這些討論的視野都是較為底層,在 Haskell 可以用更高階優雅的方式解決。閱畢感到興奮,就是要優雅!

2014-10-08

iOS 安裝 in-house app 需要的網站

因為所處的 wifi 網路環境封鎖所有 outbound,要開放 iOS Enterprise Distribution 安裝所需的網路。修改了 iPhone wifi DNS server,得到以下記錄。


  1. 17-courier.push.apple.com
  2. 1-courier.push.apple.com
  3. 26-courier.push.apple.com
  4. 2-courier.push.apple.com
  5. 31-courier.push.apple.com
  6. 36-courier.push.apple.com
  7. 40-courier.push.apple.com
  8. 9-courier.push.apple.com
  9. a1441.g4.akamai.net
  10. a97.gi3.akamai.net
  11. apple.com
  12. apple-finance.query.yahoo.com
  13. cl4.apple.com
  14. e2842.e9.akamaiedge.net
  15. init-p01st.push.apple.com
  16. local
  17. mesu.apple.com
  18. p24-keyvalueservice.icloud.com
  19. p24-keyvalueservice.icloud.com.akadns.net
  20. setup.icloud.com
  21. www.apple.com
  22. www.isg-apple.com.akadns.net
  23. xp.apple.com

2014-05-14

CoreImage & GPUImage performance

The benchmark suite numbers,

Specs

iPhone 5s
iOS 7.1.1
GPUImage 0.1.4

Still images

CPU 181.51ms
Core Image 37.08ms
GPUImage 49.62ms

Live video

CPU 15.77ms
Core Image 3.20ms
GPUImage 2.36ms

2014-04-03

xcodebuild

xcodebuild is a command line that in charge of some actions in Xcode, like build, analyze, archive, test, installsrc, install and clear.


Let says, I need release with a enterprise provision file, so here is the script,


2014-02-07

iOS 免加 UUID 發佈方式

以往都由 Apple 審核發佈 app,測試階段都是在自己的設備上,都能知道 UUID。目前做的 app 需要免加 UUID 任由安裝,Apple 稱為 in-house distribution,能有此功能只有 iOS Developer Enterprise Program 才做得到。

2013-12-18

IRC 紀錄即時推送

irssi + inotify-tools + git 即時將紀錄推送到 github。

Irssi

首先將 irssi 紀錄檔設定為每天切割:
/log open -autoopen -targets #tcffm ~/irclogs/Freenode/#tcffm-%Y-%m-%d

Git init

cd ~/irclogs/Freenode
git init
touch README
git add README
git commit -am "First commit."
git remote add origin git@github.com:OOO/tcffm.git
git push -u origin master

腳本

1. daily.sh
此腳本使用 crontab 每天 0:00 啟動,內容如下:
#!/bin/bash
killall -9 inotifywait
cd '/home/OOO/irclogs/Freenode'
today=$(date +%Y-%m-%d)
git add \#tcffm-$today
inotifywait -qme modify --format "sh onchange.sh %w" \#tcffm-$today | sh
2. onchange.sh
#!/bin/bash
git commit -am "log"
git push
將兩個腳本權限設定為 755

啟動

執行 ~/irclogs/Freenode/daily.sh


後記

inotifywait 可以監看每個檔案修改的動作,產生對應的動作。

2013-11-28

Concurrency

以前總覺得 concurrency 很難很酷,如 pthread 那樣精深,難上手。最近三年的工作經驗認識 asynchronous I/O,發現這是一種 concurrency,才覺得沒有這麼夢幻,覺得實用。我的工作經驗上,沒遇過 concurrency computing。

以 Computer Memory Hierarchy 解釋,CPU 以外的 I/O 都是很慢的,讓  CPU 等待是罪過,此決定掌握在 programmer 手上。

使用 aio 方式我用過幾種:
1) Object-C delegate
初體驗,也是啟發的框架。

2) go goroutine + channel
新語言的設計。

3) JavaScript ajax + callback
常見的方式。

自從開始有這些體驗,盡量落實每個動作都是 async,朝 C10M 邁進。

2013-10-22

德國電信商保護境內資料

從美國竊聽流往法國通信被揭露,看到德國的電信商正在研擬一個計畫,加強保護境內資料。只要是發送端和接收端都在德國,或是德活盟友。透過路由設定,資料只會在國內走,不會往外。目前看來影響不大,因為太多服務提供者不在德國。

這個草案表現出一個態度,德國人不喜歡被監聽,可能不選擇美國服務,且自身加強保護。如此一來,德國民眾可能會有更多自己國家的服務,形成特殊現象。

2013-08-08

使用 rsync & git 建立每日備份

工作上遇到災難,救災完畢後評估使用 rsync 和 git 建立每日還原點。

災難是:
前人建立某個帳戶,家目錄在 /,用 userdel -r 清理舊帳戶,時間過久才發現災難已經造成。
兩個月前閒來無事,有做系統總備份,httpd 和 mysql 是兩個月前的紀錄,客戶難免唉唉叫。救災完畢後,使用 git 建立每日備份。

主機特性是代管客戶網頁資料,包含圖片和資料庫。

概略步驟是:
1. rsync 初始,git init
2. 每日 rsync 同步,git commit
3. 每日產生 git bundle

Webpages

使用 rsync 將來源抓到工作目錄,然後在工作目錄建 git 資料夾。


接著每天做備份



最後每天產生 git bundle


MySQL

和 webpages 相似的步驟,先初始




接著每天備份,產生 git bundle




最後產生 git bundles




還原




後記

災難後尋找備份方案時,見到有人每日、每週、每月做不同程度的備份。記得將每日的動作放進 crontab 定時執行,放在離峰時間比較不影響服務品質。

資料搞失或資料復原都需要付出慘痛的代價,如果能做成自動化,可以降低很多反應時間和損失。

2013-05-29

Notification 掉包

Google Cloud Messaging 和 Apple Push Notification Service 對於發佈推撥期間裝置離線的處理,都採以下政策:

只送最後一則。

引用 GCM:
GCM will usually deliver messages immediately after they are sent. However, this might not always be possible. For example, the device could be turned off, offline, or otherwise unavailable. In other cases, the sender itself might request that messages not be delivered until the device becomes active by using the delay_while_idleflag. Finally, GCM might intentionally delay messages to prevent an application from consuming excessive resources and negatively impacting battery life.
GCM Advanced Topics, Setting an Expiration Date for a Message
引用 APNS:
If APNs attempts to deliver a notification but the device is offline, the notification is stored for a limited period of time, and delivered to the device when it becomes available. 
Only one recent notification for a particular application is stored. If multiple notifications are sent while the device is offline, each new notification causes the prior notification to be discarded. This behavior of keeping only the newest notification is referred to as coalescing notifications. 
If the device remains offline for a long time, any notifications that were being stored for it are discarded.
Local and Push Notification Programming Guide, Quality of Service

所以要自己做驗證,確保推撥有成功。

比較 Naver LINE Android 和 iOS 版本對於離線訊息的處理,一旦接上網路,離線訊息一併收到數則。猜測可能的作法是:

1. Device offline
2. Send #1 msg, server enqueue 1 msg
3. Send #2 msg, server enqueue 2 msgs
4. Device online
5. Server send queue
6. Device splits msgs and local notificate one-by-one.

2013-03-28

2013-01-09

MD5 使用注意事項

在 Go  裡使用 md5 做校驗不難,如範例所寫:


若要在迴圈裡做上面的事情,可能會有這樣的寫法:


跑出來的結果是:


f1() 和 f2() 會有不同的結果是因為 io.WriteString 在 md5.go 實作細節, WriteString 會找 Writer 的實作,而在 md5.go 的實作如下:


看見 += 就可以猜的出來是附加的方式,所以每次非得使用新的 instance,目前還沒發現能清除 digest 內容的方法。

2012-11-08

Go



這篇記錄最近一個多月學習 Go 的心得。Go 的語法相對於 Object-C 簡潔,後置的資料型態變數宣告,可以懶惰省去資料型態宣告。

有兩件事情是我碰壁許久:

json.Marshal



執行結果會得到:


p1 is: {"FirstName":"John","LastName":"Doe"}.
p2 is: {}.


要輸出的成員變數必須大寫開頭才行,下面的 package 方法同樣套用。


Exported Functions


隨意撰碼都需要模組分割,追問題容易,讀碼速度快。Go 使用資料夾結構定義 package 封裝,捨棄 Makefile。How to Write Go Code 闡述如何做到模組化,所有細節皆有提到就是 Function name 首字要大寫沒提到[1],所以一直看到

./main.go:10: cannot refer to unexported name foo.foo1

程式碼如下:

foo.go

main.go

這是最近的心得。


Updated:
1. 在 The Go Programming Language Specification 的 Exported identifiers 有提到這些細節。

2012-05-09

Toggle network for iOS Simulator

Network fault-tolerant is important to asynchronous request. For iOS simulator can not toggle the network easily, because of its network ability is binding to its level. So that if you turn your host network off, then your iOS simulator network is also down. However, the host lost all network connection.

The firewall rule can help me do that smart, just block the site and port you would. You can use the below script:



You can change the host you want block in line 3 banHost.

2012-04-24

Git hooks Xcode version

Xcode has two fields to set version information to app. Version is for releasing number, build is for building number, find more information in Information Property List Key Reference.


Since Xcode 4.0 starting to support git version control, so that we could bind git tag and commit hash text with Xcode field. The steps in the pseudo-code are below:


  1. $ git commit -am "COMMIT LOG"
  2. trigger post-commit hooking
  3. Setting the tag number and new commit hash to plist.


In the real code is like below:


Put the code in a file to PROJECT_FOLDER/.git/hooks/post-commit, and make it executable.

2012-04-19

TEPopUp uses resizableImageWithCapInsets



TEPopUp show a pop-up view that stands on a translucent view, it can add something in the dialog view easily.


TEPopUp dialog use the api, UIImage resizableImageWithCapInsets:, it needs not a full size picture as its background picture, instead of a 28x28 pixel small picture. Obviously, this technical can reduce the who app size. The main core code cuts the area of pattern image, from the center point to right-bottom corner by UIEdgeInsetsMake. Then, the UIImage returns a new instance thats already expand image to appropriate size.

2012-01-10

UIScrollView 卡關排解

因為卡了三次,特別提醒自己。

若要做成兩頁,則 contentSize 要涵蓋兩頁寬度。

2011-11-18

Owned scan screen in ZBar

By studying the ZBar iPhone SDK document, I need to preview the camera on my own UIView, then, show the scanned image and text, that's all. All I need is to use ZBarReaderView and ZBarImageScanner, the mainly code snippet as below: The screen result like below:
Check out the full sample from github.

2011-11-16

露天拍賣密碼

修改密碼網頁

希望使用者輸入至多 15 個字元,可是 html 語法卻寫成:




正確寫法是:



另外,登入頁面




修改密碼規定 15 個字元,這裡卻限制 24 個字元,明顯裡外不一。

2009-11-16

Installing XP: ***STOP: 0x0000007B (0xF78D2524,0xC0000034,0x00000000,0x00000000)

Platform: Lenovo SL400 (2743-RK3)

When installing Windows XP, during the booting procedure, it shows up the BSOD screen, "Installing XP: ***STOP: 0x0000007B (0xF78D2524,0xC0000034,0x00000000,0x00000000)". After run the complete memtest86+, it occurs again.

The solution is here, disable HD drive from ACHI to Compatibility.

2009-08-04

Converting integer to string in ANSI C


const char *base = "BLAH BLAH BLAH";
unsigned int idx = 0;
char *buf = NULL;

buf = (char *) malloc (strlen (base) + sizeof (unsigned int));
sprintf (buf, "%s%d", buf, idx);
printf ("buf: %s\n", buf);


Output
BLAH BLAH BLAH0

2009-05-29

Compaq CQ60-201AU downgrade

First ball, thanks to Compaq Presario CQ60-104AU/ CQ60-210AU 改 XP takes me many hints, and special thanks to Conexant High Definition SmartAudio 221 probbblemmmm!(WİNDOWS XP DRİVERS=), they were just discussing the audio driver.

This downgrade makes me understand that, some vendors combine some components of their product whole only supports vista drivers, it's really sucks. Fortunately, many geeks turn it works fine. So we can search their great solution and study its experiences.

2009-05-22

Why was your message broken?

I like send messages rather than dialing to communicate wtih my cellphone. As using so far, I have a big problem in my mind, that, why was messages broken when it was enough long to send? I had asked my service provider CHT, the service-person told me that caused by my OLD-SYLTE-PHONE, it is never happen with newer phone. I did not believe that anyhow. Until today morning, I have read a article on OSNEW.com, Why Text Messages Are Limited to 160 Characters, that pushes me to find something more out.

My Nokia 1650 cellphone supports SMS, EMS and Instant Messaging, spec page said that supports length up to 250 characters, not as long as wikipedia SMS page said, 160 characters.

I have not yet find anything solves it problem to normal message.

2009-05-21

Abortion

Anyone has this information who has mentioned "abortion". :P

glibc 25.6.4 Aborting a Program


Future Change Warning: Proposed Federal censorship regulations
may prohibit us from giving you information about the possibility of
calling this function. We would be required to say that this is not an
acceptable way of terminating a program.



Explanation: Re: Federal censorship regulations

The warning may be tongue in cheek. Anyone living in the US is
aware of the extreme sensitivity of the abortion issue (as it
applies to human foetuses, not computer programs).

Allin Cottrell.

2009-02-27

Compilin SQLite from source code

This article is describe how to compile SQLite 3 from its source code scratch.

Steps

1. Setting current path as $TOP variable.
export TOP=`pwd`

2. Getting source code tarball from official web site, and save it to $TOP.
wget http://www.sqlite.org/sqlite-3.6.11.tar.gz -O $TOP/sqlite-3.6.11.tar.gz

3. Extracting
cd $TOP; gzip -dc sqlite-3.6.11.tar.gz | tar -xf - ; cd sqlite-3.6.11

4. Detecting something in system environment.
./configure

5. Executing make if previous step successful. Doing debug with err.txt if errors occurs during makeing.
make 1> /dev/null 2> err.txt

6. Installing files to system (/usr/local/), need root permission.
# make install

2009-02-13

tmux - terminal multiplexer

Install steps
1. Downloading all packages, assume you're in bash shell.
wget -c http://mentors.debian.net/debian/pool/main/t/tmux/tmux_0.5{-1.d{iff.gz,sc},.orig.tar.gz}


2. Unpacking and patch, then compie it.

$ gzip -d tmux_0.5-1.diff.gz
$ tar -zxf tmux_0.5.orig.tar.gz; cd tmux-0.5
$ patch -Np1 < ../tmux_0.5-1.diff
# make 1> /dev/null 2> err.txt && make install


3. Tuning it

.tmux.conf

set prefix ^\
set status on
set status-bg yellow
set status-fg block
set status-right " "


# For 0.7

unbind ^b
set -g prefix ^\
send-prefix
set -g status on
set -g status-bg yellow
set -g status-fg black
set -g utf8 off


.bashrc
alias t='tmux attach -d'



Drawbacks
under testing...

Really runs faster than GNU Screen!!

References
OSNews, Stayin' Alive with GNU Screen, http://osnews.com/comments/20962
mentors.debian.net, http://mentors.debian.net/debian/pool/main/t/tmux/

2009-02-12

SSH Tunnel memo

ssh -CND ${OUTDOOR_PORT} ${USER}@${REMOTE_SERVER}


Specifies a port ${OUTDOOR_PORT} forwarding (-D) to ${REMOTE_SERVER} with ${USER}, that without executing the remote commands (-N), and requests all data compressed (-C).


Firefox
Changing its SOCKS Host to localhost and Port to ${OUTDOOR_PORT}.

Opera
Installing the tsocks, do manipulate with links article.


References:
1. code in the ruins, Opera 9/SOCKS hack, http://code.mogrify.org/2006/07/05/opera-9socks-hack/
2. polishlinux.org, SSH Tunnels: Bypass (Almost) Any Firewall, http://polishlinux.org/apps/ssh-tunneling-to-bypass-corporate-firewalls/

2009-01-01

Why didn't Plan 9 take over the world?

Plan 9: The Way the Future Was

Reasons:
*scanty documentation, much confusion and stumbling over fees and licensing.
* In 2003 it looks like Plan 9 failed simply because it fell short of being a compelling enough improvement on Unix to displace its ancestor.
* Some Plan 9 ideas have been absorbed into modern Unixes, particularly the more innovative open-source versions. FreeBSD has a /proc file system modeled exactly on that of Plan 9 that can be used to query or control running processes.
* Experimental 2003 versions of Linux are implementing per-process mount points, a long step toward Plan 9's private namespaces.
* The various open-source Unixes are all moving toward systemwide support for UTF-8, an encoding actually invented for Plan 9.


Conclusion:
Plan 9 is not good enough to take over to the various unix world.

2008-10-18

Modulus accepts floating type ?

Honda asks me a statement about C++ as like below:

float a, b;
a = 10.5;
b = a % 2;


First ball, there is a statement error, "2" is a integer data-type, and b is a lvalue expression as a floating type, so that they doesn't match in type manner. The line sould be modify to this:

b = a % 2.0f;


Second, modulus (%) only accept the integral computing, refer from the C++ Standard draft, Sec. 5.6, p. 124.

The conclusion is, modulus doesn't accept the floating data.

The next question is, how to get the remainder as like the modulus does?

2007-12-06

SPARC: What to Do if You Forgot Root Password

SPARC: What to Do if You Forgot Root Password


(Use keyboard abort sequence--Press Stop A keys to stop the system)
ok boot net -s
# mount /dev/dsk/c0t3d0s0 /a
# cd /a/etc
# TERM=vt100
# export TERM
# vi shadow
(Remove root's encrypted password string)
# cd /
# umount /a
# init 6

2007-12-05

Quota setting of Linux & BSD

這四天連續看了 Linux 和 FreeBSD 的手冊,設定 quota,今晚的進度即將邁入 Solaris;都是為了推廣系上得 Unix-account Service,所以需要給每位使用者 quota limit。以下寫下個別的心得。

對於 Linux,是我最熟悉的系統,之前有設定過一次,可是出現錯誤,當下沒有立即排除,造成這次閱讀的時候釐清了一些原本誤解的觀念。例如,Quota 是 kernel mode 的功能,我有一種感覺一直以為要 dependence on HW;要怎樣的 quota limit 就得割一個 partition 給設定檔,一時腦筋轉不過來。既然都是軟體實做了,這些硬體的問題都會克服的。

接著,Venus 是跑 GNU/Debian Linux,大約花了三個小時設定,釐清觀念,事後很開心,翻起 FreeBSD Handbook 接著看。

FreeBSD 是 CoreDure Quad 的壯壯機,fBSD 對於我來說是個新系統,先前的成功經驗,加上對 fBSD 的新鮮感,所以猛看手冊。上次的進度停留在 Ch.4,今天大約花了五個小時,一直看到完。我沒那麼神,中間有些東西我不感興趣,例如 printer setting 還有 networking setting,所以就 skip into next lol。早上開始逐章讀,興致全開,竟然編起 FreeBSD Kernel,我真的很開心,因為學到不少新東西。之前見到 afoofa 說 Linux 的 make menuconfig is such friendy to her, but the interface FreeBSD is a little bit bored and monolithic. 但是我反而覺得 Handbook 教的很詳細,我很感謝 maintainer 把文件寫的那麼清楚,一一介紹,讓我觀念清楚明瞭,可以放心地跟著進度走。

今天編 kernel 都沒有 booting failure,真開心。不過還沒很確定是否要這麼做 make clean cleandepend depend buildkernel installkernel,前面三個步驟是我比較不清楚的。Durning making the source tree, I've found a interesting function, had before in Linux, that is -j, menas make "make" to does something in parallel. And my best argument is "16", not "32". It earns more and more time-saving and performance.

中午吃完飯,一度沉迷在 SMP 的 option。先說的,這篇 Installing the FreeBSD SMP Kernel 已經過期了,裡面的 APIC_IO, NCPU, NBUS, NAPIC 都已經在 6.2 kernel 失效了,只需要指定 SMP 就行了。

接著,我又病發了,開始找 SMP 的實做時比較早,心中一直有個感覺,逐漸推翻 FreeBSD 優於 Linux 的看法。Linux 很多人送 code & patch,FreeBSD 則是人數沒有那麼多,而且 Linux 有不少商業公司背書,燒錢改善 Linux。不過,現在下定論還太早,因為各有可取之處。謂之:「量才適性,學而不倦」。

我現在找到最早的 Linux SMP 是 2.0 加入的,1996。而 FreeBSD 是 5.0, in 2003 推出。不過,我也有看見 1986 就在寫的,不知道正確與否。

後來,有個疑問:如果 OS kernel has no SMP supports, can program run as parallel, as like MP? 後來想到,如果 OS 沒有 SMP,四隻 folding@home process 會平分一個 CPU 資源,而有 SMP 的話,每隻都是跑到 99.8% 左右。哈哈~ 可是這又不是純 MP,如果用 icc 編的話,應該也會得到同樣的結果。

好奇 kernel 怎麼知道是 SMP-type cpu,用 asm does detect?

另一支 BSD Family 就是 Solaris,我一直覺得上面的 utilities 功能都不健全,Linux 算是最健全的,fBSD 其次,Solaris 最少。我看,說不定 AIX, IRIX, HP-UP 更少呢~ 可是,也必須承認,因為硬體特性的關係,這些大廠都寫了很多東西支援,是一般 i386 OS (Linux, fBSD) 不會去實做的。

光是 Solaris 要設定 quota 的手冊就翻了兩本,因為要 refer,加上我也對它不熟,所以今天眼睛累,手指也酸了,就先暫擱吧。

2007-09-24

Ptt 的功能未來可能性

Why Use Parallel Computing?
*Other reasons might include:
**Overcoming memory constraints - single computers have very finite memory resources. For large problems, using the memories of multiple computers may overcome this obstacle.

用 MPI 實做應該可行,不用特地買一台 20,000 NT 的 quad cores 機器。

2007-09-16

MVC - Model-view-controller

Model-view-controller

Model-view-controller (MVC) is an architectural pattern used in software engineering. In complex computer applications that present a large amount of data to the user, a developer often wishes to separate data (model) and user interface (view) concerns, so that changes to the user interface will not affect data handling, and that the data can be reorganized without changing the user interface. The model-view-controller solves this problem by decoupling data access and business logic from data presentation and user interaction, by introducing an intermediate component: the controller.

Perl::Catalyst
Perl::Jifty
PHP::CakePHP
PHP::Zend Framework

The brief is a good brief of wikipedia, I love its style forever.

cd2iso

The magic of creating CD ISO files under Windows


/* This program has been compiled with VC6 and tested under Windows XP SP2 */
#include
#include

int main ( int argc, char ** argv )
{
FILE * f, * out;
char buf[512];
unsigned len;

if (argc != 2)
{
fprintf( stderr, "Syntax: rdiso filename\n" );
return 1;
}

if ( (f = _fsopen( "\\\\?\\CdRom0", "rb", _SH_DENYNO )) == NULL)
{
fprintf( stderr, "Can't open CdRom0\n" );
return 1;
}

if ( (out = fopen( argv[1], "wb" )) == NULL)
{
fprintf( stderr, "Can't open %s\n", argv[1] );
return 1;
}

do
{
len = fread( buf, 1, sizeof(buf), f );
if (len)
fwrite( buf, 1, len, out );
}
while (len == sizeof(buf));
fclose( f );
fclose( out );
return 0;
}

2007-09-14



In the book, "The Complete FreeBSD", wrote,

“Those Linux books hve over1000 pages! This looks like nothing. What can you do? We need something yesterday!”

Haha~~

2007-09-06

ssh-copy-id


ssh-copy-id - install your identity.pub in a remote machine’s authorized_keys

ssh-copy-id [-i [identity_file]] [user@]machine

2007-09-05

Never have it again!!!


int** ptr = malloc( sizeof(int) * SIZE );
char** ptr = malloc( sizeof(char) * SIZE );

WRONG


int** ptr = malloc( sizeof(int**) * SIZE );
char** ptr = malloc( sizeof(char**) * SIZE );

RIGHT

2007-08-22

Linux Networking-HOWTO

5.7 Routing.

You cannot modify the Hosts file or the Lmhosts file in Windows Vista

You cannot modify the Hosts file or the Lmhosts file in Windows Vista

WORKAROUND
To work around this issue, follow these steps:
1. Click Start Start button , click All Programs, click Accessories, right-click Notepad, and then click Run as administrator.

User Account Control permission If you are prompted for an administrator password or for a confirmation, type the password, or click Allow.
2. Open the Hosts file or the Lmhosts file, make the necessary changes, and then click Save on the Edit menu.

Links in Today

kqemu, QEMU Accelerator modules

alias in dos, use the doskey.

2007-08-21

libmtsk.so

Forbestperformanceandfunctionality,makesurethatthelatestOpenMPruntimelibrary,
libmtsk.so,isinstalled on the running system.


How can I find out the libmtsk.so. :(

Haha~~ have the patch for old-school. :D

SunOS 5.9: Microtasking libraries (libmtsk) patch

2007-08-20

Algorithm for square matrix multiplication

The trivial: O(n^3)
The Strassen: O(n^2.807)
The fastest*: O(n^2.376)

As the Strassen algorithm [ http://0rz.tw/bf2Xo ] mentioned:

The reduction in the number of multiplications however comes at the price of a somewhat reduced numeric stability.


* Coppersmith–Winograd algorithm
Reference:

*The Simultaneous Triple Product Property and Group-theoretic Results for the Exponent of Matrix Multiplication, arXiv:cs.CS/0703145

2007-08-19

Links in Today

Improving Application Efficiency Through Chip Multi-Threading

2.1.1.8 Multi-Threaded malloc

malloc and free are single-threaded operations and are among the bottlenecks for multi-threaded applications. A multi-threaded malloc scales with multi-threaded requests and can improve multi-threaded application performance. The Solaris OS has two types of multi-threaded malloc libraries, mt-malloc and umem.

2.1.1.8.1 Usage

a. Using mt-malloc:
LD_PRELOAD=libmtmalloc.so

b. Using libumem:
LD_PRELOAD=libumem.so

cc [ flag... ] file... -lumem [ library... ]

跟我的想法是一樣的,因為開矩陣還是需要很多時間的。

2007-08-16

Ethernet Codes: Vendor codes

Ethernet Codes: Vendor codes

Grid Topics

The Globus Alliance

gen()


#include
#include

#define N1 5000
#define N2 5000


void gen( int** a, int** b)
{
int i, j;
for (i = 0; i < N1; i++) {
for (j = 0; j < N2; j++) {
srand( 0 );
a[i][j] = rand() % 5 + 1;
srand( 1 );
b[i][j] = rand() % 5 + 1;
}
//printf("i: %d\n", i);
}
pthread_exit(NULL);
}

void mul( int** a, int** b)
{
int i, j, k;
int c[N1][N2];

for (i = 0; i < N1; i++) {
for (j = 0;j < N2; j++) {
c[i][j] = 0;
for (k = 0; k < N1; k++)
c[i][j] += a[i][k] * b[k][j];
//printf("%d\t", c[i][j]);
}
//printf("\n");
}
}

int main(int argc, char *argv[])
{
int** a = NULL;
int** b = NULL;
int** c = NULL;

a = (int**) malloc( sizeof(int) * N1 * N2);
b = (int**) malloc( sizeof(int) * N1 * N2);
c = (int**) malloc( sizeof(int) * N1 * N2);

pthread_t* thread = NULL;
thread = (pthread_t*) malloc( sizeof(pthread_t) * N1);
int result;

int i;
for (i = 0; i < N1; i++) {
a[i] = (int *) malloc( sizeof(int) * N2);
b[i] = (int *) malloc( sizeof(int) * N2);
c[i] = (int *) malloc( sizeof(int) * N2);
}

gen(a, b);

return 0;
}

$ gcc m1.c && time ./a.out

real 3m55.660s
user 3m55.391s
sys 0m0.184s


This result without threading.

2007-08-12


#include <pthread.h>
#include <stdio.h>

#define N 10

void *test(void *c)
{
printf("\tI am thread: %d\n", (int)c);
pthread_exit(NULL);
}

int main()
{
int i, result;
pthread_t t[N];

for(i = 0; i < N; i++) {
result = pthread_create(&t[i], NULL, test, (void *)(i));
if (result)
printf("Cannot do create.\n");
}

return 0;
}


出來每次結果都不同。 :( 需要明確地等待

BlueGene/L Apply Form

Using BG/L

Cluster Building

NCHC Formosa PC Cluster, 感覺親切。
研討會資料, HP 64bit Cluster
硬體資料
NCHC PC Cluster
國家高速網路與計算中心-PC Cluster 討論區
HIGH PERFORMANCE COMPUTING LAB. // 高效能計算實驗室 //, 東海大學

Reaching the Goal with the Regensburg Marathon-Cluster, Hubert Feyrer
High Performance Computing Training

Books,
*Beowulf Cluster Computing with Linux




*Parallel Programming: Techniques and Applications Using Networked Workstations and Parallel Computers




*An Introduction to Parallel Computing: Design and Analysis of Algorithms

Passing Multidimensional Arrays


#include <iostream>
using std::cout;

void print_m35(int m[3][5]);
void print_mi5(int m[][5], int dim1);
//void print_mij_(int m[][], int dim1, int dim2);
void print_mij(int* m, int dim1, int dim2);


void print_m35(int m[3][5])
{
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 5; j++) cout << m[i][j] << '\t';
cout << '\n';
}
}

void print_mi5(int m[][5], int dim1)
{
for (int i = 0; i < dim1; i++)
for (int j = 0; j < 5; j++) cout << m[i][j] << '\t';
cout << '\n';

}

/*
void print_mij_(int m[][], int dim1, int dim2)
{
for (int i = 0; i < dim1; i++) {
for (int j = 0; j < dim2; j++) cout << [i][j] << '\t';
cout << '\n';
}
}
*/

void print_mij(int* m, int dim1, int dim2)
{
for (int i = 0; i < dim1; i++) {
for (int j = 0; j < dim2; j++) cout << m[i * dim2 + j] << '\t';
cout << '\n';
}
}

int main()
{
int v[3][5];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
v[i][j] = j;

print_m35(v);
print_mi5(v, 3);
print_mij(&v[0][0], 3, 5);

return 0;
}

2007-08-11

libc-dev

I have installed the icc with stdlibc++.so.5 in my box, a box grow on 2.6 series kernel. And I also have the gcc-4.1.2 with libc6 libraries. Then one time, I'd like to debug with an executable file called "a.out", but I have no idea to do it. The gdb says that,

Failed to read a valid object file image from memory

When I run it during debug process.

As the "file" results:

a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.4.1, dynamically linked (uses shared libs), for GNU/Linux 2.4.1, not stripped

But actually, it should be like below,

a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped


I'm not dare to remove the _big_base_ libc6, but I reinstall the "libc-dev" then it returns back to my hoping status. :D

SunFire 15K (Solaris & Debian)

HCL for Solaris OS
Platform Group:   sun4u


Current Status, Debian on SPARC platform
Supported are Sun4m and Sun4u machines (with a 32-bit userland).

UltraLinux

gprof

Linux/Alpha or How to Make Your Applications Fly
Linux Performance Analysis Tools

[Author], David Mosberger

---
Useful Tools tutorial

gprof TIPS:

* Don't optimize before profiling
* Be careful not to optimize before profiling!
* Profile before you optimize.

hahaha~~~ :D I compiled it with -O3 options of icc and gcc. :D

2007-08-07

Apache+Subversion Recipe

subversion with lighty?
Apache+Subversion Recipe, Good boy!!

Linux to Power Google GPhone

HTC

 
 

Sent to you by Alan via Google Reader:

 
 

via OSNews by donotreply@osnews.com (Eugenia Loli-Queru) on Aug 04, 2007

"Google's first mobile phone reportedly will run a Linux operating system on a Texas Instruments "Edge" chipset, and will likely ship to T-Mobile and Orange customers in the Spring of 2008. "GPhone" call minutes and text messages will apparently be funded by mobile advertising, according to reports." The report found at the popular embedded systems Linux news site LinuxDevices.

 
 

Things you can do from here:

 
 

2007-08-06

Matrix Transpose

I did ten thousand times multiplication with 800x800 matrix, each element is raged from one to five, integer type.

yrchen tole me a hint yesterday afternoon, that, the matrices should be tramsposed before did a huge compute. In today's experiment, I wrote two version codes, one doesn't has any transpose loop (called m1), the other does (called m1_t). Both them compiled with gcc, with -O3 optimization. The result is:

m1_t:
real 5m31.300s
user 5m31.245s
sys 0m0.020s


m1:
real 5m30.802s
user 5m30.265s
sys 0m0.008s


It looks like that -O3 did the transpose before has the huge matrices multiplication.


#include
#include

#define DIE 800

void gen( int a[][DIE]);
void mul( int a[][DIE], int b[][DIE]);

int main(int argc, char *argv[])
{
int a[DIE][DIE];
int b[DIE][DIE];

int i;
for (i = 0; i < 10000; i++) {
srand(0);
gen(a);
srand(1);
gen(b);
mul(a, b);
}

return 0;
}

void gen( int a[][DIE] )
{
int i, j;
for (i = 0; i < DIE; i++)
for (j = 0; j < DIE; j++)
a[i][j] = random() % 5 + 1;
}

void mul( int a[][DIE], int b[][DIE])
{
int i, j, k;
int c[DIE][DIE];

//Transpose
for (i = 0; i < DIE; i++)
for (j = 0; j < DIE; j++)
mul[i][j] = b[j][i];

for (i = 0; i < DIE; i++) {
for (j = 0;j < DIE; j++) {
c[i][j] = 0;
for (k = 0; k < DIE; k++)
c[i][j] += a[i][k] * mul[i][k];
//printf("%d\t", c[i][j]);
}
//printf("\n");
}
}

2007-08-04

Matrix Mutiplication Hint

先做轉置 (det)。

因為 CPU 會一次 fetch 1byte in each row, 而 matrix mul 是 col * row,所以可以直接把做一次 det(row) -> col,就能直接 fetch det(row) -> col。速度較快!

不要使用 recursive,因為 OS 要 handle 很多 stacks is a heavy-loading job。直接改用多個 whilie 把 huge-matrix 展開,開 threads 去分割成 strsen algo smaller-matrix.

這是 yrchen 給的 common hint.

2007-07-27

Linux: The 0.01 Release



 
 

Sent to you by Alan via Google Reader:

 
 


"This is a free minix-like kernel for i386(+) based AT-machines," began the Linux version 0.01 release notes in September of 1991 for the first release of the Linux kernel. "As the version number (0.01) suggests this is not a mature product. Currently only a subset of AT-hardware is supported (hard-disk, screen, keyboard and serial lines), and some of the system calls are not yet fully implemented (notably mount/umount aren't even implemented)." Booting the original 0.01 Linux kernel required bootstrapping it with minix, and the keyboard driver was written in assembly and hard-wired for a Finnish keyboard. The listed features were mostly presented as a comparison to minix and included, efficiently using the 386 chip rather than the older 8088, use of system calls rather than message passing, a fully multithreaded FS, minimal task switching, and visible interrupts. Linus Torvalds noted, "the guiding line when implementing linux was: get it working fast. I wanted the kernel simple, yet powerful enough to run most unix software." In a section titled "Apologies :-)" he noted:

"This isn't yet the 'mother of all operating systems', and anyone who hoped for that will have to wait for the first real release (1.0), and even then you might not want to change from minix. This is a source release for those that are interested in seeing what linux looks like, and it's not really supported yet."

read more


 
 
 
 

Lighttpd Configuration Reference

http://trac.lighttpd.net/trac/wiki/Docs%3AConfigurationOptions

2007-07-26

Uninstall DRBL

for i in `acs drbl|cut -f 1 -d " "`; do agr -y "$i";done

Schedule

1. Matrix Multiplication
2. 1 + 2 + 3 + ... + 999999 with pthreads method
3. Dividing the huge matrices into small parts
4. Redo last step with pthreads
5. Knowing how to manipulate icc

pthread

POSIX Threads

Native POSIX Thread Library (NPTL), getconf GNU_LIBPTHREAD_VERSION, NPTL 2.3.6

NPTL Trace Tool

IBM Linux Technology Library, Linux threading models compared: LinuxThreads and NPTL

2007-07-06

HPC Links

Gluster is a GNU cluster distribution aimed at commoditizing Supercomputing and Superstorage. Core of the Gluster provides a platform for developing clustering applications tailored for a specific tasks such as HPC Clustering, Storage Clustering, Enterprise Provisioning, Database Clustering etc.

Z RESEARCH enables System Integrators, with little or no experience in clustering, to build Clustered File Storage, HPC Clusters and Supercomputers from Commodity off the Shelf Components (COTS) using Clustered architecture and Z RESEARCH'S software stack 'Gluster'.

amar, 可愛的網域。 :) 是一位印裔工程師。

白爛的圖片

Computer cluster

2007-07-05

e1000_request_irq: Unable to allocate MSI interrupt Error: -22

結論是,暫時不要用 linux-image-2.6.20-15-generic 或 Feist 的版本。 衝 gutsy!!

Links:
google://
dmesg eth0 e1000_request_irq Unable to allocate MSI interrupt Error: 22

wired ethernet interface missing
e1000 high latency problem, msi error on boot.

2007-06-21

人家只是轉圖檔而已...

竟然造成 kernel panic!! 因為 Out of memory!

for i in `ls -1 *.jpg`;do (convert -quality 48 -crop +0-1000 "$i" tmp/"$i" &); done

如此而已就 :(
寫信來去論壇問看看

2007-06-20

Perldoc, Day 1

perlintro.html

Using my in combination with a use strict; at the top of your Perl scripts means that the interpreter will pick up certain common programming errors. For instance, in the example above, the final print $b would cause a compile-time error and prevent you from running the program. Using strict is highly recommended.

類似 gcc -Wall


unless ( condition )
if (!condition)


Note that the braces are required in Perl, even if you've only got one line in the block.

Too bad


print "LA LA LA\n" while 1;          # loops forever


Cool!!


A list of them is given at the start of perlfunc and you can easily read about any given function by using perldoc -f functionname .



You can read from an open filehandle using the <> operator. In scalar context it reads a single line from the filehandle, and in list context it reads the whole file in, assigning each line to an element of the list:



Reading in the whole file at one time is called slurping. It can be useful but it may be a memory hog.

寫的真傳神! hog *grin* :P


When you're done with your filehandles, you should close() them (though to be honest, Perl will clean up after you if you forget):

哈! 好笑! though to e honest. :P


if ($a =~ /foo/) { ... }  # true if $a contains "foo"

The // matching operator is documented in perlop. It operates on $_ by default, or can be bound to another variable using the =~ binding operator (also documented in perlop).

In [perlop.html],
Binary "=~" binds a scalar expression to a pattern match. Certain operations search or modify the string $_ by default. This operator makes that kind of operation work on some other string. The right argument is a search pattern, substitution, or transliteration. The left argument is what is supposed to be searched, substituted, or transliterated instead of the default $_. When used in scalar context, the return value generally indicates the success of the operation. Behavior in list context depends on the particular operator. See "Regexp Quote-Like Operators" for details and perlretut for examples using these operators.

If the right argument is an expression rather than a search pattern, substitution, or transliteration, it is interpreted as a search pattern at run time.

Binary "!~" is just like "=~" except the return value is negated in the logical sense.



These are documented at great length in perlre, but for the meantime, here's a quick cheat sheet:
XDDD 快速騙人小抄 (quick cheat sheet)



while (<>) {
next if /^$/;
print;
}

我覺得寫的很美!

while ((c = get()) != NULL) {
printf ("%s\n", c);
}



http://cpan.stu.edu.tw/

第一次嘗試 CPAN install Bundle::CPAN 跑出一大堆鬼東西,看起來這個系統寫的很完整,也很大!

2007-06-19

‘Bad fd number’ error in Ubuntu 6.10 (Edgy Eft)

PCMan, Day 1

Demystifying Subclassing
Advice from the creator of C++

A Tour of C++
Procedural Programming
Decide which procedures you want; use the best algorithms you can find.

Modular Programming
Decide which modules you want; partition the program so that data is hidden within modules.

IBM Blade Center
Bjarne Stroustrup's homepage

Separate compilation is an issue in all real programs. It is not simply a concern in programs that present facilities, such as a Stack, as modules. Strictly speaking, using separate compilation isn't a language issue; it is an issue of how best to take advantage of a particular language implementation. However, it is of great practical importance. The best approach is to maximize modularity, represent that modularity logically through language features, and then exploit the modularity physically through files for effective separate compilation.