Section 7.2. Common Scenarios


7.2. Common Scenarios

There are quite a few places where your code can go wrong, and since you wrote it, it's your problem, but here are the most common problems that Rails applications run into. If these don't help you solve your problem, remember to check out the Mongrel mailing list and the FAQ on the Mongrel Web site (http://rubyforge.org/mailman/listinfo/mongrel-users and http://mongrel.rubyforge.org/faq.html).

  • Leaking Files Leaking files in Rails is common for people who come from other languages where open files will be closed by the GC. Ruby's GC isn't quite that smart, so many new Rails programmers leak files by accident. Using the files.log debugging will show you right away what you're doing. Best way to avoid it is to always open your files and use them in a block:

    open('thefile.txt') {|f| f.read }

  • Leaking Objects Leaking in a language like Ruby basically means that you're storing objects in places where the Garbage Collector (GC) can't get to them or can't release them. The object.log will help you spot objects that are getting leaked if you simply look for any class whose delta goes up but never down. You can avoid leaks of this kind by utilizing WeakRef in any internal caching you do, and by not storing things in class variables (@@likethis).

  • Nobody Likes Mongrel Or, everything's configured right, but requests just aren't getting to Mongrel. The problem is difficult to debug without actually looking at the network traffic, but looking at the rails.log will tell you if requests are coming in and being formed correctly. If that doesn't work then you'll need to use a packet sniffer to really find out what's going on.

  • Jammed Requests This is also known as "stopped mongrel" or "stuck mongrel" and happens when you have a Rails action that seems to never finished. Common causes are having multiple Mongrel processes all trying to use common resources without proper locking. Turning on USR1 logging temporarily in production will help you figure out which action is causing you problems.

  • EMFILE If you open too many files for either Ruby to handle or for your system's restrictions then you'll get a "too many open files" exception in your Rails codes or even at other random locations. Mongrel will log these in the mongrel.log as attempts to kill Threads that are "too old," but really the problem is you have a Rails action that's causing the damage. What you want to do is turn on USR1 logging and -B logging to get the files.log. Then look at which request opens the most files and find a way to tone it down.




Mongrel. Serving, Deploying, and Extending Your Ruby Applications
Mongrel. Serving, Deploying, and Extending Your Ruby Applications
ISBN: 9812836357
EAN: N/A
Year: 2006
Pages: 48

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net