There's a backstory, but it's not especially political -- merb started
out as a supplemental thing that would let multiple users upload files
without tying up an entire Rails process for each one. Then it got
bigger. Basically, it's Less-Opinionated Software.
I'm definitely watching for the 1.0 release.
-Sam
As I understand it, it's advantages over Rails are that it's
multi-threaded (MRI works, JRuby work is in progress), lighter weight
(uses half the memory for a single instance, and additional threads
weigh nothing rather than requiring you to start another process), is
faster and more responsive, and lets you easily choose different ORM and
view technologies.
The disadvantages of Merb seem to be are that there is no usable
official documentation, it lacks many convenience features, and it
requires developers using it to understand it at a much deeper
implementation level to be able to do useful work.
I've poked at it a few times in the past, but the documentation was
little more than a few terse blog entries, there were no complete
examples, and the official site still has absolutely no actual
documentation -- their rdoc is useless unless you already know where to
use, say, a deep_array_node call. However, the architecture has mostly
stabilized and there's clearly effort being made to explain how Merb works.
Here are some promising Merb tutorials on my to-read list for those
interested:
"Life On The Edge With Merb, DataMapper & RSpec"
http://merb.4ninjas.org/
"Meet Merb" [It's $9, but I've always been happy with my PeepCode purchases]
http://peepcode.com/products/meet-merb-pdf-draft
"Slapp: A simple chat wall Merb tutorial."
http://www.socialface.com/slapp/
-igal
has_many :through
is in the pipes, but…
Let's not confuse DataMapper (which is what the above quote applies
to) and Merb. Merb can also use ActiveRecord.
Merb consists of a number of gems:merb-core
,merb-more
andmerb-plugins
. This means that it is possible to pick and choose the functionality you need, instead of cluttering up the framework with non-essential features
People pick Merb because a single Merb process consumes half the memory
of a Rails process and is able to handle many simultaneous clients with
that one Merb process, whereas you must have one 60MB+ Rails process for
every single concurrent client.
Consider uploads (which Sam mentioned earlier). Let's say you have 4
Rails processes. If four people decide to upload a file at the same
time, then your website is effectively offline until one of those
uploads finishes -- each upload takes the total attention of a single
Rails process. In contrast, Merb can handle many uploads at once, and
your site also stays online for other users.
Many large Rails sites offload their uploads to Merb, while using Rails
and its many features for serving the main site. Merb is also able to
serve more requests per second, so some large Rails sites use Merb to
serve their most-heavily hit pages.
A note about threading: MRI supports green threads, whereas JRuby makes
use of Java's processor threads. Merb is still useful on MRI, but it's
benefit is more about making use of otherwise idle processes on a single
CPU core rather than distributing processes efficiently across many
cores. So if you're using MRI on a multicore system, you'll want to
start one Merb process per core.
-igal
In the case of file uploads, you could render a response to the user
that their file has been uploaded and continue processing the
controller action to thumbnail the file.
If I recall correctly, in a rails controller action that thumbnails an
uploaded image, that process will be blocked while until the action
completes.
Dan
Here's Zed Shaw's 2 cents on the matter:
> nginx does buffer the whole request body before sending it to the
> backends. This is why pound, pen, or balance works but nginx doesn't
> when you do upload progress.
Also, here's a link with more discussion on how to monitor an upload's
progress using nginx and a Merb controller and jQuery AJAX client for
monitoring progress:
http://blog.new-bamboo.co.uk/2007/11/23/upload-progress-with-nginx
Although their sample code seems fairly straightforward, is anyone using
a good plugin or such that wraps this all up to provide an upload
progress monitor?
-igal
I've used the following strategies to execute long-running asynchronous
tasks:
(1) Invoke a method that forks, reconnects to the database, runs the
task, and exits to kill the forked child process. Pros: Easy to write
and manage because there's no need for to manually launch a separate
process to run tasks, since the processes are forked from your existing
Rails processes. Cons: Ugly, and you can end up with many forked
children running at the same time.
(2) Offload tasks to a queue or DRb server. Pros: Gives you total
control over how of how you run tasks and many resources you use, e.g.
number of workers, whether to use the Rails environment, etc. Cons: More
complicated and you have to launch/manage a separate process that'll run
tasks in the queue or answer DRb requests.
-igal
(1) Invoke a method that forks, reconnects to the database, runs theOne thing to be aware of is that on most OS's if the GC fires it'll trigger a copying of all the memory pages. If you're ram limited and get several long running forks at once that can push you into swapping or other bad things.
For simple image resizing I've found that shelling out a background convert/mogrify command works best.