Questions for Mongrel
Total Page:16
File Type:pdf, Size:1020Kb
www.YoYoBrain.com - Accelerators for Memory and Learning Questions for Mongrel Category: Introduction - (16 questions) Mongrel is described in what way in the "A web application container for Ruby on Mongrel pdf available from O Reilly Rails" Mongrel is compared with what web servers production performance: Fast CGI or SCGI in the Rails world in terms of production performance and development Development: WEBrick simplicity/speed Creator of Mongrel Zed A Shawwww.zedshaw.com Mongrel is developed on what mixture of Ruby and C programming/scripting languages Documentation for Mongrel mongrel.rubyforge.org/docs/index.html The creators of Mongrel describe it how? 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 Three key technologies that are used for A custom HTTP 1.1 parser (based on RFC Mongrel's internals standard, written using Ragel in C and Java as a Rby extension) Simple server that uses the parser and URIClassifier to process requests, find the right handlers, then pass the results to the handler for processing Handlers are responsible for using HttpRequet and HttpResponse objects to "do their thing and then return results" Component of Mongrel responsible for Handlers dealing with HttpRequest and HttpResponse How does Mongrel support threading one thread per request, but it will start closing connections when it gets "overloaded"while Mongrel is processing HTTP requests and sending responses it uses Ruby's threading system What platforms that already work with Camping and Og+Nitro Mongrel are throught to be "thread-safe" Have not been heavily tested Is Ruby on Rails thread safe? no How does Mongrel handle Rails" " Ruby on Rails is not thread safe so there is a synchronized block around the calls to Dispatcher.dispatch. This means that everything is threaded right before and right after Rails runs. While Rails is running there is only one controller in operation at a time. This is why people typically have to run a small set of Mongrel processes (a "Pack of Mongrels") to get good concurrency." How does mongrel handle things if you have It doesn't, and this can cause performance long running actions? problems....and the author of Mongrelrecommends you look for ways to offlaod work to another process so the rails app can keep working Describe how mongrel works (esoteric flashcard) A request hits mongrel. Mongrel makes a thread and parses the HTTP request headers. If the body is small, then it puts the body into a StringIO. If the body is large then it streams the body to a temp file. When the request is "cooked" it call the RailsHandler. The RailsHandler sees if the file is possibly page cached, if so then it sends the cached page. Now you're finally ready to process the Rails request. LOCK! Still locked, Mongrel calls the Rails Dispatcher to handle the request, passing in the headers, and StringIO or Tempfile for body. When Rails is done, UNLOCK! . Rails has (hopefully) put all of its output into a StringIO. Mongrel then takes this StringIO output, any output headers, and streams them back to the client super fast. minor processing related command to remove svn files so they cannot be browsed on your Web server find . -name ".svn" -exec rm -rf {} \; Does mongrel have SSL no Category: Configuration - (17 questions) Recommend solution to avoid giving people use svn export rather than checkout to get access to your .svn files your code Recommended way to get Mongrel installed due to the way fedora chops up it packages, on Fedora Mongrel author recommends installing Ruby from Source, then installing Mongrel Common causes of Mongrel stopping proper Lots, moany related to using resources that functioning are not shared properly between multiple processes Common problem with logs that can stop Configuring Logger to rotate log files. Logger Mongrel's proper functioning doesn't do this reliably between processes, so use an external log rotation like logrotate. IMPORTANT security idiosynchrocy of using Capistrano doesn't use svn export to create Capistrano and svn to deploy the deployment directory so there's a bunch of extra information in the .svn files. Without special config changes to your web server you'll be letting people access these. common cause of Mongrel not functioning not having MySQL timeouts properly set properly related to MySQL Common cause of Mongrel not functioning using Pstore - no faster than db and has properly related to sessions frequent locking and coordination issues Common cause of Mongrel not functioning Sharing a file or similar service without properly related to file sharing proper locking. SQLite and BerkleyDB are both culprits here. Common cause of mongrel not functioning Using up too much CPU or memory on Linux properly related to hardware will cause the oomkiller to kill your Mongrel process. Recommended way to get mongrel servers For Rails the best way is either memcached within a cluster to synch sessions (with or database session storage. Do not use Rails) PStore''' It is broken, will crash or lock your Mongrel processes, and really isn't all that fast. what is num-procs? affects resource eaten by deployments - Determines how many active requests are allowed before clients are denied and old requests are killed off. how does the timeout setting throttle your The timeout option is what you use if you server want to make sure that a Mongrel server can't take on too much work (i.e. you need to throttle it). What it does is sleep for N 100th/second after each accept. This means that it will slow down the number of incoming clients. Very handy if you have a shared hosting system and don't want people to eat your servers. Known problem related to MySQL " If you find that Mongrel stops working after a long idle time and you're using MySQL then you're hitting a bug in the MySQL driver that doesn't properly timeout connections. What happens is the MySQL server side of the connection times out and closes, but the MySQL client doesn't detect this and just sits there. What you have to do is set: ActiveRecord::Base.verification_timeout = 14400 Or to any value that is lower than the MySQL server's interactive_timeout setting. This will make sure that ActiveRecord checks the connection often enough to reset the connection. " idiosyncrocy of Mongrel and PIDs There was a change to the 0.3.13.4 release and on that makes it so Mongrel doesn't try to "fix" invalid paths. You should change your configurations so that they give explicit full paths to both the log and pid files. Most common cause of MySQL "lost The most common cause is that you're using connection to database" errors mysql.rb that comes with Rails rather than the MySQL compiled ruby driver from gems. Do this: sudo gem install mysql And pick the one for your system (don't type sudo if you're win32). How can you run some code before rails implest way is to put it in your production.rb starts and configure it there, but if you need it done long before Rails starts, then you can throw it into a mongrel.conf and run that file with the -S option (see mongrel_rails --help). The mongrel.conf is a Ruby script that lets you configure Mongrel with special Ruby code, but you can also put other Ruby code in it. What does BAD CLIENT mean " It means that a request came in which Mongrel rejects because it doesn't follow the RFC grammar. Mongrel is pretty relaxed about most requests, but in order to block the majority of security attacks for web servers it is strict about characters used, header formats, status line formats, etc. This is also based on matching the RFC's grammar specification to a Ragel grammar specification, so it's easy to compare. If you need to know why the client is triggering this, then simply hit your Mongrel processes with USR1 signals and they'll log the full request data and parameters that were collected. Then, if you think the request is valid send me this data and I'll look. If it's not valid than fix the client. Mongrel takes the stance that all clients are written by software developers and that they should follow the standard. By doing this it reduces the bugs and potential security holes found in many other web servers. It also means that if you absolutely have to allow a bad client, then you'll need to not use Mongrel. " Category: Syntax and Commands - (21 questions) purpose of stop -f same as stop --force forces shutdown Mongrel: purpose of -p option -p FILE or --pid FILE tells mongrel where to write the PID install command for mongrel via rubygems sudo gem install mongrel purpose of start -c -c PATH same as start --chdir PATH changes to this directory before starting command to stop Mongrel mongrel_rails stop command to run mongrel in the background mongrel_rails start -d command to see options you can set for mongrel_rails start -h Mongrel start command Option Mongrel provides for debugging mongrel_rails start -B option. memory leaks It will log objects that get created to log/mongrel_debug and you can look in there to find out what object is causing the problems. command option that lets you set an arbitrary uri as your prefix mongrel_rails start -e production --prefix=/someprefix -a option of start command same as --address defaults to 0.0.0.0 purpose of -l option same as --log provide name of logfile ...must be absolute path to log file -n option on start, default value n,--num-procs (:num_processors) Maximum number of concurrent processing threads to allow.