星期四, 3月 29, 2007

TIOBE Programming Community Index for March 2007

# in Mar
2007
# in Mar
2006
Delta in
Position
LanguageRatings
Mar 2007
Delta
Mar 2006
Status
1 1 Java 18.044% -3.84% A
2 2 C 15.633% -2.16% A
3 3 C++ 11.109% -0.05% A
4 4 PHP 9.458% -0.49% A
5 5 (Visual) Basic 8.147% -1.74% A
6 6 Perl 6.420% 0.00% A
7 8 Python 3.897% +0.80% A
8 10 JavaScript 3.485% +1.75% A
9 7 C# 3.365% +0.22% A
10 21 11 * Ruby 2.773% +2.31% A
11 11 SAS 1.849% +0.51% A
12 9 Delphi 1.760% -0.08% A
13 12 PL/SQL 1.549% +0.56% A
14 20 6 * D 1.268% +0.78% A
15 19 ABAP 0.777% +0.26% A
16 15 Lisp/Scheme 0.726% +0.15% A-
17 14 Ada 0.654% +0.06% B
18 17 COBOL 0.647% +0.12% B
19 16 FoxPro/xBase 0.600% +0.06% B
20 31 11 * Transact-SQL 0.586% +0.38% B


Ruby goes up for 11 postion and get the highest growth rate (+2.31%) among other programming languages. I beleive there is lot of potential of Ruby. According to TIOBE,
Both languages are boosted by their corresponding frameworks, Ruby On Rails and Ajax. This might be a new trend. In the recent past it was necessary to have a large company behind the language to get it in the spotlight (Sun with Java, Microsoft with C#), but nowadays a killer app appears to be sufficient. Viral marketing via the Internet works!

星期一, 3月 26, 2007

Apache 2.2 + Mongrel 設定方式

設定 Mongrel Cluster

請將你的 Mongrel Cluster 設定好,這裡預設 port 從 4000 ~ 4009 ,一共十個,跑在 production 環境下

mongrel_rails cluster::configure -e production -p 4000 -N 10
mongrel_rails cluster::start
修改 Apache 2.2 設定檔

Apache 的設定檔放在 httpd.conf ,以下修改內容皆在 httpd.conf 裡面設定。

首先確定你的 Apach 2.2 有 enable apache 的其中一個 Module mod_proxy
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
再來我們開始設定 Mongrel Cluster 的 reverse proxy 設定,首先我們給這組 cluster 取名叫做 examplecluster,他是10組 Mongrel ,跑在 port 4000 ~ 4009 之中

# cluster member 1
BalancerMember http://127.0.0.1:4000
BalancerMember http://127.0.0.1:4001
....
BalancerMember http://127.0.0.1:4009
再來假設你的 hostname 為 example.com,我們開始設定 virtual host

ServerName example.com
ServerAdmin root@example.com
DocumentRoot "/var/www/example.com/htdocs"
ProxyPass /images !
ProxyPass /stylesheets !
ProxyPass /javascripts !
ProxyPass / balancer://examplecluster/
ProxyPassReverse / balancer://examplecluster/


重 點是在於 ProxyPass,ProxyPass 代表 images,stylesheets,javascript 等 static file 交給 Apache 處理,不要給 Mongrel 處理。 還有 ProxyPassReverse 要指定正確的 cluster name ,我們要指定為 examplecluster。

最後重起 Apache 即可。本設定改自著名的文章 Scaling Rails with Apache 2.2, mod_proxy_balancer and Mongrel,還有 Robin 的 在Windows平台使用Apache2.2和Mongrel运行Ruby on Rails。設定是在 Gentoo Linux + Apache 2.2.3 + Mongrel 跑完全沒有任何問題。

[via: http://lightyror.thegiive.net/2006/12/apache-22-mongrel.html]

Mongrel 使用方式 Part 2 : Mongrel Cluster

看完上一篇,大家一定很想丟雞蛋
這樣的 tutorial 也可以出來混一篇文章
在大家浪費買蛋錢之前,我必須要說,好戲在後頭呀!!!
Mongrel 如果只有單獨啟動在 80 port
他充其量不過是一個速度較普普的 Web Server
但是,當作 Backend Application Server 才是他的宿命呀

今天的需求是這樣
我們可以開啟數個 Mongrel Process 在其他 port
前端開一個 Proxy Server
當 Proxy Server 接受到 request
他會傳給 backend application server
其實作法很像 Mod_fastcgi 的作法
只是中間的 application server 將 fastcgi 改成了 mongrel

如果要開啟眾多的 Mongrel Process
我們當然可以用

mongrel_rails start -d -p 8000 -P log/mongrel_1.pid
mongrel_rails start -d -p 8001 -P log/mongrel_2.pid
....
這樣來執行,但是要管理就變得相當的麻煩
不但要一一起動,要關掉或是重起的變得相當麻煩
如果 Mongrel 那麼麻煩的話
那我們還搞屁,直接用 fastcgi 就好啦 XD
這時候請用 mongrel cluster
有了他,Mongrel 才變成簡單好用的 Application Server

安裝方式
gem i mongrel_cluster
即可

設定方式
一開始,請到 Ruby on Rails 的根目錄
先設定 Mongrel 的設定檔
mongrel_rails cluster::configure -e 那些環境 \
-p 8000 \
-N 3 \
-c /var/www/servers/ \
-a 127.0.0.1 \
--user mongrel \
--group mongrel
他會將 config 寫到 config/database.yml
我解釋一下選項
  • -e 就是用那個環境啟動(production/development/test)
  • -p 就是用那個 port 開始
  • -N 就是開啟幾個 process
  • -c 就是先切到那個目錄,再執行 mongrel cluster (通常是這個Ruby on Rails 的根目錄)
  • -a 就是在那個 host 啟動
  • --user 就是以那個 user 身份啟動
  • --group 就是以那個 group 啟動

如果設定好後,以後使用 mongrel_rails cluster::start 他就會立刻使用剛剛的設定檔
這裡要注意的是 -N 跟 -p 的選項
假設 -p = 8000 -N 為 3
那他會開啟三個mongrel process ,分別以 8000 , 8001 , 8002 來聽
其實 -p 8000 -N 3
就跟
mongrel_rails start -d -p 8000 -P log/mongrel_1.pid
mongrel_rails start -d -p 8001 -P log/mongrel_2.pid
mongrel_rails start -d -p 8002 -P log/mongrel_3.pid
一樣的意義

以此類推假設 -p = 7000 -N 為 5
那他會開啟五個mongrel process ,分別以 7000 , 7001 , 7002 , 7003 , 7004 來聽

使用方式
啟動方式
mongrel_rails cluster::start

關閉方式
mongrel_rails cluster::stop

重起方式
mongrel_rails cluster::restart

參考連結
  1. Rails, Mongrel, Lighty and Mint

[via: http://lightyror.thegiive.net/2006/10/mongrel-part-2-mongrel-cluster.html]

Mongrel 使用方式

Ruby on Rails 架設一直有一個問題
找不到適當的 Application Server
Webricks 太慢,fastcgi 太玄妙,scgi 太年輕
這個時候
只有 Mongrel 可以拯救世界呀~~~~

Mongrel 首頁是這樣寫的

Mongrel is a fast HTTP library and server for Ruby that is intended for hosting Ruby web applications of any kind using plain HTTP rather than FastCGI or SCGI. It is framework agnostic and already supports Ruby On Rails, Og+Nitro, and Camping frameworks.
他跟Webricks 一樣,是一個方便我們架設 Ruby on Rails 環境的網頁伺服器
並且他比 Webricks 還要來得快速

安裝方式很簡單
gem i mongrel
使用方式呢,基本上跟 Webrick 差不多
到 Rails 根目錄
打入
mongrel_rails start
你就會發現他已經可以使用了

如果要用 deamon 模式來使用的話
打入
mongrel_rails start -d
即可

如果要使用特定的 port
mongrel_rails start -p 1234
即可

用不同環境啟動
mongrel_rails start -e production/development/test
即可

指定log file
mongrel_rails start -l log/mongrel_log
即可

有啟動的問題
mongrel_rails start -h
即可

重起 Mongrel
mongrel_rails restart

停止 Mongrel
mongrel_rails stop

[via: http://lightyror.thegiive.net/2006/10/mongrel.html]

ror installation

My steps to install Ruby On Rails 1.8.5 over ubuntu 6.0.6

Prep
Make sure you have gcc complier and zlib development package installed. If not sure, please run

apt-get install build-essestial
apt-get install zlib1g-dev
Ruby
Download ruby-1.8.5-p12.tar.gz from http://www.rubyonrails.org
tar xzvf ruby-1.8.5-p12.tar.gz
cd ruby-1.8.5-p12
./configure --prefix=/usr/local --enable-pthread
make
sudo make install
sudo make install-doc
cd
..
If you saw lots of text fly by but didn’t get that error, it means that we should now have a brand new Ruby installed.

We can verify this (as well as a correct path setting) by typing the following command:

ruby -v
You should see something like this:
ruby 1.8.5 (2006-12-04 patchlevel 2) [i686-linux]
zLib
Download zlib package from
http://www.blue.sky.or.jp/atelier/ruby/ruby-zlib-0.6.0.tar.gz
tar zxvf ruby-zlib-0.6.0.tar.gz
cd ruby-zlib-0.6.0
ruby extconf.rb
make
sudo make install
cd ..
RubyGems
Download rubygems package rubygems-0.9.2.tgz from
http://rubyforge.org/projects/rubygems/
tar xzvf rubygems-0.9.2.tgz
cd rubygems-0.9.2
sudo /usr/local/bin/ruby setup.rb
cd ..
RubyOnRails
With RubyGems installed, Rails is a simple, one-line install:
sudo gem install rails --include-dependencies
* gem respects the following variables for proxy settings
  • http_proxy
  • HTTP_PROXY
  • NO_PROXY

星期日, 3月 25, 2007

Ruby on Rails 伺服器架設原理

一般來說,Ruby on Rails 架設原理很簡單,分成三個部份。

  1. Frontend Server
  2. Application Server
  3. Database Server
每個部份都有自己的功用。


Frontend Server 負責將所有 HTTP Request forward 給後端的 Application Server,也就是他是作類似 Reverse proxy 的工作。一般來說,Apache 2.2 跑 mod_reverse_proxy 是最常出現的選擇,nginx 也是不錯的選擇。Lighty 1.5 之後跑 mod_proxy_core 也很方便,等到 1.5 release 之後我會作詳細的評估。
Application Server 負 責跑 Ruby on Rails 程式,你寫好的程式就在上面跑。一般來說可以用 Webricks,Fastcgi,scgi,Mongrel 等等 Ruby on Rails Runner來跑。Webricks 太慢,Fastcgi 有穩定性,以及不好設定的疑慮。SCGI 太年輕。目前最穩,最好用,而且已經被驗證過的 Application Server 就是 Mongrel。

Database Server 就是處理資料處理的工作。可以跑 SQLite,MySQL 之類的 RDBMS 。甚至使用 File 來當資料處理,或是使用 NFS 也未嘗不可。不過這裡通常大家都是使用一般大廠的 RDBMS資料庫。

組合方式

Apache 2.2 + Mongrel:穩定,高彈性的組合

Apache 2.2 遇到 user request 用 HTTP 分配給 Mongrel ,然後 Mongrel 去跑。這個組合的好處是每個 Application Server node 都可以很輕易的拆成不同台機器,並且很好管理。Apache 的穩定又是出名的。雖然不見得最快,但是方便 scale 以及穩定是他最好的優點。目前所有組合當中最穩定的方式,很多流量最大的 Ruby on Rails 站台也都是使用這個方式。適合在已經有一定規模的網站。設定方式在此我有介紹

Lighttpd + Fastcgi:單機最佳選擇
Lighttpd 1.4 跑 PHP 或是跑 Ruby on Rails 都是這樣跑。Lighttpd 為 Frontend Server ,他接到 request ,經由 unix socket 送給身為 Application Server 的 Fastcgi ,Fastcgi 再執行 Ruby on Rails 程式。通常這個方式是 Frontend Server 跟 Application Server 跑在同一個機器上面的,當然每個 Fastcgi 也可以跑在 TCP Mode ,然後 Fastcgi 放在不同機器上面,不過設定不易不常使用這個方式。這個組合的好處是執行效率非常快速,如果 Frontend 跟 Application 放在同一台機器上,Lighty 這個組合遠比 Apache 的組合來得輕快許多。但是缺點是多台機器設定複雜,不易擴展到多台機器上,Fastcgi 又有在高負載下罷工的負面報導。相反的,單台機器上面 Fastcgi 設定管理簡單,速度又飛快,非常適合小網站剛剛起步時,機器不足,流量不大的需求。設定方式在此我有介紹

Nginx or Lighttpd 1.5 + Mongrel:未來的新選擇

類 似Apache 的組合,但是 nginx 或是 Lighttpd 1.5 都有一個優點,不像 Apache 2.2 那麼肥。反正這個 Frontend 只要作 reverse proxy 的工作,其實不需要 Apache 那麼大的 Server 來作。好處是 Frontend Server 比較快速。壞處是 nginx 這個俄國來的 Server 大家不熟悉,doc 又很少(俄文是很多啦)。Lighttpd 1.5 又只在 pre-release 階段,穩定程度還是得花點時間。不過如果扣掉 Frontend 的 X factor,這個組合兼具輕快跟方便 Scale ,可說是最好的組合。lighty 1.5設定方式在此我有介紹。nginx 的設定檔這裡有範例,可以參考。

[via: http://lightyror.thegiive.net/2006/12/ruby-on-rails_30.html]