Sunday, July 14, 2013

Java 7 vs Groovy 2.1 Performance Comparison

I haven't used Groovy for 2 years, since my last touch with Grails. I get stuck in (hard)core Enterprise Java, with some performance aspects in background. I've almost missed a chance to learn Spock, but fortunately Warsaw Java User Group helped me to snap out of some legacy systems and back to normal self-development. In fact I hope that frameworks such as Spock or Geb will change approach to writing tests, by making them easier and more effective. Both frameworks use Groovy, as well as the new king in build tools - Gradle. Seeing pace how Groovy impacts our daily routines I decided to look closer at its performance, and compare it to Java 7.

My test environment is based on Java 1.7.0_25 and Groovy 2.1.6. As always in such comparisons I used Caliper in version 1.0-beta-1 (almost stable) and prepared a number of (I hope) representative microbenchmarks.

First benchmark based on Fork/Join framework should be most similar in both languages, because it uses some native mechanisms. My test initialize array with some random int data, and then use framework to find biggest element in array. In Groovy my compute functions looks like below:
Integer compute() {
  def size = end - start
  if (size == 1) {
    Math.max(array[start], array[end])
  } else {
    int diff = size / 2
    MaxValueSeeker left = 
      new MaxValueSeeker(array, start, start + diff)
    MaxValueSeeker right = 
      new MaxValueSeeker(array, start + diff, end)
    Math.max(right.compute(), left.join())
Java version is of course very similar. After dozen minutes of measuring I get very promising result: Groovy is slower only... 8 times :)

Saturday, July 13, 2013

Confitura 2013 - first time on the other side

I used to attend Confitura (formerly Javarsovia) or at least watch videos from presentations. I even had a chance to speak on it 4 years ago and share my reflections about continuous integration. This year I also decided to try to organize myself and prepare presentation about profiling Java Virtual Machine. Few days after submitting abstract, my chat window blinks with Tomek Dziurko saying:
 - "Hello! Confitura Organisation Commitee would like to invite you to join us. We don't give anything in return except satisfaction, but we take a lot of time. Are you in?"
Of course it's great honor but also we've to remember that with great power comes great responsibility :) Finally after exchanging a few words I've decided to accept challenge and put my shoulder to the wheel! Now I can say that it was definitely great decision! Guys - if you're reading this post please know, that working with you is a huge delight!

But I'm not going to sum up months of preparations and thousands of emails right now - I just want to share my feedback about conference.

Saturday, 6th July started for me at 6am, when I arrived at Warsaw University campus. We made finishing touch, provide some help for sponsors working on theirs booths and about eight o'clock first attendees appeared. Volunteers did really great job unloading registration queues (and also in many different things, helping us through whole conference). We've no more to do except get our aprons on, take big pot full of prizes and go straight for biggest lecture hall to open today's event! It was really, really nice to see so many geeks spending theirs free time to develop skills and help us making Confitura so unique conference!

Sunday, July 7, 2013

Using HA Singleton in JBoss 7

Some time ago I had to change standard clustering behavior of Quartz Scheduler, and let it work without synchronizing over database. There are of course a lot of options to do that, but because I'm big fan of simplicity I've decided to use standard Spring @Scheduled configuration and totally skip thinking about cluster at this level. The idea was to just invoke "check that I'm on master node" method at the beginning of the scheduled method. The only problem was how to write such method :) The choice was to use JBoss HA Singleton functionality. It's available in JBoss 7.x but the big lack of documentation forces some experiments... nice!

First thing which we need to do is to provide proper dependency, containing few important classes. Of course remember about right version (here I'm using 7.1.1.Final because it's available in public repositories and all next versions of 7 needs to be build manually).
Now it's time to do some coding! Let's start from class containing service that will be installed into application server. Its role is to set master status flag and expose it by simple static method.