Tuesday, 5 March 2013

Java on a $5 per month server from Digital Ocean

I just recently came across Digital Ocean - "Simple Cloud Hosting". I was impressed by the pricing, much cheaper than my current VPS solution so I've set up an Ubuntu 12.10 server with 512MB, 20GB SSD, for $5 USD per month. Since I've moved almost everything to Google (from self hosted WordPress to Blogger and Google Docs) the only thing I really need a VPS for is to run my Java applications (there still is the option to use AppEngine with Play 1.2.x if it makes sense to use DataStore).

But for $5 a month, this means I can use Grails or Play with a relational database - if it performs well enough.


Setting up a server with Digital Ocean really is simple. Once you've signed up (check their Twitter posts for a coupon) and added a credit card, your server can be running in minutes. I chose Ubuntu 12.10, and then they have nice and clear instructions on what to do next to secure it:
Now, a couple of other things I did to get the server up to date and install Jetty8:
  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install openjdk-7-jre-headless
  • sudo apt-get install jetty8
To get jetty to start, you've got to edit /etc/default/jetty8 and change:
  • NO_START=0
  • JETTY_HOST=0.0.0.0
  • JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/jre/
You can find the location of Java by using 
  • ls -al /etc/alternatives/java
which should show you the linked path such as
  • lrwxrwxrwx 1 root root 45 Mar  5 01:58 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java
Now start Jetty with
  • sudo service jetty8 start
and it should be running on port 8080. I still have to enable it on port 80, but first I'll see how well my applications run on it and how it goes with memory.

'top' is currently reporting 188MB free - not much, but to upgrade to 1G is only going to cost $10p/m - I'll just have to see how well the applications run...

top - 03:27:04 up  1:29,  3 users,  load average: 0.00, 0.01, 0.04
Tasks:  67 total,   1 running,  66 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:    508396 total,   319948 used,   188448 free,    16688 buffers
KiB Swap:        0 total,        0 used,        0 free,   250652 cached

(In the past I've usually used Apache in front of Tomcat, but since I don't need all that flexibility any more, I'm trying to simplify my setup and make the best use of my memory) 

6 comments:

  1. This is very old school... having to setup everything and worry about security, updates and backup. I have started using openshift and their offering is really good, choose your back end technology, choose your persistence stack, connect the two, push to the provided git repo to publish, and jenkins will build & promote your code...
    Give it a try, for now the initial offering is free, you can't beat that...

    ReplyDelete
  2. Thats right, it is old-school, but still simple. I'll have a look at openshift, it does look interesting.

    ReplyDelete
  3. Accessing Jetty on port 80 was as simple as forwarding 80 to 8080 as described http://wiki.eclipse.org/Jetty/Howto/Port80

    sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

    ReplyDelete
  4. I recently tried installing play 2 on DO with 512 MB configuration. My server goes down after few hrs. Not sure if it is issue with memory or what. Cloudbees give free account to host play application with just 128M and it never crashes.
    Not sure if it is still 512 M issue on DO or what

    ReplyDelete
  5. I'm writing my current app using Python/Django - I started with Play2 (java) but it just seemed too difficult and slow (ide problems and scala issues). I'm hoping Django will have a smaller memory footprint and run on the DO 512M better than a java app. I am enjoying Django - it's quite easy and flexible and fast, and I hope it is also easier to deploy (I'm thinking to update the server I'll just checkout a tag from git).

    ReplyDelete
  6. Although this post is a bit old (2011), it says good things about Play2 memory consumption:

    "The memory consumption is amazing: only 2MB of heap is used when a Play 2.0 app is started. Tests on Guillaume's laptop have shown that it can handle up to 40,000 requests per second, without any optimization of the JVM. Not only that, but after the requests subside, garbage collection cleans up everything and reduces the memory consumption back to 2MB."

    http://raibledesigns.com/rd/entry/play_2_0_a_web

    ReplyDelete