= 2010-05-11 = * 組務報告 - 軟體技術組 :: 綠能雲端團隊(Green Cloud Team) * [wiki:jazz/Performance_Tuning 系統效能調校參數(Performance Tuning Parameters)] == Linux == * [http://packages.debian.org/acct acct] - The GNU Accounting utilities for process and login accounting * 從 [http://phantom.nchc.org.tw/ Phantom Cluster] 的架構圖中看到 psacct package,原來是可以拿來統計不同使用者登入登出跟執行指令的工具啊!! ([wiki:jazz/09-09-23#ClusterComputing 2009-09-23]) * ac - 統計使用者連線時間 (單位: 小時) (Ref: [http://cha.homeip.net/blog/archives/2006/11/psacct_checkins.html psacct & checkinstall 使用備忘]) * sa - 統計執行過的程序 {{{ #!sh ~$ sudo apt-get install acct ~$ ac -d # 依日期統計 ~$ ac -p # 依使用者帳號統計 ~$ ac -f /var/log/wtmp.1 # 指定來源檔案 (預設 /var/log/wtmp) - 因此只能統計近期的使用情形 ~$ sudo sa -a # 顯示所有程序記錄 ~$ sudo sa -m # 依使用者統計 }}} * 如何調整每個使用者可以開啟的檔案個數 * [參考] [http://www.xenoclast.org/doc/benchmark/HTTP-benchmarking-HOWTO/node7.html Increasing the file descriptor limit] * [參考] [http://www.netadmintools.com/art295.html GNU/Linux - How Many Open Files?] * [參考] [http://www.cs.wisc.edu/condor/condorg/linux_scalability.html Linux Scalability] * 注意:修改 /etc/security/limits.conf 中間必須確定是 TAB ,如果有設定 vim 的 softwaretab 的話,得特別當心!!! * /proc/sys/fs/file-max - 核心預設最多可以開啟的檔案個數 - RHEL5 上限為 1048576 (2^20^) {{{ ~$ cat /proc/sys/fs/file-max 743964 }}} * 修改方法: 使用 sysctl 指令或編輯 /etc/sysctl.conf {{{ sysctl -w fs.file-max=100000 }}} * /proc/sys/fs/file-nr - 目前已開啟檔案個數、可供開啟檔案個數、總開啟檔案上限 {{{ [root@srv-4 proc]# cat /proc/sys/fs/file-nr 3391 969 52427 | | | | | | | | maximum open file descriptors | total free allocated file descriptors total allocated file descriptors (the number of file descriptors allocated since boot) }}} * /etc/security/limits.conf - 每個程序(process)可以開啟檔案的個數(number limits of open files per process) - 像 HDFS 的 !DataNode 就需要調整這種參數([wiki:jazz/10-02-22#Hadoop:HDFS 2010-02-22]) {{{ #!diff --- /etc/security/limits.conf 2010-02-22 11:29:11.000000000 +0800 +++ /etc/security/limits.conf.new 2010-02-22 11:28:33.000000000 +0800 @@ -49,4 +49,6 @@ #ftp - chroot /ftp #@student - maxlogins 4 +* soft nofile 4096 +* hard nofile 743964 + # End of file }}} * /etc/pam.d/login - 告訴系統要用 /etc/security/limits.conf 來設定一些上限 {{{ # Sets up user limits according to /etc/security/limits.conf # (Replaces the use of /etc/limits in old login) session required pam_limits.so }}} * 指令: ulimit - 可以告訴你一些系統限制,並且設定想要的値 {{{ jazz@Wdebian:~$ ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 72704 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 72704 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited }}} * 假設 /proc/sys/fs/file-max 跟 /etc/security/limits.conf 都有設定上限為 743964,且 /etc/pam.d/login 也有打開,但是 ulimit -a 指令仍顯示 1024 (預設),可以修改 /etc/rc.local 或 /etc/profile 強制用 ulimit -n 743964 來提高開檔個數。 {{{ ~$ ulimit -n 743964 }}} * [備註] 如果 ulimit 超出可容許範圍,會顯示 Operation not permitted,此時請檢查相關設定値 {{{ ~$ ulimit -n 7439640 -bash: ulimit: open files: cannot modify limit: Operation not permitted }}} * Linux ACL 權限控管 * [參考] [http://www.linux-mag.com/id/7777From the ACLU: Know Your Rights] * 指令:'''getfacl''' - get file access control lists {{{ ~$ getfacl .bashrc # file: .bashrc # owner: jazz # group: jazz user::rw- group::r-- other::r-- }}} * [參考] [http://www.babyface.idv.tw/NetAdmin/42200907acl01 網管人第42期 Linux 檔案 ACL設定範例(上)] * 指令:'''setfacl''' - set file access control lists == Perl + SQLite3 == * [專案] 實作 Perl + SQLite * [wiki:jazz/08-12-29#Perl 其他參考連結] * [參考] [http://mailliststock.wordpress.com/2007/03/01/sqlite-examples-with-bash-perl-and-python/ SQLite examples with Bash, Perl and Python] (2007-03-01) * 環境: Debian 5.0.4 , amd64 核心 {{{ jazz@drbl:~$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 5.0.4 (lenny) Release: 5.0.4 Codename: lenny jazz@drbl:~$ uname -a Linux drbl 2.6.26-lustre-amd64 #1 SMP Sun Jun 28 18:28:02 CST 2009 x86_64 GNU/Linux }}} * 相關套件: [http://packages.debian.org/sqlite3 sqlite3],[http://packages.debian.org/libsqlite3-0 libsqlite3-0],[http://packages.debian.org/libdbd-sqlite3-perl libdbd-sqlite3-perl] {{{ jazz@drbl:~$ sudo apt-get install sqlite3 libdbd-sqlite3-perl libsqlite3-0 jazz@drbl:~$ dpkg -l | grep sqlite ii libdbd-sqlite3-perl 1.14-3 Perl DBI driver with a self-contained RDBMS ii libsqlite3-0 3.5.9-6 SQLite 3 shared library ii sqlite3 3.5.9-6 A command line interface for SQLite 3 }}} * 使用範例程式建立 test.db {{{ jazz@drbl:~$ vi perlsqlite3.pl jazz@drbl:~$ chmod a+x perlsqlite3.pl jazz@drbl:~$ ./perlsqlite3.pl jazz@drbl:~$ file test.db test.db: SQLite 3.x database jazz@drbl:~$ sqlite3 test.db "select * from n" 1|john|smith }}} {{{ #!perl #!/usr/bin/perl -w use DBI; use strict; my $db = DBI->connect("dbi:SQLite:test.db", "", "", {RaiseError => 1, AutoCommit => 1}); $db->do("CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)"); $db->do("INSERT INTO n VALUES (NULL, 'john', 'smith')"); my $all = $db->selectall_arrayref("SELECT * FROM n"); foreach my $row (@$all) { my ($id, $first, $last) = @$row; print "$id|$first|$last"; } }}} == Python + SQLite3 == * [參考] [http://mailliststock.wordpress.com/2007/03/01/sqlite-examples-with-bash-perl-and-python/ SQLite examples with Bash, Perl and Python] (2007-03-01) * 環境: Debian 5.0.4 , amd64 核心 {{{ jazz@drbl:~$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 5.0.4 (lenny) Release: 5.0.4 Codename: lenny jazz@drbl:~$ uname -a Linux drbl 2.6.26-lustre-amd64 #1 SMP Sun Jun 28 18:28:02 CST 2009 x86_64 GNU/Linux }}} * 相關套件: [http://packages.debian.org/sqlite3 sqlite3],[http://packages.debian.org/python-pysqlite2 python-pysqlite2] {{{ jazz@drbl:~$ sudo apt-get install python-pysqlite2 sqlite3 jazz@drbl:~$ dpkg -l | grep sqlite ii python-pysqlite2 2.4.1-1 Python interface to SQLite 3 ii sqlite3 3.5.9-6 A command line interface for SQLite 3 }}} * 使用範例程式建立 test.db {{{ jazz@drbl:~$ vi pythonsqlite.py jazz@drbl:~$ chmod a+x pythonsqlite.py jazz@drbl:~$ ./pythonsqlite.py jazz@drbl:~$ file test.db test.db: SQLite 3.x database jazz@drbl:~$ sqlite3 test.db "select * from n" 1|john|smith }}} {{{ #!python #!/usr/bin/python from pysqlite2 import dbapi2 as sqlite db = sqlite.connect('test.db') cur = db.cursor() cur.execute('CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)') db.commit() cur.execute('INSERT INTO n (id, f, l) VALUES(NULL, "john", "smith")') db.commit() cur.execute('SELECT * FROM n') print cur.fetchall() }}} == Open Hardware == * [http://www.makerbot.com/ MakerBot] - an affordable, open source 3D printer * [http://www.youtube.com/watch?gl=TW&v=zirHL_rRBu0 影片] * 五六年前看[http://www.books.com.tw/exep/prod/booksfile.php?item=0010071703 『MIT媒體實驗室 (The Media Lab : inventing the future at MIT)』]帶給我很多震撼,書中提到了幾個大的趨勢,我記得第一個是"電機、資訊、通訊將融合成一個學門",在當時我自己本身的碩士論文早已是融合三者的最佳典範([http://ctlin.nctu.edu.tw/labs/VR/vr7.htm 史督華六軸飛行平台(ECE)+虛擬實境(CS)+高階分散式架構(CM)]),當然像是「電子紙」的部分,近兩年也已經紅遍半邊天。另一個一直記得的新趨勢叫做「個人製造」,自製 3D 印表機的新聞在前幾年也有注意到,但是商品化的部分看起來也是近兩年才開始比較興盛,加上「阿凡達」的 3D 效應,還有 DIY 的價格越來越平民化,未來或許只要會操作 CAD 這一類自由軟體,就可以自己切割電路、自己製作產品雛型,相信在不遠的將來,產品工業設計師、建築師等,都將蒙受其利。