Friday, September 21, 2012

First month @Runa Inc. - Clojure shop in Silicon Valley

Recently, about a month ago to be precise, I was fortunate to join one of the Clojure powerhouse in the Bay Area, Runa Inc. I have to say that what I saw within first month of my real Clojure shop experience is so great that I made a personal commitment to write about at least one Clojure blog post a month about my journey there.
First of all, the choice of Clojure for the types of problems Runa is set out to solve is beyond the doubt is the right one. For any data centric projects, Clojure seems to be the best suited language out there for now. However, the aim of my post is not to convince what has already been pretty well known about Clojure. Rather, I would like to share few things about Runa's Clojure projects. Since I started with Runa, I found following about a project that I was assigned to work:
  • TDD is done right.  As stated in Amit's excellent book, Clojure in action, Runa really does stick with and encourage developer to use TDD. The project is very well tested and working with it has been a joy so far. In case if you have not read the book yet, the usual TDD flow is: Write failing test -> Make it pass -> Refactor and repeat. For example, if you are testing for existence of a particular information in a log file, which in turn comes from some configuration file, here is how you would put TDD in practice (Will post concrete examples in my next blog post): 
             - Write a failing test to check for the missing information that is not there.
             - Put the information in the config file and make the test pass
             - Refactor such as separate out config file creation and deletion using high order function. 
  • Small core.  What I am very excited about the project is that there is no frameworks or huge external library dependencies in it. It has minimal external libraries and has a very small and well tested core. Usage of fast and small library is always preferred to keep its foot print small. This has also added benefit of much portability in terms of deployment and being used as a module for other projects. The project is a high performance web service and it does not even use ring or compojure. It just uses jetty library.
  • Clojure can be fast, I mean really fast.   There are many ways to speed up clojure projects such as type hinting, using memoziation and using performant data structures such as chuncked sequence. But there are cases that one can utilize plain old java to speed it up even more. The project has very strict response time (a request response time has to be under 3 millisecond). Since we are all stateless, we end up using number of single java thread processes for logging, monitoring,instrumentation and also java queues from java.util.concurrent package. Now we are able to serve 40 thousand requests per second under 15% load capacity of per app instance.(The app is deployed on over a dozen nodes with a load balancer routing requests). I will blog with more details such as performance charts and overall big picture design in my future blog posts. 
If above sounds interesting to you, check us out.

Saturday, February 25, 2012

Simple way to use Clojure in Emacs 24

I have been thinking of writing this up for sometime. Do we really need another post about how to get started with Clojure in Emacs? There are so many articles on plethora of ways of doing this on the inter web. Honestly speaking, I have tried them all. I am not gonna list them here to save myself and you the trouble of being distracted. Finally, I have settled with following and I hope you do the same.
1. Install leiningen:
  a. wget https://raw.github.com/technomancy/leiningen/stable/bin/lein
  b. chmod +x lein
  c. lein self-install
  Note: If you are lucky user of Ubuntu 11.10, do: sudo apt-get install leiningen
2. Intall Emacs 24
  Ubuntu: sudo apt-add-repository ppa:cassou/emacs; apt-get install emacs-snapshot
  Mac OS: get it here: <a href="http://emacsformacosx.com/"></a>
3. Put following lines in your .emacs file and restart your emacs
(require 'package)
(add-to-list '
package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
(add-hook '
clojure-mode-hook
          (lambda ()
            (setq inferior-lisp-program "lein repl")))

Once your Emacs starts up fine, issues following command to get clojure mode:
Alt-x package-install clojure-mode

Then you can just open a clj file and run: alt-x inferior-lisp. You will get yourself a nice repl within Emacs and start hacking. Following is a quick summary of what you can do:
1. Move around defn and def forms with Ctrl-Alt-p and Ctr-Alt-n for up and down
2. Evaluate defn and def with Ctrl-Alt-x while the curser is anywhere within the form
3. Use Alt-p and Alt-n to navigate repl history

Plus, enjoy all of the rest of Emacs' superb editing powers while you are at it. I am also thinking of starting conversational style Clojure programming guide and let me know if you are interested in proof reading or contributing.

Sociable