- Memory allocation and garbage collection Web applications allocate memory on an as needed basis, and release it by performing garbage�collection. For most dynamic languages, the garbage collector freezes all other activity while the heap is cleaned out. To collect metrics on the health of your GC, consider using ltrace, rbtrace, and check out Joe Damato's presentation on Garbage Collection and the Ruby Heap. In Ruby Enterprise Edition (REE), and JRuby, you can easily tune the garbage collector in accordance with the Goldilocks principle. The GC should not run too often, but it should run often enough that memory consumption does not become a problem. Kirk Haines wrote a great blog post on memory allocation here.�You can read more about performance tuning in REE here, or JRuby over here.
- Background�processes Starting with metric collection, use tools like RPM, or memprof to find your most expensive actions. Often, these actions can be moved to a background worker that run periodically using a separate GC. Engine Yard officially supports background processes through both�Delayed Job, and�Resque, but there are a handful of alternatives, both in Ruby and other languages.
- Copy-On-Write Web Servers If you cannot move an expensive action to a background process, you can also save memory by forking a process using Copy-On-Write (COW). Both Passenger and Unicorn web servers support this. COW allows you to save memory by forking a master process without allocating an equivalent amount of memory. Basically, the forked child gets enough memory to run the application, but shares code and libraries. You can read more about COW on the Passenger website.
2011年4月14日星期四
Losing the Forest for the Trees
订阅:
博文评论 (Atom)
没有评论:
发表评论