Dynamic Languages & Web Frameworks in GlassFish v3 Arun Gupta (blogs.sun.com/arungupta, @arungupta) Sun Microsystems, Inc.
What is a Dynamic Language ? <ul><li>Broadly a language that allows a program to change its own code at runtime </li><ul><...
Manipulate code as data ({&quot;name&quot;=>&quot;Duke&quot;}.each {|data| puts data})
High order functions
Dynamic Typing
Closures, Continuations, Macros, ... </li></ul><li>Simple, human-readable syntax
List, Ruby, Python, Groovy, ... </li></ul>
Web Frameworks <ul><li>Full-stack </li><ul><li>Object relational mapping
MVC-pattern
Templating
JavaScript library
Extension points </li></ul><li>Agile Development </li><ul><li>No compile, redeploy, restart cycles
Testing built into the framework </li></ul></ul>
Design Principles <ul><li>Convention over Configuration (CoC) </li><ul><li>Common cases easily served
Encourages standard practices
Everything simpler and smaller </li></ul><li>Don't Repeat Yourself (DRY) </li><ul><li>Framework written around minimizing ...
What is GlassFish ? <ul><li>A community </li><ul><li>Users, Partners, Testers, Developers, ...
Started in 2005 on java.net </li></ul><li>Application Server </li><ul><li>Enterprise Quality and Open Source
Java EE Reference Implementation
Full Commercial Support from Sun </li></ul></ul>
Sun GlassFish Enterprise Server GlassFish Open Source Application Server Customer Focused Support Team Patches & Upgrades ...
GlassFish v3 <ul><li>Modular: </li><ul><li>Maven 2 – Build & Module description
Felix – OSGi runtime (216 bundles)
Allow any type of Container to be plugged </li><ul><li>Start Container and Services on demand </li></ul></ul><li>Embeddabl...
Extensible </li><ul><li>Rails, Grails, Django, ... </li></ul></ul>
GlassFish v3 Architecture GlassFish Kernel Security Rails Grails Web Config Injection Naming Grizzly Bundles Repositories ...
Dynamic Languages & Frameworks http://glassfish-scripting.dev.java.net
<ul><li>Ruby interpreter written in Java
Current Version: 1.4.0
Ruby 1.8.6 compatible
Some Ruby 1.9 support  </li><ul><li>--1.9 flag
80% of 1.9.1 </li></ul><li>9 Active committers </li></ul>What is  ? http://jruby.kenai.com/presentations/JRubyConf%2009%20...
Compatibility <ul><li>~37,000 passing rubyspecs
~22,000 passing assertions
Continuous Integration </li><ul><li>On commit ~3 Java versions * 4 vendors
Nightly: 30 minute “full” run </li></ul></ul>
<ul><li>Solid performance (  ͋ Ruby 1.9) </li><ul><li>Startup is poor, execution usually better than 1.9 </li></ul><li>Run...
Foreign Function Interface (FFI) for C libraries
Runs Rails great! </li></ul>
<ul><li>Full-stack Web development MVC framework in Ruby
Current Version: Rails 2.3.4
Getting Started </li><ul><li>Install Rails: “jruby -S gem install rails”
Generate Rails app: “jruby -S rails helloworld” </li></ul></ul>What is  ?
Rails Deployment Choices Credits: http://birdwatchersdigest.com
Directory-based Deployment: How ? jruby -S rails helloworld asadmin start-domain asadmin create-jvm-options -DJRUBY_HOME=....
Directory-based: Capistrano Recipes http://wiki.glassfish.java.net/Wiki.jsp?page=DeployUsingCapsitrano
Rails Development using NetBeans 6.8 http://blogs.sun.com/arungupta/entry/screencast_26_develop_run_debug
Rails Deployment: GlassFish Gem
GlassFish Gem: How ? jruby -S rails helloworld jruby -S gem install glassfish cd helloworld jruby -S glassfish
Single Threaded Rails < v 2.2
Multi Threaded Rails or Merb or ...
GlassFish Gem: Capistrano Recipes http://wiki.glassfish.java.net/Wiki.jsp?page=DeployUsingCapsitrano
GlassFish Gem Options jruby -S glassfish -h -n:  Number of JRuby runtimes to create initially --runtimes-min:  Minimum run...
Demo GlassFish Gem http://blogs.sun.com/arungupta/entry/totd_76_jruby_1_2
GlassFish Gem in Production <ul><li>Easy,  green  deployment </li><ul><li>Reverse proxy not required
JRuby runtime pool provides required scaling </li><ul><li>Rails is single threaded by default </li></ul><li>MT frameworks ...
Optional front-ending http://blogs.sun.com/arungupta/entry/totd_81_how_to_use http://blogs.sun.com/arungupta/entry/totd_84...
Rails Deployment: WAR-based
WAR-based: How ? jruby -S gem install warbler cd helloworld   jruby warble config   Edit “config/warble.rb”   Include gems...
WAR Deployment: Packaging
Demo WAR-based Deployment http://blogs.sun.com/arungupta/entry/totd_73_jruby_and_glassfish
Upcoming SlideShare
Loading in...5
×

Dynamic Languages Web Frameworks Indicthreads 2009

2,333

Published on

Dynamic Languages & Web Frameworks in GlassFish v3 presentation at 4th IndicThreads conference, Pune, India.

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

No Downloads
Views
Total Views
2,333
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
35
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Dynamic Languages Web Frameworks Indicthreads 2009

  1. 1. Dynamic Languages & Web Frameworks in GlassFish v3 Arun Gupta (blogs.sun.com/arungupta, @arungupta) Sun Microsystems, Inc.
  2. 2. What is a Dynamic Language ? <ul><li>Broadly a language that allows a program to change its own code at runtime </li><ul><li>Evaluate data as code (&quot;The name is: #{@name}&quot; )
  3. 3. Manipulate code as data ({&quot;name&quot;=>&quot;Duke&quot;}.each {|data| puts data})
  4. 4. High order functions
  5. 5. Dynamic Typing
  6. 6. Closures, Continuations, Macros, ... </li></ul><li>Simple, human-readable syntax
  7. 7. List, Ruby, Python, Groovy, ... </li></ul>
  8. 8. Web Frameworks <ul><li>Full-stack </li><ul><li>Object relational mapping
  9. 9. MVC-pattern
  10. 10. Templating
  11. 11. JavaScript library
  12. 12. Extension points </li></ul><li>Agile Development </li><ul><li>No compile, redeploy, restart cycles
  13. 13. Testing built into the framework </li></ul></ul>
  14. 14. Design Principles <ul><li>Convention over Configuration (CoC) </li><ul><li>Common cases easily served
  15. 15. Encourages standard practices
  16. 16. Everything simpler and smaller </li></ul><li>Don't Repeat Yourself (DRY) </li><ul><li>Framework written around minimizing repetition </li></ul></ul>
  17. 17. What is GlassFish ? <ul><li>A community </li><ul><li>Users, Partners, Testers, Developers, ...
  18. 18. Started in 2005 on java.net </li></ul><li>Application Server </li><ul><li>Enterprise Quality and Open Source
  19. 19. Java EE Reference Implementation
  20. 20. Full Commercial Support from Sun </li></ul></ul>
  21. 21. Sun GlassFish Enterprise Server GlassFish Open Source Application Server Customer Focused Support Team Patches & Upgrades 24x7 Support Customer Advocate Sun VIP Interoperability Support Enterprise Manager eLearning Credit
  22. 22. GlassFish v3 <ul><li>Modular: </li><ul><li>Maven 2 – Build & Module description
  23. 23. Felix – OSGi runtime (216 bundles)
  24. 24. Allow any type of Container to be plugged </li><ul><li>Start Container and Services on demand </li></ul></ul><li>Embeddable: runs in-VM
  25. 25. Extensible </li><ul><li>Rails, Grails, Django, ... </li></ul></ul>
  26. 26. GlassFish v3 Architecture GlassFish Kernel Security Rails Grails Web Config Injection Naming Grizzly Bundles Repositories HK2 Services OSGi Runtime
  27. 27. Dynamic Languages & Frameworks http://glassfish-scripting.dev.java.net
  28. 28. <ul><li>Ruby interpreter written in Java
  29. 29. Current Version: 1.4.0
  30. 30. Ruby 1.8.6 compatible
  31. 31. Some Ruby 1.9 support </li><ul><li>--1.9 flag
  32. 32. 80% of 1.9.1 </li></ul><li>9 Active committers </li></ul>What is ? http://jruby.kenai.com/presentations/JRubyConf%2009%20Keynote.pdf
  33. 33. Compatibility <ul><li>~37,000 passing rubyspecs
  34. 34. ~22,000 passing assertions
  35. 35. Continuous Integration </li><ul><li>On commit ~3 Java versions * 4 vendors
  36. 36. Nightly: 30 minute “full” run </li></ul></ul>
  37. 37. <ul><li>Solid performance ( ͋ Ruby 1.9) </li><ul><li>Startup is poor, execution usually better than 1.9 </li></ul><li>Runs native threads
  38. 38. Foreign Function Interface (FFI) for C libraries
  39. 39. Runs Rails great! </li></ul>
  40. 40. <ul><li>Full-stack Web development MVC framework in Ruby
  41. 41. Current Version: Rails 2.3.4
  42. 42. Getting Started </li><ul><li>Install Rails: “jruby -S gem install rails”
  43. 43. Generate Rails app: “jruby -S rails helloworld” </li></ul></ul>What is ?
  44. 44. Rails Deployment Choices Credits: http://birdwatchersdigest.com
  45. 45. Directory-based Deployment: How ? jruby -S rails helloworld asadmin start-domain asadmin create-jvm-options -DJRUBY_HOME=... asadmin deploy railsconf
  46. 46. Directory-based: Capistrano Recipes http://wiki.glassfish.java.net/Wiki.jsp?page=DeployUsingCapsitrano
  47. 47. Rails Development using NetBeans 6.8 http://blogs.sun.com/arungupta/entry/screencast_26_develop_run_debug
  48. 48. Rails Deployment: GlassFish Gem
  49. 49. GlassFish Gem: How ? jruby -S rails helloworld jruby -S gem install glassfish cd helloworld jruby -S glassfish
  50. 50. Single Threaded Rails < v 2.2
  51. 51. Multi Threaded Rails or Merb or ...
  52. 52. GlassFish Gem: Capistrano Recipes http://wiki.glassfish.java.net/Wiki.jsp?page=DeployUsingCapsitrano
  53. 53. GlassFish Gem Options jruby -S glassfish -h -n: Number of JRuby runtimes to create initially --runtimes-min: Minimum runtimes --runtimes-max: Maximum runtimes -c : change the context root -e : environment -d : Runs as daemon -P : location of PID file -l : log file location -log-level : Logging level (0-7)
  54. 54. Demo GlassFish Gem http://blogs.sun.com/arungupta/entry/totd_76_jruby_1_2
  55. 55. GlassFish Gem in Production <ul><li>Easy, green deployment </li><ul><li>Reverse proxy not required
  56. 56. JRuby runtime pool provides required scaling </li><ul><li>Rails is single threaded by default </li></ul><li>MT frameworks scales automatically </li><ul><li>JRuby and JVM support native threads </li></ul></ul><li>Configuration using “glassfish.yml” </li></ul>
  57. 57. Optional front-ending http://blogs.sun.com/arungupta/entry/totd_81_how_to_use http://blogs.sun.com/arungupta/entry/totd_84_using_apache_mod
  58. 58. Rails Deployment: WAR-based
  59. 59. WAR-based: How ? jruby -S gem install warbler cd helloworld jruby warble config Edit “config/warble.rb” Include gems, Change RAILS_ENV jruby warble asadmin deploy helloworld.war jruby -S rails helloworld
  60. 60. WAR Deployment: Packaging
  61. 61. Demo WAR-based Deployment http://blogs.sun.com/arungupta/entry/totd_73_jruby_and_glassfish
  62. 62. JRuby Module on GlassFish Update Center
  63. 63. Ruby Rack Support <ul><li>Rack - A Web server interface
  64. 64. Plugin any Rack compliant framework </li><ul><li>Rails, Merb, Sinatra, Ramaze, Campsite, ... </li></ul><li>Rack support in GlassFish </li><ul><li>GlassFish Gem </li><ul><li>Plugin any Rack metal (such as RackCache) </li></ul><li>GlassFish v2 & v3 through Warbler </li></ul><li>Use your own framework </li><ul><li>Rackup script
  65. 65. jruby.applicationType property </li></ul></ul>
  66. 66. Ruby Application Auto-detection
  67. 67. Performance <ul><li>Need JVM tuning for production </li><ul><li>Use Server profile where possible (- server ) </li></ul><li>GC settings </li><ul><li>-XX:+DisableExplicitGC, -XX:NewRatio=2 </li></ul><li>Memory settings </li><ul><li>Use large settings for -Xmx -Xms and -XX:MaxPermSize
  68. 68. Use at least 20 MB perm gen space for each JRuby runtime </li></ul></ul>
  69. 69. Scaling <ul><li>Rails is single-threaded by default
  70. 70. Setup JRuby runtime pool </li><ul><li>With gem </li><ul><li>glassfish -n 3 –runtime-min 2 –runtime-max 4 </li></ul></ul><li>2 HTTP Worker Threads per runtime
  71. 71. Turn on file caching </li><ul><li>network-config>protocols>protocol>http>file-cache#enabled </li></ul><li>MT frameworks (Rails > 2.2, Merb) </li><ul><li>No configuration needed </li></ul></ul>
  72. 72. Rails Monitoring <ul><li>Basic Monitoring </li><ul><li>jinfo : System properties and VM CLI flags
  73. 73. jmap : Shared object memory map
  74. 74. jstack : Stack traces of Java threads
  75. 75. jstat : Performance stats on class, JIT compiler, GC </li></ul><li>Advanced </li><ul><li>jconsole / Visual VM
  76. 76. NewRelic, FiveRuns, ... </li></ul></ul>
  77. 77. Rails Monitoring in GlassFish v3 <ul><li>asadmin enable-monitoring –level jruby-container=HIGH
  78. 78. asadmin list –monitor=true “*”
  79. 79. asadmin list –monitor=true “*jruby*”
  80. 80. asadmin list-probes | grep jruby
  81. 81. dtrace or JavScript-based monitoring </li></ul>http://blogs.sun.com/arungupta/entry/totd_104_glassfish_v3_monitoring
  82. 82. Endorsements Look like the best deploying option I ever found for Rails, GREAT! the easiest rails stack in the world, jruby 1.2rc, rails 2.3rc, glassfish v3 ... too easy to run jruby/rack/ glassfish behind nginx leading the way to simple, scalable, no-hassle hosting for Ruby web applications. ... it's true one-step deployment . had no reliability and performance issues with Glassfish money is on JRuby (and Glassfish) for the long haul ; if you haven't checked out Glassfish yet, you're doing yourself a disservice! nice way to deploy and manage my app while leaving things open for scaling
  83. 83. Who loves Rails on GlassFish ?
  84. 85. What is ? <ul><li>Agile dynamic language for the JVM
  85. 86. Seamlessly integrates with all existing Java objects & libraries </li><ul><li>Compiles straight to bytecode </li></ul><li>Current version: 1.6.7
  86. 87. groovy -e &quot;println 'Hello ' + args[0]&quot; World </li></ul>
  87. 88. What is ? <ul><li>MVC Web framework for the Java platform </li><ul><li>Persistence framework (Hibernate)
  88. 89. Templating using GSP (Groovy Server Pages)
  89. 90. Tag libraries to create web page components
  90. 91. Good Ajax support
  91. 92. Web server & automatic resources reload </li></ul><li>Current Version: 1.1.2, 1.2 RC1 released 12/5 </li></ul>
  92. 93. Grails “Hello World” <ul><li>Create app: “grails create-app bookstore” </li><ul><li>Create domain class: “grails create-domain-class book”
  93. 94. Edit “grails-app/domain/Book.groovy” and add attributes
  94. 95. Create controller: “grails create-controller Book”
  95. 96. Edit “grails-app/controllers/BookController.groovy”
  96. 97. Add scaffold: “def scaffold = Book” </li></ul><li>Run app: “grails run-app” </li></ul>
  97. 98. Grails on GlassFish App Server <ul><li>Create WAR: “grails war”
  98. 99. Deploy: “asadmin deploy helloworld-0.1.war” </li></ul>
  99. 100. Demo Grails & GlassFish http://blogs.sun.com/arungupta/entry/getting_started_with_grails_on http://blogs.sun.com/arungupta/entry/totd_75_getting_started_with http://blogs.sun.com/arungupta/entry/grails_on_glassfish_v3_embedded http://blogs.sun.com/arungupta/entry/tic_tac_toe_using_rails
  100. 101. Grails Module on GlassFish Update Center
  101. 102. Efficient Deployment <ul><li>Grails Application WAR </li><ul><li>Large </li><ul><li>Over 48 Grails dependent JARs
  102. 103. ~20MB for a simple app </li></ul><li>Expensive to bundle in single WAR
  103. 104. Issues when hot deployment is required </li></ul></ul>
  104. 105. GlassFish proposes light-weight WAR <ul><li>Don't package dependencies!
  105. 106. Smaller WAR file: ~200KB vs ~20MB
  106. 107. GlassFish knows how to find dependencies
  107. 108. Only one copy of dependencies in GlassFish </li><ul><li>Less memory consumption and deployment speed-up </li></ul><li>$ grails shared-war
  108. 109. With Grails 1.1 use –nojars option
  109. 110. $ asadmin deploy helloworld-0.1.war </li></ul>
  110. 111. GlassFish/Grails: Coming up ... <ul><li>Use “grails –nojars” </li><ul><li>JIRA-5174, JIRA-5175 </li></ul><li>“grails install-plugin glassfish –global” </li><ul><li>grails run-app </li></ul><li>“asadmin deploy grailsApp” </li></ul>
  111. 113. What is ? <ul><li>Implementation of Python in Java </li><ul><li>Seamless integration of Python and Java
  112. 114. Java <==> Python
  113. 115. Just Python
  114. 116. Dynamic compilation to Java bytecodes </li></ul><li>Jython 2.5.1 released (Sep 2009)
  115. 117. Works with Django 1.0 </li></ul>
  116. 118. What is ? <ul><li>MVC-based framework written in Python </li><ul><li>Object-relational mapper
  117. 119. A lightweight, standalone Web server
  118. 120. A regular expression based URL dispatcher
  119. 121. A templating system
  120. 122. A caching framework
  121. 123. An internationalization system
  122. 124. . . . </li></ul></ul>
  123. 125. GlassFish Deployment <ul><li>Deploy as WAR </li><ul><li>Modjy </li><ul><li>Servlet, ServletContextListener + WSGI Implementation
  124. 126. Integrated with Jython 2.5 </li></ul></ul><li>Pure Django Deployment </li><ul><li>Grizzly + WSGI => Django
  125. 127. No WAR, no packaging
  126. 128. asadmin deploy myDjangoApp </li></ul></ul>
  127. 129. How does it work ? <ul><li>Download Jython
  128. 130. Install Django (jython25 setup.py install)
  129. 131. GlassFish v3 Jython OSGi module from UC
  130. 132. asadmin create-jvm-options -Djython.home=...
  131. 133. cd DjangoApp
  132. 134. asadmin deploy . </li></ul>
  133. 135. Jython Module on GlassFish Update Center
  134. 136. Demo Django & GlassFish http://blogs.sun.com/arungupta/entry/totd_85_getting_started_with
  135. 137. http://blogs.sun.com/arungupta/entry/tic_tac_toe_using_rails
  136. 138. Java EE & Dynamic Languages <ul><li>JavaEE is a mature and robust platform </li><ul><li>Servlet, EJB, JMS, JAX-RS, JAX-WS... </li></ul><li>Hybrid Rails and Servlet/JSP application </li><ul><li>Forward to and from Rails to Servlet/JSP
  137. 139. HTTPSession as Rails session
  138. 140. ServletRequest/Response API available to Rails </li></ul><li>JDBC connection pool
  139. 141. JMS: Async messaging in Rails </li></ul>
  140. 142. Servlet 3.0 Pluggability <ul><li>JavaEE 6 and Dynamic Languages </li><ul><li>No boilerplate web.xml
  141. 143. Dynamically add ServletFilter and ServletContextListener </li></ul><li>Simple packaging </li><ul><li>No need to package as WAR, No Warbler
  142. 144. Place application inside WEB-INF directory </li></ul></ul>
  143. 145. References <ul><li>glassfish.org
  144. 146. glassfish-scripting.dev.java.net
  145. 147. sun.com/glassfish
  146. 148. blogs.sun.com/theaquarium
  147. 149. twitter.com/glassfish
  148. 150. [email_address] </li></ul>
  149. 151. Dynamic Languages & Web Frameworks in GlassFish v3 Arun Gupta (blogs.sun.com/arungupta, @arungupta) Sun Microsystems, Inc.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×