Updates from April, 2014 Toggle Comment Threads | Keyboard Shortcuts

  • Richard 2:53 pm on April 16, 2014 Permalink |  

    Running Clojure on Azure Web Sites 

    The recent release of Java on Microsoft Azure Web Sites was a big one. Not only because there are a load of Java developers out there that can now get easy access to a great public cloud (and yes, Web Sites have sticky sessions out of the box) but the announcement is much more than just Java, it’s the Java Virtual Machine.

    The JVM is host to a number of interesting languages, so this announcement unlocks the potential to run thing likes Scala, Clojure, Groovy, JRuby, Jython and Kotlin on Azure Web Sites.

    I thought it would be fun to start with Clojure. It’s what Uncle Bob would do.

    This tutorial takes you from scratch to having a clojure ‘hello world’ running. I did this all from Windows 8, but I assume you could do this just as easily from any desktop operating system.

    Prerequisites

    Install Java

    Install Java SE Development Kit 7

    Install Clojure 1.6

    Install Leiningen

    Install Git

    (yes there’s a lot of installing)

    Create a Hello World Application

    We’ll use compojure to create a simple hello world app, and then create a war file.

    From the command prompt type this:

    > lein new compojure hello-world

    You can test your new web application by typing in:

    > cd hello-world
    > lein ring server

    … which will start the web server on port 3000.

    Now create a ‘war’ file, which we will use to deploy the application to Azure:

    > lein ring uberwar

    This should create something called target/hello-world-0.1.0-SNAPSHOT-standalone.war

    Creating the Azure Web Site from the Jetty Template

    The easiest way to get Java running is to take the existing Jetty template.

    In the Azure Portal go to ‘New’ and select Compute -> Web Site -> From Gallery.

    Select the ‘Jetty’ template (it’s in the ‘Templates’ sub section).

    Type in a unique url, and select a region, and click the ‘tick’ button to create the site.

    This will create a template website with the Jetty stuff already configured.

    Deploy to Azure

    To deploy our Clojure app, we need to put the war file in the right place in the Jetty template, and then push it up to Azure.

    In the portal navigate to the newly created website and click ‘Set up deployment from source control’ and select ‘Local Git repository’.

    This will take a few seconds, then give you a git url.

    Copy this url, and then from the command prompt, navigate out of the clojure app directory, and clone the website to a new directory (make sure the USERNAME and WEBSITENAME bit are correct for your site).

    > cd ..
    > git clone https://USERNAME@WEBSITENAME.scm.azurewebsites.net:443/WEBSITENAME.git
    > cd WEBSITENAME

    Now take the ‘target/hello-world-0.1.0-SNAPSHOT-standalone.war’ file, and save it in the ‘bin/jetty-distribution-9.1.2.v20140210/webapps’ directory as ‘ROOT.war’. This should replace the existing file.

    > git commit -am "added clojure war"
    > git push origin master

    And you’re done.  Navigate to the URL for your web site, and you should see ‘Hello World’.

    Conclusion

    It’s exciting to see Microsoft providing support for the JVM in Azure Web Sites. The JVM support a rich ecosystem of new languages and web frameworks, and deployment to Azure websites is a simple git push away.

    Oh, and Clojure is fun.

    Advertisement
     
  • Richard 9:51 am on April 3, 2014 Permalink |  

    Microsoft Codename Orleans Public Preview 

    OrleansSDK_128x

    Yesterday at build the public preview of Micosoft’s Codename Orleans project was announced.

    You can download the Orleans binaries here:

    http://aka.ms/orleans

    The blog post on the .NET blog has more details:

    http://blogs.msdn.com/b/dotnet/archive/2014/04/02/available-now-preview-of-project-orleans-cloud-services-at-scale.aspx

    I was privileged enough to have early access to the project, and I wrote a few of the samples available in the Codeplex repository:

    https://orleans.codeplex.com/

     

    Why is Orleans Interesting?

    Orleans is ideally suited to problems requiring both high scale and low latency, but that doesn’t preclude you from using it at small scale.

    What Orleans does well is manage a large number of grains (the Orleans term for an actor) in memory, think hundreds of thousands of grains per server. It does this by managing the lifecycle of these objects, so they are only active when required, and after a certain period they can be garbage collected. Keeping these object in memory gives you low latency, as you can respond to requests on your system out of state you have in memory, rather than having to load information out of a database. It’s a bit like an in-memory cache in some regards, only the objects in the cache are programmable.

    Orleans can run on a cluster of machines (think hundreds of machines) to provide the high scale. The system has a fairly linear relationship between throughput and cluster size, which in plain english means that adding more machines to your cluster will increase your capacity, and doesn’t degrade too badly due to inter-server communication.

    Orleans is written in .NET, and you write your grains in C#. Grains are simply an interface and a class. The system is designed to be easy for the developer use. You don’t have to be a distributed system expert, those kinds of problems have been solved for you in the framework.

    Orleans will run on Windows Server, but it’s really designed for Azure. It’s a simple xcopy deploy to install, and comes with libraries designed to work with Worker Roles. You’ll need to front Orleans with your own API, which will have to be .NET (probably ASP.NET/WebAPI).

    Orleans gives you some constraints you must work within. You cannot have any shared state between grains, and all code must be asynchronous.

    However Orleans gives you some good guarantees. These are that there will only ever be one instance of a grain of a given identity and that the code in the grain will only run in a single thread (you can have exceptions to these rules). This means you don’t have to worry about thread safety, locking and parallel programming. You just write simple class implementations.

    Single threaded async, it sounds a bit like node.js doesn’t it? It even has the node hexagons. This is probably the reason I like Orleans so much!

    What next?

    Watch this space. I expect a small ecosystem of tools and libraries to grow up around Orleans, let me know if you’re interested.

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel