原谅新手类型的问题但是,是什么决定了rails和MySQL(我的服务器是Ubuntu)消耗的RAM?几乎没有任何请求进入服务器似乎徘徊在2GB的1.5左右。 MySQL有大约100MB的数据存储在其中。该网站拥有约3500名注册用户,当流量较高时,内存趋于高达1.8 GB左右。当流量很低或不存在时,它不会下降太多。
在RoR部署方面,RAM消耗的主要因素是什么?我会假设数据库大小,但我的数据库大小远不及我的RAM消耗(但这可能是错误的思考方式吗?)。
有人能指出我这方面的好资源,或者在这里向我解释一下吗?
感谢。
答案 0 :(得分:2)
我正在分析Ubuntu服务器中最细微的配置,以便使用Nginx + Unicorn配置以最低内存占用运行我的Rails 3.2.6应用程序。并使用本地postgres数据库。
在ubuntu中移除了诸如whoopsie和apparmor之类的许多服务之后,只允许我可以在双方实例化我的工作人员的基本流程,nginx和unicorn共计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
通过这些信息,我可以确定我的操作系统使用92个进程来托管我的应用程序,只需1个连接,因为从Nginx和Unicorn产生了更多进程,进程数增加了+1,并且还增加了与数据库的连接。
查看每个进程的内存使用情况也有助于确定应用程序的内存消耗量。
我正在使用旧笔记本电脑来确定我的应用程序基线,它只有3GB的内存。 在未来,我计划在具有低规格服务器的分布式环境中发布此应用程序,因此我想特别了解我的rails应用程序中所有内容的足迹。
我沿途学到的一些东西是:
捆绑安装 - 无需开发测试#确保您的应用使用并加载仅在生产环境中使用的Gems,而不是更多。
确保只加载您的请求所需的ActiveRecord模型,而不是更多。
答案 1 :(得分:1)
EngineYard有一个good blog post,讨论了Rails中内存问题的一些潜在来源。你是如何为你的网站服务的? (乘客?杂种?)