※ 引述《lxb.bbs@bbs.hkday.net (閉關修法)》之銘言:
: ※ 引述《smartboy.bbs@ptt.cc (小光光)》之銘言:
: : single thread telnet bbs 要做動畫, 大概只有靠 select() 或 alarm() 之類做
: : nonblocking i/o. 每隔一小段時間 input timeout 就再送出一些 output.
: : 以 ptt 這種規模的 bbs 不太可能這麼做 -- 那會帶來大量的 context switch,
: : 徒然浪費 cpu 及頻寬.
: 問一下, 現在 pmore 利用 select() 來等 timeout,
: 對系統負荷實際帶來多少影響, 可否跟大家分享一下 ?
: (估計目前並未大幅度觸發應用, 但若有一點兒比較或統計,
: 相信有助於 bbs 管理員衡量是否引入此功能. )
以下和 BBS 程式無關, 純粹講系統...
select() 來等 timeout 的好處是
1. 不需用到 SIGALARM 因此不會出現 race condition...
(sleep() 會用到 SIGALARM)
2. 計時精確度高
3. Kernel scheduler 支援這種 wake up 方法, 因此 performance 也相當好
這作法我記得是在 Richard Stevens 的 UNIX Network Programming 裡面看到的,
書中有詳細的 performance 比較... 因此我深信不疑...
目前我自己寫的 code 全部是用 select() 來替代 sleep()
* * *
如果要應用到 BBS 動畫上, 大量 context switch 是必定免不了的,
因此我同意 smartboy 的說法, 這樣的大幅浪費資源, 沒有必要...
因為頻寬/網路不良問題造成的斷線也更容易在看動畫時出現...
但是以小站來說, 資源原本就過剩, 也許可以考慮。
真的要做, 後面大量給 terminal function 動手術改成 non-blocking I/O
的過程才真的讓人受不了。
--
Don't get suckered in by the comments -- they can be terribly
misleading. Debug only code.
-- Dave Storer
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.135.254.153