Tuesday, September 20, 2011

Play Framework Cookbook :book review


Play Framework Cookbook

Author : Alexander Reelsen

Play framework is an upcoming framework that comes in the growing breed of rapid application development, using convention over configuration based web application development.
The thing that sets apart this framework apart from others is the customizability of the framework in the jvm, while taking advantage of either java or scala as desired. However, owing to the late arrival of play, there has been a lack of tutorials and documentation in order to solve real world problems with this framework.
This book, being a cookbook covers the topics, head-on and gives practical insight into building web application while covering loads of practical topics, from installation to deployment.

The book has been divided into 7 chapters and a small appendix. The first chapter covers the basics and is good for those coming without rails experience. However, the chapter also presents recepies for customizing all parts of the framework- pretty much everything that other technology cookbooks pack into themselves from cover to cover. The middle chapters dig deeper into the framework and integration with external services. One thing that is special in this cookbook is it devotes 3 chapters to modules as extensibility via modules is one of the main differentiating factor that play framework offers.  In line with practicality, the book devotes its last chapter totally on deployment and release functions. This does omits the cloud vendors that provide paas for play framework directly, but as a lot of cloud offerings for play are unfinalized, they do not find any mention. The appendix is a disappointment as there are no pointers for carrying out further. As with any upcoming technology, it is imperative to look out for more resources in order to update and correct ourselves with its ecosystem. This is especially important as play 2.0 would be out on beta by the end of this year and a reader always expects pragmatism from a hands-on cookbook. Also, due to the flexibility of this framework, various PAAS vendors are providing, or planning to provide play support, which deserves at least a listing of these services. The author clearly states his intention behind leaving scala based applications in play, and this hopefully might make its way in future editions.

Overall, this is a book that lives well up to its expectations on providing us with something apart from the documented portions and the stock examples supplied with the play distribution while providing insights into the activities covered and making them flexible enough to be used practically.
For anyone learning play framework and looking to go beyond the examples for making interesting and practical applications, I’d heartily recommend this book.

Wednesday, August 24, 2011

Up Next : Book review on Play framework

Today I received a copy of the book, 'Play Framework Cookbook' by Alexander Reelsen, courtesy its publisher, Packt Publications.




As the name suggests, it covers various recipes regarding the play framework, which is a promising rapid application development framework in java/scala platform.

This is the first instance of any good documentation of this upcoming framework for professionals and looks promising. I will be going over this book for the next few days and would be posting my views about it, stay tuned!

Friday, August 5, 2011

Need Concurrency ? LMAX to rescue!



In praise of LMAX.

Concurrency is a necessary evil beast in any application. Multicore architecture has ncessiated the use of programming for concurrency if there is a need for enhancing application performance.
Recently, on the martin fowler's blog, I came across an interesting architecture, LMAX which was used by in a financial application to run over 6 Million transaction simultaneously, over a single thread of execution only!
Even if this architecture is limited to finance domain, it makes up for an excellent solution for dealing with concurrency. With its single point of handling of the business logic processing there might seem a potential bottleneck, but is negated via alternative mechanisms to recreate this controller - Event Sourcing.
The concept of in-memory solution for performance is not new, but having concurrency  without the taxing side effects of transactions is indeed interesting.
I'll be doing some more study through it during this weekend, and update here if necessary.

Links :

Saturday, June 25, 2011

The curious case of multithreading Sqlite

In a recent project, I've embarked upon the process of saving information in a quick and lightweight manner for which the serverless database, sqlite was ideal. This is not only a flexible database supporting dynamic data types, but also an extendible one used from embedded web browsers and mobile platforms to rails based websites(good riddiance, mysql) .The database is so lightweight that you'll find yourself exclaiming it as db. It is less than 100 kb in some cases and can be used as a memory resident database for the performance conscious folks and applications.
However, the support of transactions and scalability leave a lot to desire as the documentation cleary states the goals of this database is not these.
In my case, getting started was just the matter of finding the jdbc driver and it s documentation from its website. However, upon customization, there was a need for normalization which in turn required a sequential read/write operations. As soon as this was done, the multi-threaded application that was accessing started experiencing concurrency issues around the database.
This was resolved via using a little used jni wrapper that I discovered, sqlite4java. This not only solved the concurrency issues, but also enabled transactions. The beauty of this approach is also the fact that it uses a single connection as opposed to a pooled/fresh connection per every request, which tends to be a real performance bottleneck as we scale up our application.

For such a nice framework, it is a surprise that these changes have not permeated to the java/native jdbc drivers so far and the users have to cope up with its api at the moment. This could be probably because of its tight integration with the underlying C-based api that is quite performant as compared to its
alternatives in python and java, effectively making it non compliant with the jdbc specification.

As the single connection served entire applications, exposing it as a singleton was the easiest approach :


static SQLiteQueue queue = new SQLiteQueue(new File("BiddingsDB"));

static {
queue.start();
}

For providing a transaction-like support, there was a need to wrap the existing operations in this queue :

public static void databaseInsert(final List list) { queue.execute(new SQLiteJob() { @Override protected Integer job(SQLiteConnection arg0) throws Throwable { insert(bidders, arg0); return null; }}); } The insert method performs the actual reads and writes in a row in a non-blocking manner which earlier used to cause locking problems with sqlite in the past. Integration tests verified this performance gains (recollections): DB insert (Read + Multiple writes in the operation) 1 Record  : ~200 ms 2 s 100 Records : 5s 10s 10000 Records : Fail ~100s As an afterthought, you can have a plain vanilla solution via the scraperwiki.com that not only gives you free cloud access for your scripts, but also its data via sqlite.  This aptly highlights the difference in the mindsets of java as well as scripting developers. Here, I was able to run a rudimentary scraper in a matter of minutes but was of no use for my client due to the gathering restrictions of the running jobs there. Hopefully, we get to see some mixing of both the worlds in the near future as scripting for jvm has been making a lot of noise for the past 3 years, but not much efforts have been made by the two sides so far. Oh, and I am really enjoying the rainy weather as I write this post!

Saturday, April 23, 2011

PC Gaming on Linux

Many people consider Linux as a serious OS for computing, but there is a fun aspect to it that is not really known as there is no marketing done for these games. However, for a moderate gamer, linux platform is satisfying especially if you are looking for playing games for your amusement without going too heavy on your wallet. Linux has also improved on the UI front considerably as now we can have some seriously GPU intensive graphics through out of box programs like compiz.
Cool 3D Desktop with Compiz
Those looking for a quick solution can use http://live.linux-gamers.net that allows you to create and start gaming from the live CD/USB directly.

In addition to the point and click games(like card based games),  you can have some serious fun with 3D games that PC gamers have become familiar with. Be it a fast paced action game like AssaultCube or a racing game like TuxKart, there are options for everyone.
TuxKart  : Funny racing game
AssaultCube : Fast paced action, a la Quake3 style

Thanks to ID software's initiative of providing a linux binary(and their stand on DirectX framework), we can install and play a game like DOOM3 on Linux http://sites.google.com/site/lgmscripts/scripts/games/doom-3 (which is definitively on my TODO list:)

There are certain caveats to this excercise too. Since my laptop has a Nvidia GeForce 8200MG card, I had to use a non open source binary driver as the cannonical one was not working well on Ubuntu. If you consider the freedom and the non presence of any cost/license, it forms a good overall personal entertainment package.