Friday, May 27, 2011

i7's Turbo-Boost in Action

The following steps in Ubuntu Natty show turbo-boost in action on my new laptop, which is quadcore 2.0GHz, boost-able to 2.8/2.9GHz:-

sudo apt-get install acpidump
sudo modprobe msr
sudo turbostat

Turbostat shows the following stat while my laptop is not doing heavy thing:-

avg 0.80 2.00
0 0.80 2.00
1 0.80 2.00
2 0.80 2.00
3 0.80 2.00
4 0.81 2.00
5 0.80 2.00
6 0.80 2.00
7 0.80 2.00

Let's make the processor's cores busy, open another terminal and enter:-

while :; do :; done

Now the stat shows:-

avg 2.86 2.00
0 2.77 2.00
1 2.87 2.00
2 2.70 2.00
3 2.74 2.00
4 2.77 2.00
5 2.81 2.00
6 2.76 2.00
7 2.77 2.00

Cores are working hard, enjoy!

Sunday, May 8, 2011

Learning Scala - Code Update without Redeployment via JRebel

Scala Developer entitles to free license from JRebel, just request it from ZeroTurnaround (, the license will be emailed to you in minutes. You'll need to download and install JRebel as well.

Having done so, you are only 2 steps away from code update without redeployment.

Step 1
Changed your sbt launch script, I have changed mine to:-

java -Xmx1512M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=512m -noverify -javaagent:/opt/ZeroTurnaround/JRebel/jrebel.jar -jar /opt/sbt/sbt-launch-0.7.5.jar "$@"

Note that I installed my sbt jar in /opt/sbt/ and JRebel in /opt/ZeroTurnaround/JRebel/.

Step 2
Change your Web Project build class:-

import sbt._
class WebAppBuild(info: ProjectInfo) extends DefaultWebProject(info) {

val jetty6 = "org.mortbay.jetty" % "jetty" % "6.1.14" % "test"
val servletApi = "javax.servlet" % "servlet-api" % "2.5"

override def jettyWebappPath = webappPath
override def scanDirectories = Nil

That's all for the setup, now you can launch sbt in your project directory and test:-

~ prepare-webapp

Go ahead and change your Servlet source file, upon saving, you can refresh your web browser to see your changes immediately, without the need to redeploy the whole web app.

Learning Scala - Continuous Redeployment with jetty-run

To make jetty-run to auto-detect and redeploy the web app, run the following commands in sbt:-

~ prepare-webapp

Now you can change your servlet source code and save, the web app should get compiled and redeployed automatcally.

Saturday, May 7, 2011

Learning Scala : Hello World Web App with SBT

Creating Project:-

mkdir HelloWorld
cd HelloWorld

You will be prompted to create new project, type 'y' and enter project name, organization, version etc.:-

Name: HelloWorld
Organization: QQ Enterprise
Version [1.0]:
Scala version [2.8.1]:
sbt version [0.7.5]:

Required Scala libraries will be downloaded automatically, make sure you are connected to internet.

Create WebAppBuild.scala build in project/build/ (create build directory if it's not there):-

import sbt._
class WebAppBuild(info: ProjectInfo) extends DefaultWebProject(info) {
val jetty6 = "org.mortbay.jetty" % "jetty" % "6.1.14" % "test"
val servletApi = "javax.servlet" % "servlet-api" % "2.5"

In the SBT console, enter:-


Create HelloWorldServlet.scala in src/main/scala directory:-

import javax.servlet.http._
class HelloWorldServlet extends HttpServlet {
override def doGet(req: HttpServletRequest, resp: HttpServletResponse) = {
resp.getWriter().print("Hello World!")

Create webapp directory in src/main, and consequently create WEB-INF directory and web.xml:-

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"



In SBT, run:-


Open your web browser and go to http://localhost:8080, you should see the Hello World! message being print out from your simple servlet written in Scala.