Your SlideShare is downloading. ×
JRuby on Rails - RoR's Simplicity Meets Java's Class (a case in point)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

JRuby on Rails - RoR's Simplicity Meets Java's Class (a case in point)

2,039

Published on

Slides from my talk at RubyConf India 2012. This is a case in point for a highly productive & scalable enterprise application development platform with JRuby on Rails. …

Slides from my talk at RubyConf India 2012. This is a case in point for a highly productive & scalable enterprise application development platform with JRuby on Rails.
When we started to architect an enterprise micro-blogging solution as part of the internal collaboration platform for a large customer (henceforth referred by dummy name 'CustCollab'), the next immediate question was “Which web application development framework to use?”. Simplicity, productivity, ability to deliver high quality of service (QoS), especially performance & scalability, & alignment with CustCollab's technology stack were our top criteria for framework selection. After considerable research on state-of-the-art, we zeroed in on 2 frameworks – 1) “Ruby on Rails” (RoR) for its super simplicity & productivity & 2) “Java Enterprise Edition” (JEE) for its obvious “enterprise” class, high QoS & greater alignment with CustCollab's technology stack. But we just couldn't rule out either one, since each framework had been proven to deliver qualities not so proven in the other framework. Naturally, we started dreaming of a framework which can deliver best of both worlds! And in reality, there lived such a framework – 'JRuby on Rails'!
In this talk I will focus more on our experience of how JRuby, & hence JRoR, has done a fantastic job of delivering best of RoR & JEE worlds to an enterprise application w.r.t multiple 'quality of service' attributes like scalability (parallel processing, Garbage Collection, compilation, caching, advanced database connection pooling etc.), productivity, extensibility, security (especially CSRF), session management, reusability, total cost of ownership (alignment with existing/preferred technology stack) etc.

With the help of the real world 'CustCollab Micro-blogging' case in point, this presentation demonstrates how the distant, isolated worlds of RoR & JEE can synergize with the help of the JRuby bridge to result in a highly productive & scalable enterprise application development platform.

I hope it encourages others to adapt JRuby, & hence Ruby, in the enterprise. After all, as promised by the JRuby dev. team, the JRuby improvisation is well capable of delivering the best of both Java & Ruby worlds, & hence deserves greater attention in the enterprise world!

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,039
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 1
  • 2. Once upon a time… powerful Java on their beautiful Ruby way to win the plot to unfold Enterprize battles to be won when Java, Ruby tried to win battles on their own… there were happy times… …& some down times… ……. then comes the time… Java falls in love with Ruby… (a little rhyming love song…I promise) now wait for the climax…No background music Fast & dramatic No popcorn break 2
  • 3. The script writer & confessions…x I’m neither too deep into Ruby nor have I run too far onto Rails so farBut I love its Simplicity I think & code in usual Java & JEEAnd I love its Class I architect & code solutions at TCS Thrilled to talk about JRuby when one of it’s creators & a JRuby hero is here! (Unbelievable!)x I tried, but couldn’t further shorten title of this story… 3
  • 4. The plot Micro-blogging @CustCollab API Search Public/private/ corporate/auto Profiles follow communities Smart Follow, unfollow, phones Micro-blogging invites etc. Pretty std notifications deply arch with Usage DMZ expected to Timelines, over a period threads, hashtags 200,000+ total users & Notifications from other apps 4
  • 5. The actors supporting Java & Ruby/** @author #jruby.org*/public class JRuby implements Ruby { /* * This implementation of Ruby programming * language brings class to Ruby/Rails * & simplicity to Java/JEE. */ …} 5
  • 6. “Ruby on Rails® is an open-source web framework thats optimized for programmers happiness and sustainable productivity. It lets you write beautiful code by favoring convention over configuration.” - rubyonrails.org 6“On a rail track” by Ahmad Kavousian (flickr)
  • 7. Is it the Silver Bullet? 7Silver bullet (flickr)
  • 8. Large Crowd (flickr) 8
  • 9. The battles to be won Performance & Scalability Productivity Extensibility Security Platform Maturity & Skills (Total Cost of Ownership) 9
  • 10. Technology stack under consideration JEE 5 on standard JEE container Ruby 1.8.7 (MRI) + Rails 2.3.5 on standard RoR container JRuby 1.5.0 (Ruby 1.8.7) + Rails 2.3.5 on standard JEE container 10
  • 11. Performance & Scalability 11
  • 12. Mumbai at sleep hours… Mumbai at peak hours… “Architect to Scale”Pune way back in my college days… Pune on my way to RubyConfIndia 2012 12
  • 13. “Languages don’t scale, architectures do” - (someone wise) 13Twitter bird (flickr)
  • 14. Perf. & Scale Threading & Parallel Processing[Concurrency is a Myth in Ruby by Ilya Grigorik] JRubyThanks to Ilya Grigorik, Evan Phoenix (Ruby, Concurrency, and You) & Sasada Koichi (YARV)for demystifying the concurrency & parallelism in Ruby implementations… 14
  • 15. Perf. & Scale Memory Management JRuby:Ruby 1.8 (MRI): More init mem. util (-), JVM GCStop the world, mark & sweep optimized to death over the years. E.g.Min. GC pauses usingRuby 1.9.3 (YARV): Lazy sweep multi- cores, or….or….(++)garbage truck (flickr) 15
  • 16. Perf. & ScaleCode Execution Mechanism Ruby 1.8 Ruby 1.9 JRuby - Charles Nutter, Learning More About JRuby 16
  • 17. The battlefield……… 17
  • 18. Perf. & Scale CachingData store ~ bottleneckCaching = Don’t hit bottleneck. Closer is faster. JRoR JEE RoR @CustCollab Session, application scope:  Memcached:  Simple, fast JEE • No i/o, protocol for in-memory +1 breakpoint, cache • Auto expiry +1 component  Options++ • App. server’s high availability  Cache’s HA to (HA) = cache’s HA be architectedScale out options: Ehcache, …  Page, view,Page, view, fragment scope etc. fragment scope etc. 18
  • 19. Perf. & Scale Advanced Database Connection Poolingrequire ‘reliable/db/pooling’handle (spikes + heavy load + no load + failures) JEE containers RoR containers JRoR JDBC Pool + warm-up + Pool + ?  JRuby AR-JDBC shrink + health ping + bridge enables recover leaked connections scalable + reliable db + monitor utilization = connection pool Scalable + Reliable 19
  • 20. Perf. & Scale Asynchronous MessagingCan’t remove bottlenecks?Decouple them… JRoR JEE RoR @CustCollabJMS: Good ones like ‘delayed job’  JMS planned Evolving. As high QoS as as message• Stood the test of JVM impls? Twitter FUD. queue time…& money in large financial No open std specs as such? institutions! Product lock-in?• High Quality of Service (QoS) 20
  • 21. Perf. & Scale JRuby+Java 7+new compiler: Future worth a mention + New Compiler: “Give the JVM better byte code.” Wow! +“There will always be cases where we win or where we lose. Java 7s featureshave made the win cases more frequent and more impressive. In generalif we are slower we consider it a bug and would like bug reports.”[Sources: Charles Nutter, Learning More About JRuby & red/black tree benchmark ] 21
  • 22. The battlefield……… 22
  • 23. Yeah, yeah.. but what about Productivity? 23
  • 24. Productivity Write Less, Do MoreEvery manager’s dream! Every programmer’s happiness!Uhh? “programmer’s happiness”? = RoR  JEE RoR JRoR @CustCollab You being smart isn’t  Quick, feature rich enough …need smarter IDE Genetically coded releases for the Next Gen Configuration is the web...  Happy happy we Convention (seen web.xml shall be! When we of a large app?) learn our JRuby! AJAX 24
  • 25. Extensibility 25
  • 26. Extensibility + Productivity Multiple Response FormatsI want it NOW!consumers = browsers + computers + smart phones +…aliens? JEE RoR JRoR @CustCollab  Not readily Ready to eat XML,  Agile, XML based micro- cooked into the JSON, RSS, ATOM blogging API. Integrated framework w/ apps, BB, iOS devices <%= @messages.to_xml(:root => "messages") %> 26
  • 27. The battlefield……… 27
  • 28. Security 28
  • 29. Security + Productivity SAML Single Sign-OnDon’t re-invent. Reuse. JEE RoR JRoR @CustCollab Tested, ready to  Develop it or wait till  Reused the ready to use Java someone else does. Then use! That was fast! OpenSAML customize it, test it. custom components in CustCollab 29
  • 30. Security + Optimization Session ManagementKey to quality of service for good guys. Master key for bad guys.Secure to death. JEE RoR JRoR @CustCollab  In-memory w/o  Cookie: 4 KB limit, not  Secure, high quality i/o, w/ auto- b/w friendly, of service session invalidation vulnerable in principle mgmt. = JEE  Inherits app. server’s  AR: db queries + session store high availability (HA) cleanup daemon = architecture (perf. + maint.)++  Vary session timeout based on  Session mgmt.  Memcached: +1 intranet or internet API: Set timeout breakpoint + need to using JEE session based on IP range design HA + cleanup mgmt. APIs w/o persistent cookie 30
  • 31. Security + Productivity Protection Against Security ThreatsBuilt-in is better. JEE RoR JRoR @CustCollab Protection against XSS,  XSS, SQL injection,  Micro-blogging SQL injection etc. prepared stmts, use case most CSRF protection? [JSF 2.2 CSRF… vulnerable to XSS, (WIP): strong, Servlet  Easy to use plug-ins, SQL injection, spec 3.1 (WIP?): yes?] gems for others. E.g. CSRF. RoR ReCAPTCHA simplifies protection. “protect_from_forgery” + “verify :method =>…” 31
  • 32. The battlefield……… 32
  • 33. All this is fine, but have you thoughtabout my Total Cost of Ownership? 33
  • 34. Total Cost of Ownership Alignment with Preferred Tech. Stack= low total cost of ownership (TCO). Cost does matter. JEE JRoR on JEE runtime RoR @JavaJEEShop @JavaJEEShop @JavaJEEShop Mature. Large  Simplicity =  JEE resources ramped up footprint in Unconventionally on RoR…real quick! enterprise world short learning  Leveraged @CustCollab: & @CustCollab. curve for Apache mod_jk, Tomcat, Leverage dev, programmers build & deploy (war), ops skills,  Infra, ops, tools, jVisualvm, Servlet filters, infra, tools = evolving,…? = High logging & analysis etc. Low TCO TCO  Low TCO 34
  • 35. & the battles are over…so, who won the enter prize ? 35
  • 36. 36
  • 37. @ 37
  • 38. Hey, enough of dialogues! We want some action! 38
  • 39. Seeing is Believing. Can it walk the talk? JRuby 1.5 (Ruby 1.8.7), Rails 2.3.5, deployed as a WAR file on Tomcat 6 with PostgreSQL 8.4 database. Target load (~50% of prod. estimate): 1500 concurrent/active users in load test environment Response time target for transaction: 90th percentile should be < 2 to 3 seconds. Peak load steady state of 30 minutes. 39
  • 40.  2 application servers: Each w/ RHEL, virtualized, Intel® Xeon® , 2 vCPUs, 3 GB RAM, 2 GB JVM heap size. Test data volume: 270,000+ micro-blogging channels, 480,000+ micro-blogs. JRuby min and max runtimes = 1. Thread-safe code + “config.threadsafe!” in Rails.Warm-up database connection pool to around 150.On your mark…..get set….. 40
  • 41. Rails is Happiness… 41running…tracks(flickr)
  • 42. & the result is… 90th percentile of resp. time < 1.2 sec (!!), 100% passingThroughput achieved: o ~127,800 primary requests in steady state (30 min) - (excludes secondary req like images, css, js) o ~ 71 primary requests/sec in steady stateCPU utilizations o Each application server <= 60% o Database server <= 20% RAM usage before test ~ RAM usage during & after test JVM heap space utilization ~ 85% in steady state (peak) 42
  • 43. Quick facts…Live in production.Being used via web browser as well as from other apps & smart phones via micro-blogging API. Personal channels: 200,000+ Communities (active than personal): 5000+ Micro-blogs till Feb 2012: 224,000+ 43
  • 44. Now enter the climax… 44
  • 45. Hmmm…JRuby looks cool, isn’t it…So, do you want to build fast & scalable applications? Silver Bullet = 45Silver bullet (flickr)
  • 46. Oops…thereisNOsilverbullet 46
  • 47. buildFastScalableApp() { try { do { (estimate + architect + design + program).to_scale; assert_doesnt_scale? : don’t throw new hw($$$)  ; self.be_patient(); everything.tune(); } while (!scale && !tunedTheHellOutOfEverything); }//end try finally { if !scale? { throw new hw($$$) || throw new (arch && design) || throw new (technology) || self.resign(); }//end nightmare else { beer.overflow(); RubyConfIndia.talk()?; }//start celebrations }//end finally}//end job 47
  • 48. && while (that’s true)…{ Classy runtimes like JVM ability to scale …rest is left up to the developer’s abilities & ENV[“constraints”]…} 48
  • 49. &&{ Simple languages like Ruby & Convention based frameworks like Rails productivity (more time to work on scalability :)...rest is left up to the developer’s abilities & ENV[“constraints”]…} 49
  • 50. &&{ Classy, Simple, Convention based marriages like JRuby on Rails ability to scale && productivity …rest is left up to you to arrange such a marriage that’s fast & will last in your ENV[“constraints”]…} 50
  • 51. finally { for (ENV[“CustCollab”]) { that.marriage = jruby + rails; }}//end talk…almost 51
  • 52. Done? Where’s the little rhyming love song that was promised? 52
  • 53. ‘Java + Ruby’ works just well…Best of both is glued by the JRuby gel… Its fast… & will scale… Thanks JRuby, your promise didn’t fail! - Darshan  53
  • 54. A note of thanks to the backstageo My colleague Yashasree Barve for letting me know abt RubyConfIndia CFP.o RubyConfIndia for this opportunity!o Manasee, my worried wife, for being cool with JRuby, Rails, MS ppt & me over all the weekends those followed my talk’s selection (she’s worried if I would ever finish preparing these slides & present them well…) 54
  • 55. Artwork creditsoThe creative & open minds on flickr: o Mr. Ahmad Kavousian for officially permitting me to use his beautiful art work - /photos/kavous/2473202527/ o Silver bullet - /photos/eschipul/4160817135/ o People - /photos/kheelcenter/5279081507/ o Twitter bird - /photos/travelinlibrarian/4329755033/ o Garbage truck - /photos/jeffyoungstrom/3602384021/ o Rain drops - /photos/photographygal123/4959951870/ o Running along train tracks - /photos/seandreilinger/3167848378/ 55
  • 56. …& they lived happily ever after… 56“On a rail track” by Ahmad Kavousian (flickr)
  • 57. twitter.com/#!/dkarandikarin.linkedin.com/in/darshankarandikar 57

×