[ Play 2.0 ] Deploying on production

1,579 views
Skip to first unread message

Aishwarya Singhal

unread,
May 16, 2012, 3:31:44 PM5/16/12
to play-framework
hi All

I am building my first play 2 (Scala) web application as a personal
project. I intend to host it on the EC2 and need your opinion on what
would be a high performance / recommended production set up. I can
think of the following options:

1. Web server + Servlet container
a. Apache HTTPD + Apache Tomcat
b. NGINX + Apache Tomcat
c. Apache HTTPD/ lighttpd + Jetty

2. Just a servlet container
a. Tomcat
b. Jetty
c. Resin?

3. Native netty + play service

4. Any other?

What do you recommend and why ?

Also, how do I generate a WAR file for play 2? Reading through the
docs, looks like dist would only create JARs.

Many thanks!
best regards
Aishwarya

Tex

unread,
May 16, 2012, 5:10:59 PM5/16/12
to play-fr...@googlegroups.com
Hi, 

for war deployment see: 

Lars Grote

unread,
May 16, 2012, 6:04:05 PM5/16/12
to play-fr...@googlegroups.com
I'd suggest nginx + play.
Meaning, don't use any web container like Tomcat, just use plain play. This would be the fastest, as far as I know.

Cheers

Eric Jain

unread,
May 16, 2012, 6:25:35 PM5/16/12
to play-framework
On May 16, 12:31 pm, Aishwarya Singhal <asingha...@gmail.com> wrote:
> What do you recommend and why ?

If you manage to generate a war file, Elastic Beanstalk might be the
simplest option.

Play 2.0 lacks many features (e.g. SSL or gzipping static resources);
if this matters, set up Apache or nginx as a reverse proxy.

Aishwarya Singhal

unread,
May 18, 2012, 5:45:41 AM5/18/12
to play-framework
Thanks a lot guys. For the time being, I have install tomcat + httpd.
Simply because I was more comfortable with the installation steps :-)

I like the idea of NGINX + play, however, I ran into too many
discouraging reports on Nginx with java stack on the net. Has anybody
tried that set up? How is it performing?

Elastic Beanstalk seems to be Amazon's package of httpd + tomcat, so I
just went with the raw installations. I have posted the steps on
http://aishwaryasinghal.wordpress.com/2012/05/18/deploy-play-2-application-on-aws-with-tomcat-and-apache-httpd/
for anybody that's interested.

best regards

On May 17, 3:25 am, Eric Jain <eric.j...@gmail.com> wrote:

Robin Green

unread,
May 18, 2012, 9:45:53 AM5/18/12
to play-fr...@googlegroups.com, Eric Jain
On 16 May 2012 23:25, Eric Jain <eric...@gmail.com> wrote:
Play 2.0 lacks many features (e.g. SSL or gzipping static resources);

No, gzipping is supported: 
 
"Play 2.0 comes with a built-in controller to serve public assets. By default, this controller provides caching, ETag, gzip compression and JavaScript minification support."

Eric Jain

unread,
May 18, 2012, 1:03:36 PM5/18/12
to play-fr...@googlegroups.com
I don't see any of my assets being gzipped--looks like this feature
was disabled in 2.0 (see [1] and [2]). JavaScript minification doesn't
work on all platforms (see [3]). Finally, ETags aren't being generated
correctly (see [4]). Don't trust the docs blindly :-)

[1] https://play.lighthouseapp.com/projects/82401/tickets/89-might-not-want-to-gzip-images-and-pdfs
[2] https://play.lighthouseapp.com/projects/82401/tickets/158-21-gzip-all-output-not-only-static-files
[3] https://play.lighthouseapp.com/projects/82401/tickets/274-closure-compiler-broken-in-windows
[4] https://play.lighthouseapp.com/projects/82401-play-20/tickets/480-etags-header-is-not-being-set-in-line-with-specification-standard

Aishwarya Singhal

unread,
May 18, 2012, 1:17:56 PM5/18/12
to play-framework
i can confirm that gzip/ minification doesn't seem to work out of the
box on my set up either :-) I am forcing minification and gzip through
old school techniques.

best

On May 18, 10:03 pm, Eric Jain <eric.j...@gmail.com> wrote:
> I don't see any of my assets being gzipped--looks like this feature
> was disabled in 2.0 (see [1] and [2]). JavaScript minification doesn't
> work on all platforms (see [3]). Finally, ETags aren't being generated
> correctly (see [4]). Don't trust the docs blindly :-)
>
> [1]https://play.lighthouseapp.com/projects/82401/tickets/89-might-not-wa...
> [2]https://play.lighthouseapp.com/projects/82401/tickets/158-21-gzip-all...
> [3]https://play.lighthouseapp.com/projects/82401/tickets/274-closure-com...
> [4]https://play.lighthouseapp.com/projects/82401-play-20/tickets/480-eta...

Marconi

unread,
May 18, 2012, 3:41:44 PM5/18/12
to play-fr...@googlegroups.com
On Friday, May 18, 2012 1:03:36 PM UTC-4, Eric Jain wrote:
> I don't see any of my assets being gzipped--looks like this feature
> was disabled in 2.0

You have to create the .gz file yourself:

"Gzip support
If a resource with the same name but using a .gz suffix is found, the Assets controller will serve this one by adding the proper HTTP header"

http://www.playframework.org/documentation/2.0.1/Assets

Marconi Lanna

unread,
May 18, 2012, 4:20:00 PM5/18/12
to play-fr...@googlegroups.com
Oh, and you have to start the application in PROD mode:

$ play run
$ curl -i -H "Accept-Encoding: gzip, deflate" localhost:9000/js/jquery-1.7.2.js
HTTP/1.1 200 OK
Content-Length: 252881
Content-Type: application/javascript
Etag: 7bba57cb766db28b0e444cd9707f54b01edad64c
Cache-Control: no-cache

$ play start
$ curl -i -H "Accept-Encoding: gzip, deflate" localhost:9000/js/jquery-1.7.2.js
HTTP/1.1 200 OK
Etag: ba70607994722f2d8f6010832da49935ac95944c
Content-Encoding: gzip
Content-Length: 33602
Cache-Control: max-age=3600
Content-Type: application/javascript

I love this arrangement: I can serve unminified files in DEV for easy debugging and minified, gzipped files in PROD. You can gzip -9 your files beforehand and not waste CPU cycles compressing them on the fly. One can also easily control which files are served compressed: I saved 45% by compressing my favicon.ico, but left all other images untouched; I compress my .eot, .svg, and .ttf web fonts, but not the .woff, etc.

You can see more details of how I'm using Play selective gzip compression at https://github.com/marconilanna/play-boilerplate/

Eric Jain

unread,
May 19, 2012, 11:17:03 AM5/19/12
to play-fr...@googlegroups.com
On Fri, May 18, 2012 at 1:20 PM, Marconi Lanna <marcon...@gmail.com> wrote:
> I love this arrangement: I can serve unminified files in DEV for easy
> debugging and minified, gzipped files in PROD. You can gzip -9 your files
> beforehand and not waste CPU cycles compressing them on the fly. One can
> also easily control which files are served compressed: I saved 45% by
> compressing my favicon.ico, but left all other images untouched; I compress
> my .eot, .svg, and .ttf web fonts, but not the .woff, etc.

That is a neat feature, but can the gzipping be done automatically at
build time? It's not a big deal to manually gzip files that rarely
change (e.g. JQuery), but this approach isn't great for your own
resources, and won't work for any js and css that is "compiled"
(Closure Compiler, LESS) by Play.

KajMagnus

unread,
May 26, 2012, 6:53:39 PM5/26/12
to play-fr...@googlegroups.com
Hi Eric!

I'm gzipping my Javascript files automatically at build time. I've written a SBT rule, that ... hmm... calls GNU Make, and the Makefile rules combine and gzip Javascript files.

I'm not currently using the closure compiler, but I think the approach (below) would work with the Closure compiler, since I simply concatenate and gzip files, after everything has been compiled and minified.


Here are my SBT rules:
===========================
  def mainSettings = List(
    compileRhinoTask := { "make compile_javascript"! },
    combineAndGzipJs := {
      "make combine_and_gzip_javascript"!
    },
    combineAndGzipJs <<= combineAndGzipJs.dependsOn(compile in Compile),
    Keys.compile in Compile <<=
       (Keys.compile in Compile).dependsOn(compileRhinoTask),
    playPackageEverything <<=
       (playPackageEverything).dependsOn(combineAndGzipJs))

  val rhinoClassDir = "target/scala-2.9.1/classes/"

  def compileRhinoTask = TaskKey[Unit]("compile-js",
    "Invokes Rhino to compile Javascript to Java bytecode")

  def combineAndGzipJs = TaskKey[Unit]("combine-and-gzip-js",
    "Appengs and gzips much Javascript to one single file")
===========================


Here is the relevant part of my Makefile. (I'm new to GNU Make so there're some duplicated code.)
===========================
# Combine some Javascript files, and gzips the resulting files, so Play will serve them
# gzip compressed.

PUBLIC_JS_DIR=target/scala-2.9.1/classes/public/debiki-core-resources/js/
PUBLIC_JS_LIB_DIR=target/scala-2.9.1/classes/public/debiki-core-resources/lib/

JS_DESKTOP_MIN_JS = ${PUBLIC_JS_DIR}combined-debiki-desktop.min.js
JS_TOUCH_MIN_JS = ${PUBLIC_JS_DIR}combined-debiki-touch.min.js
JS_LOGIN_MIN_JS = ${PUBLIC_JS_DIR}combined-debiki-login.min.js

JS_DESKTOP_MIN_JS_GZ = ${JS_DESKTOP_MIN_JS}.gz
JS_TOUCH_MIN_JS_GZ = ${JS_TOUCH_MIN_JS}.gz
JS_LOGIN_MIN_JS_GZ = ${JS_LOGIN_MIN_JS}.gz

JS_COMMON_SRC = \
  ${PUBLIC_JS_DIR}diff_match_patch.js \
  ${PUBLIC_JS_DIR}html-sanitizer-minified.js \
  ${PUBLIC_JS_DIR}jquery-cookie.js \
  ${PUBLIC_JS_DIR}tagdog.js \
  ${PUBLIC_JS_DIR}javascript-yaml-parser.js

JS_DESKTOP_ONLY_SRC = \
  ${PUBLIC_JS_DIR}jquery-scrollable.js \
  ${PUBLIC_JS_DIR}debiki-utterscroll.js \
  ${PUBLIC_JS_DIR}bootstrap-tooltip.js

JS_LOGIN_SRC = \
  ${PUBLIC_JS_DIR}popuplib.js \
  ${PUBLIC_JS_LIB_DIR}openid-selector/js/openid-jquery.js \
  ${PUBLIC_JS_LIB_DIR}openid-selector/js/openid-en.js

JS_TOUCH_SRC = \
  ${JS_COMMON_SRC} \
  ${PUBLIC_JS_DIR}debiki.js

# For now, don't include JS_LOGIN_SRC. I'll load those files one at a time,
# so I don't have to rewrite that much Javascript right now.
JS_DESKTOP_SRC = \
  ${JS_COMMON_SRC} \
  ${JS_DESKTOP_ONLY_SRC} \
  ${PUBLIC_JS_DIR}debiki.js

combine_and_gzip_javascript: ${JS_DESKTOP_MIN_JS_GZ} ${JS_TOUCH_MIN_JS_GZ} ${JS_LOGIN_MIN_JS_GZ}

# (How can I merge the dupl code in these 2 x 3 rules?)

${JS_DESKTOP_MIN_JS}: ${JS_DESKTOP_SRC}
cat $^ > $@

${JS_TOUCH_MIN_JS}: ${JS_TOUCH_SRC}
cat $^ > $@

${JS_LOGIN_MIN_JS}: ${JS_LOGIN_SRC}
cat $^ > $@

${JS_DESKTOP_MIN_JS_GZ}: ${JS_DESKTOP_MIN_JS}
gzip -c $^ > $@

${JS_TOUCH_MIN_JS_GZ}: ${JS_TOUCH_MIN_JS}
gzip -c $^ > $@

${JS_LOGIN_MIN_JS_GZ}: ${JS_LOGIN_MIN_JS}
gzip -c $^ > $@
===========================

HTH, KajMagnus


On Saturday, May 19, 2012 5:17:03 PM UTC+2, Eric Jain wrote:

Pete

unread,
Feb 22, 2014, 11:26:50 AM2/22/14
to play-fr...@googlegroups.com
It'd be nice if there was a step by step tutorial or video tutorial that showed you how to deploy a play project

Will Sargent

unread,
Feb 22, 2014, 7:08:40 PM2/22/14
to play-fr...@googlegroups.com
There's


but the steps are different for every platform you're deploying to.

Will Sargent
Consultant, Professional Services
Typesafe, the company behind Play Framework, Akka and Scala


On Sat, Feb 22, 2014 at 8:26 AM, Pete <piotrrom...@gmail.com> wrote:
It'd be nice if there was a step by step tutorial or video tutorial that showed you how to deploy a play project

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages