2009-10-03 89 views
3

原諒新手問題,但是,什麼決定了Rails和MySQL(我的服務器是Ubuntu)所消耗的內存?幾乎沒有任何請求進入服務器似乎徘徊在2GB的1.5左右。 MySQL有大約100MB的數據存儲在其中。該網站擁有約3500名註冊用戶,當交通流量較高時,內存趨於峯值約1.8 GB。當流量很低或不存在時,雖然不會有太大的下降。用Rails和MySQL確定Ubuntu的內存使用情況

當涉及RoR部署時,RAM消耗的主要因素是什麼?我會假設數據庫大小,但我的數據庫大小遠不及我的內存消耗(但也許這是錯誤的方式來考慮它)?

任何人都可以指出我對這方面的一個很好的資源,或向我解釋這個嗎?

謝謝。

回答

1

EngineYard有一個good blog post,它討論了Rails中存儲問題的一些潛在來源。你如何爲你的網站提供服務? (Passenger?Mongrel?)

+0

乘客。我有一個2GB的切片(slicehost) – chrishomer 2009-10-03 00:22:06

+0

還有幾個問題:什麼是Ruby版本?什麼是您的PassengerMaxPoolSize? Nginx還是Apache?我想我的博客文章中有一些內容可以幫助你,但額外的信息不會受到傷害。 – 2009-10-03 00:36:15

+0

紅寶石1.8.7 Apache PassengerMaxPoolSize - >我還沒有設置這個(所以6?),但現在,我查看它,也許我應該? – chrishomer 2009-10-03 20:15:47

2

我正在分析Ubuntu服務器中最簡單的配置是什麼,以便使用Nginx + Unicorn配置以最低的內存佔用量運行我的Rails 3.2.6應用程序。並使用本地postgres數據庫。

在ubuntu下刪除了很多像whoopsie和apparmor這樣的服務,並且只讓基本的流程能夠實例化我的工作人員,nginx和獨角獸總共500MB。

這純粹是應用程序的香草推出。只有一個數據庫連接。 這是與所述第一用戶執行以基線的命令的結果:

$ free -mt 
      total  used  free  shared buffers  cached 
Mem:   3001  550  2450   0   16  178 
-/+ buffers/cache:  355  2646 
Swap:   952   0  952 
Total:  3954  550  3403 

$ ps -ef | grep nginx 
root  1232  1 0 12:54 ?  00:00:00 nginx: master process /usr/sbin/nginx 
www-data 1233 1232 0 12:54 ?  00:00:00 nginx: worker process 
www-data 1234 1232 0 12:54 ?  00:00:00 nginx: worker process 
www-data 1235 1232 0 12:54 ?  00:00:00 nginx: worker process 
www-data 1236 1232 0 12:54 ?  00:00:00 nginx: worker process 
herminio 5292 1078 0 13:24 pts/1 00:00:00 grep nginx 

$ ps -ef | grep unicorn 
herminio 4863  1 0 13:01 ?  00:00:00 unicorn_rails master -c unicorn.rb -D -E production               
herminio 4866 4863 2 13:01 ?  00:00:34 unicorn_rails worker[0] -c unicorn.rb -D -E production                           
herminio 5296 1078 0 13:24 pts/1 00:00:00 grep unicorn 

$ ps -ef | grep postg 
postgres 935  1 0 12:54 ?  00:00:00 /usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf 
postgres 940 935 0 12:54 ?  00:00:00 postgres: writer process                          
postgres 941 935 0 12:54 ?  00:00:00 postgres: wal writer process                         
postgres 942 935 0 12:54 ?  00:00:00 postgres: autovacuum launcher process                      
postgres 943 935 0 12:54 ?  00:00:00 postgres: stats collector process                       
postgres 5215 935 0 13:12 ?  00:00:00 postgres: user_db pto_db_prod 127.0.0.1(47118) idle                  
herminio 5300 1078 0 13:24 pts/1 00:00:00 grep postg 

有了這個信息我可以確定我的OS使用92個流程主機我應用與1個連接,隨着越來越多的過程是從Nginx的產卵並且獨角獸的進程數量增加了1,並且還增加了與數據庫的連接。

研究每個進程的內存使用情況也有助於確定應用程序的內存消耗量。

我正在使用舊筆記本電腦來設置我的應用程序基準,並且它只有3GB的內存。 將來我打算在低規格服務器的分佈式環境中發佈這個應用程序,因此我想特別瞭解我的Rails應用程序中所有內容的佔用空間。

一些我一路上學到的東西是:

捆綁安裝--without開發測試#爲了使那些只在生產環境中使用,而不是更確保您的應用程序使用和負載寶石。

請確保您只加載您的請求需要而不是更多的ActiveRecord模型。