Practical Intro Merb

37
Merb, not rails? A practical introduction to a new framework.

description

from http://www.mindbucket.com

Transcript of Practical Intro Merb

Page 1: Practical Intro Merb

Merb, not rails? !

A practical introduction to a new framework.

Page 2: Practical Intro Merb

Intro to merb

Page 3: Practical Intro Merb

What is merb?

• MVC Framework.

• Similar to Rails.

• Lightweight, extensible, fast.

Page 4: Practical Intro Merb

Merb Ideology

• Hacker-friendly.

• Core should be small, plugins bountiful.

• Code should be as simple as possible.

• Code should not be “magical.”

Page 5: Practical Intro Merb

Merb is like rails

• Application structure is very similar

• Can use ActiveRecord

Page 6: Practical Intro Merb

What does merb-core include?

• rack-based request handling

• session handling

• before / after filters

• layouts / views with erb

• routing

Page 7: Practical Intro Merb

What does merb-core include?

• gem-based plugins

• mailers

• partials

• exceptions

• generator for controllers, and models (integrates with your chosen ORM).

Page 8: Practical Intro Merb

What is elsewhere?

• an ORM (can use ActiveRecord, DataMapper, Sequel)

• form helpers such as form_for (merb_helper)

• ActiveSupport and all those little ruby extensions (extlib?)

Page 9: Practical Intro Merb

What is elsewhere?

• flash (merb_has_flash and redirect :message)

• redirect("/posts/34", :message => { :notice => 'Post updated successfully!' })

• scaffolding

• caching (merb-cache)

• ajax library (merb_jquery)

Page 10: Practical Intro Merb

DataMapper

• Thread-safe.

• Supports data stores you don’t manage.

• Optimizations in eager-loading, lazy-loading, etc.

Page 11: Practical Intro Merb

What do we need helper functions for?

• Why not just use HTML for templating instead of all those helper functions?

• Why not just use JQuery for AJAX instead of all those AJAX helper functions?

Page 12: Practical Intro Merb

Thread-safety

• Merb is thread-safe now.

• Rails will be thread-safe in 2.2.

• What does that mean? http://blog.headius.com/2008/08/qa-what-thread-safe-rails-means.html

Page 13: Practical Intro Merb

Considerations

• Does your app block?

• File uploads

• Remote HTTP calls

• Facebook app: 1-2s wait time?

• Do you have native threads?

• JRuby / C ruby differences

Page 14: Practical Intro Merb

Instances RequiredMerb Rails

C MRI, one core, no blocking

C MRI, one core, 80% blocking

C MRI, two cores, no blocking

C MRI, two core, 80% blocking

Jruby, one core, no blocking

Jruby, one core, 80% blocking

Jruby, two cores, no blocking

Jruby, two core, 80% blocking

Jruby, 16 cores, 80% blocking

1 1

1 5

2 2

2 10

1 1

1 5

1 2

1 10

1 80

Page 15: Practical Intro Merb
Page 16: Practical Intro Merb

Case study

Page 17: Practical Intro Merb

The Project

• CMS for Faculty.

• Keeps track of courses, education, biography info, etc.

• Deployed to Tomcat.

Page 18: Practical Intro Merb

Requirements

• 2500 faculty websites.

• 5 concurrent backend users.

• 500 users per day on the public facing pages.

Page 19: Practical Intro Merb

Can Rails handle that?

• One process per file upload?

• RAM requirements?

Page 20: Practical Intro Merb

Why merb?

• Thread-safe.

• Low memory footprint.

• ???

Page 21: Practical Intro Merb

Why JRuby?

• Authentication integration using JRadius

• Java platform lowers IT stress level.

Page 22: Practical Intro Merb

What is development like?

• There are no books... yet.

• The codebase is changing.

• Smaller userbase than rails.

• If you are doing anything weird, be prepared to corepatch!

Page 23: Practical Intro Merb

Problems

• File upload broken in Tomcat deploy.

• Partial behavior is totally weird.

• Render syntax changed / broke export code.

• Activerecord-jdbc mysql quote error.

• String concurrency problem??

Page 24: Practical Intro Merb

Other Issues

• acts_as_list had to be extracted from ActiveRecord files and manually included in init.rb.

Page 25: Practical Intro Merb

Post-mortem

Page 26: Practical Intro Merb

Speed Comparison

• Test with simple merb / rails apps using ActiveRecord

• Tests using ab -n 10000

• Testing serially, not concurrently.

• Tested on this MacBook Pro

Page 27: Practical Intro Merb

C MRI Mongrel

• Merb: 170 requests / second

• Rails: 32 requests / second

Page 28: Practical Intro Merb

JRuby Tomcat

• Merb: 69 requests / second

• Rails : 121 requests / second

Page 29: Practical Intro Merb

JRuby Mongrel

• Merb: 104 requests / second

• Rails: 29 requests / second

Page 30: Practical Intro Merb

JRuby Glassfish

• Merb: 106 requests / second

• Rails : 125 requests / second

Page 31: Practical Intro Merb

What is the deal?

• JRuby thread pool, instead of thread instantiation?

• Default session handling?

• Overspinning threads in app server?

• Incorrect JIT compilation?

Page 32: Practical Intro Merb

Tomcat Memory Usage

• Merb: ~30 MB for all threads

• Rails: ~60 MB+ additional memory per process

• (Tested on Tomcat)

Page 33: Practical Intro Merb

Was it worth it?

• Thread-safety is a minor advantage when it comes to file uploads.

• Merb uses less memory.

• Merb is slower than rails.

• Merb may die on string thread-safe bug until JRuby / Merb team fix it.

Page 34: Practical Intro Merb

Conclusion

Page 35: Practical Intro Merb

Consider merb if...

• you’re writing a small tool.

• you have limited memory requirements.

• you like trying new ORMs.

• you need fast performance (and you’ve figured out why it runs so slow on JRuby).

• you like hacking about in frameworks.

Page 36: Practical Intro Merb

Upcoming

• Merb 1.0 is released Oct 11-12.

• MerbCamp is in San Diego Oct 11-12.

• Merb in Action book (2009?).

Page 37: Practical Intro Merb

Available

• I’m available for contracts again. Talk to me here, at 408-646-2240 or [email protected].

• http://www.mindbucket.com/