Archive
CloudBees talk at the ElsassJug
Yesterday night, Sacha Labourey came to the Elsass Jug to introduce CloudBees.
It was pretty nice to see Sacha IRL: he’s a very friendly and humble person (while being, for those not knowing him, creator and CEO of CloudBees after quite a career). It’s really easy and interesting to speak with him so go and get him whenever you need/can.
CloudBees specializes in using the clouds resources and tools for developing and running Java (web) applications (Platform As A Service way). It’s what they call their Dev@Cloud and Run@Cloud.
Having Koshuke among their staff, the whole stack is centered around Jenkins: if you use it, then you’ll be like at home. Actually, you’ll be most likely better than at home: their jenkins come with slaves running each job (infinite scaling FTW) as well as the usual plugins plus some on top from third parties.
Roughly put, it’s a nicely already set up Jenkins environment, with some goodies like remote console line tools or Eclipse plugins. To me it really felt like all the tools you wanted to use with Jenkins but already there and waiting for you (like having slaves running the jobs to avoid bottlenecks).
The Run@Cloud part is also interesting: basically, once your jenkins jobs are done, you can decide to promote some to production. They are then deployed to your web apps. The web apps location(s) are pretty flexible: they can either host them (if I got it right), put them in some well known hoisters or, in fact, any cloud (as long as openstack compatible). Actually, it’s not only about web apps, they can also handle DBs (mysql only AFAIK).
One option I wasn’t aware of is that the deployment part can also be building images (VSphere ones, so VMWare) and push these images wherever you want. In line with their concept, looks like they handle the OS and stack parts of these images: you just have to put in your WAR file and you’re done. Sweet isn’t it?
For sure, they’ve plenty of goodies not spoken of here: they can have webdav based maven repos (you can also rent on top some artifactory), the monitoring tools for the running apps look great (again, the fancy tools you heard of but never bothered to actually put in use are available here) and so forth.
To sum up, they really aim on doing the "devops" part of development, so developers can concentrate on… developing. Not too bad isn’t it? In terms of target, they have pay as you go pricing and others one for bigger users.
One example Sacha put forward to showcase the whole concept is Loose It. Loose It is a mobile/web app helping you to loose weight. The interesting part there is that they’re only 5 developers and they’re able to deliver 1.5 millions users and up to 20 000 transactions per minutes. All this without scaling issues and dedicated staff. Just 5 devs in the wild. Well, for sure, I guess they owe CloudBees some money, but obviously only a fraction of what it would have costed them to handle it all on their own.
My thought being put to words, I’m off
++
joseph
Side note: in case you wonder why this post is in english, it’s pretty straightforward: I wanted this dear uwe to be able to be able to read it, since his company looks like the perfect fit for CloudBees and… I would be eager to have some first hand feedback. Nasty me? You bet ![]()
BTW, thanks uwe for proof reading this post.
Multithreaded performance testing checklist
In the past months we did some performance testing at work, making quite some mistakes on the way, and probably still doing some. In between, I’ve read "Java Concurrency in practice", by Brian Goetz, and learned once again some more goodies. As such, I’ve written this quick checklist, in order to forget less next time I’ll try to do some performance testing.
As usual, let me know of any mistake, lack or questions.
before starting the test
- check your issue still with the latest JVM to make sure the trouble still exists.
- use the latest JVM: java.util.concurrent had some great improvements in Java 6. Furthermore the various JVM options are more complete (includes display of Lock and its sub classes locking state).
while coding the test
- mind locking in utilities libraries. For example UUID.randomUUID() uses SecureRandom, which is thread safe… Prefer less secure random value generators which don’t imply locking, like System.nanoTime().
- measure time before and after all threads/tests, dividing it as needed, instead of many small measurements (less impacts on the tested code).
- do unpredictable stuff: the JVM is very good at optimizing out code whose result can be guessed, like by pre computing it once and for all. For example, compare some hashCode() with System.nanoTime(), printing out something in (highly unlikely) case of equality.
- do production representative work: the JVM always tries to optimize the code. It can take shortcuts which became invalids with further class loading. Restricting yourself to few classes increase the risk of optimization which won’t happen in production.
test launch set up
-
Be as close from production as possible
- mind the -server option, which has important effects.
- define your memory using -Xms and -Xmx (see java -X for more information).
-
setup runtime information display
-
add -verbose:gc to see garbage collection.
By default, 2 types of garbage collection exist:-
minor ones (iterative), which garbages out the low hanging fruits. Quite frequent, these ones don’t affect performance too much. A typical minor collection is displayed this way in the console:
[GC 325407K->83000K(776768K), 0.2300771 secs]
It shows the decrease in memory consumption and the time it took to get rid of this memory. -
"stop the world" garbage collection. Nothing else happens during these majors garbage collections, hence the stopping world name. As such, it’s a really performance hit: plan your test to run long enough to streamline its effects.
A stop the world collection is shown this way in the console:
[Full GC 267628K->83769K(776768K), 1.8479984 secs]
more options exist to monitor garbage collection, for example -XX:+PrintGCDetails. See Java HotSpot VM Options
and Tuning Garbage Collection with the 5.0 Java[tm] Virtual Machine. -
minor ones (iterative), which garbages out the low hanging fruits. Quite frequent, these ones don’t affect performance too much. A typical minor collection is displayed this way in the console:
-
add -XX:-PrintCompilation to see the JVM compiling bytecode to assembler code where it sees it fits.
- have accordingly a "warm up" period when running your test, to put this compilation out of the tested code.
-
add -verbose:gc to see garbage collection.
while running the test
-
look at what’s going on in the JVM
- use jps to locate the test process.
-
use jstack to see the current stack.
- triggered frequently it gives a very nice overview of what the program is doing most of the time.
- displays information about lock held, waiting and deadlocking threads. More about it there Detecting Java Thread Deadlocks with ‘jstack’.
-
monitor your system
- what about the network traffic. Is the application network bound?
- what about CPU usage: a properly multi threaded software should make good use of them all.
- what about RAM, before starting and while running. Swapping shouldn’t be used normally.
- Be patient: the test should run some minutes to be conclusive…
all this time: test your intuitions/assumptions/known facts
- Surprises are lurking all over the place.
- Facts of yesterday are today’s illusions!
That’s all for now folks!
Book: Implementations Patterns
In Implementations Patterns, Kent Beck focuses on "low level" advices. It’s all about how to write nice, readable and maintainable code.
Such a narrow focus is good and provides a nice occasion to think on one own’s habits.The extensive thinking put down in the book quite often put words on feelings/intuitions one can have while coding. It makes them explicit/obvious and helps to think more rationally about them. It also put new light on different aspects, widening the comprehension.
The chapter "Theory of Programming" is also pretty nice, esp. when addressing flexibility. Indeed, flexibility is about being able to change easily the code, not providing the user with hooks all over the place to change everything in the software. Insisting on code readability is also always welcomed and well put in perspective. It somehow managed to feel more convincing than previous readings I had on the topic.
Yet it isn’t all nice in Implementations Patterns. The term pattern feels often overstretched. Kent Beck is mainly just browsing through the available options in Java and discussing their pro and cons. Sometimes it feels obvious and a bit overdone.
The chapter on collection performance feels also a bit like "space filling" rather than helping achieving the book goal. A nasty voice inside of me can’t help noticing that for a 129pages yet 45$ book, it’s comprehensible…
A point has also really surprised me: Kent Beck speaks of final fields and says he usually doesn’t bother writing the final keyword. He would only if his code would be changed by many people. Not only it’s contradict his main motto of communication to the readers, but it’s actually a big hole in the class, both in terms of performance and maintenance… Crazy it managed to go through the editing process IMHO.
To conclude, the book is helpful and hopefully my coworkers will appreciate its effects on my code. I’ve more tools/knowledge/options to write readable code, I just have to make good use of them by now… Is it a must read ? Dunno. Maybe I start to have read quite a bunch of such books to have a feeling of "deja vu". Surely as well I’m getting older. Anyway, it was a good read, I recommend it. Whether it’s a must read is left to the reader as an exercise
Side note: for a deeper look at the book content, there’s this infoq review Book Review: Implementation Patterns which shows it well.
Wicket et ses fonctionnalités de templating
[This note is also available in English.]
Wicket fournit des fonctionnalités de templating. Rien de bien folichon, mais c’est tout de même bien pratique, surtout quand il faut intégrer du JavaScript.
Ces fonctionnalités sont cependant très peu discutées voir même, je suspecte, globalement inconnues. Aussi, creusons un peu la chose!
Comme tout système de templating, tout tourne autour de texte contenant des variables, définies par ${variable} et dont les valeurs sont données via Java.
Voyons un exemple simple, un fichier de template nommé javascript.tpl:
alert('${variable}');
Wicket permet d’aisément accéder à ces templates en tant que ressources mises dans des packages Java, via la classe PackagedTextTemplate:
public PackagedTextTemplate(final Class clazz, final String fileName)
Par exemple:
PackagedTextTemplate jsTemplate = new PackagedTextTemplate(this.getClass(), "javascript.tpl");
Ainsi, le template se trouve à côté de la classe Java et de l’html l’utilisant, rendant le tout aisé d’utilisation.
Les variables sont fournies au moyen d’une simple Map:
Map parameters = new HashMap();
parameters.put("variable","test working");
Au final ce template trônera certainement au milieu d’html. Aussi Wicket fournit plusieurs options pour cela:
- contribution au header html:
add(TextTemplateHeaderContributor.forJavaScript(jsTemplate, new Model((Serializable) parameters)));
- accolé à des éléments du body html:
Java:Label myScript = new Label("myScript", new JavaScriptTemplate(jsTemplate).asString(parameters)); myScript.setEscapeModelStrings(false); add(myScript);Html :
<wicket:container wicket:id="myScript"></wicket:container>
Vous avez sans doute remarqué que, dans chacun des cas, je ne fournis pas le tag qui devrait entourer le tout. Pas d’inquiétude à avoir, Wicket le fait pour vous.
L’html résultant est en effet:
<script type="text/javascript"><!--/*--><![CDATA[/*><!--*/
alert('test working');
/*-->]]>*/</script>
Si le template contenait plutôt du CSS, il faut juste utiliser un CssTemplate au lieu du JavaScriptTemplate.
Quelques info supplémentaires sont disponibles sur le wiki wicket: Including CSS resources.
++
joseph
Certification, part 2 ;)
hi
Small post to tell that I’ve started to look into SCJD, another certification. As such, I fear I will once again post way less (in case anyone cared, which might be quite optimistic, yes I know, thanks
).
Anyway, not to do a totally useless entry, let’s share a few links :
- a nice reference diagrams about design patterns. For once a design patterns reference one can finish before falling asleep ^^
- a nice recap of sql joins (provided, surprise !, by our dear admin)
- if ever you (too) stumbled upon Hibernate not escaping tables’ and columns’ names when creating the database, some explanations and work around: Escaping database column name when using Hibernate
- to finish on a lighter note, for clueless foreigners working in Germany, some info about the Bielefled conspiracy.Hopefully the blog won’t be taken down !
see ya !
++
Book review : SCJP Sun Certified Programmer for Java 6 Study Guide
In order to get ready for the SCJP 6 exam, I’ve read SCJP Sun Certified Programmer for Java 6 Study Guide, from Katherine Sierra and Bert Bates, aka some of the certification’s exam creators.
The authors make clear at the beginning that the book is about, and only about, being ready for the SCJP exam. No more, no less. And they keep to their words : the book is strictly focused on the exam.
The bad consequence is that sometime (often) I was eager to know more, to go further the "there’s plenty more to tell, but that’s enough for the exam, so we stop here". Furthermore, as you can imagine, this isn’t the most fancy book I’ve ever read. Katherine and Bert do attempt a few times to instil some fun, but it didn’t fall quite right.
The very good side is that the book teaches all you need to know, no more, no less. I would even go a bit further : if the authors say "methods X and Y are also part of the exam", then you should really know exactly what’s in these methods. I’m pretty sure I lost some points due to some API I didn’t know enough. Even better, they say clearly what’s in the exam and not. No need to worry because some dumb mock exams found on the web put stuff you hadn’t any clue off. If it wasn’t in the book, it’s not on the exam.
Even more important, the writers are very good at explanations. Really, they know out to make things clear. Awesome. I now have a grip on regexp. Really !
To conclude, this book is really one (if not the one – I haven’t read the others so it’s hard to tell) to go for when preparing SCJP 6, no more, no less. At least it was for me!
++
EDIT : did a bit of clean-up
Playing with Wicket’s templates
[Ce billet est également disponible en français.]
Wicket comes with some templating facilities. Nothing fancy, but still they’re quite handy, especially when integrating JavaScript components.
These functionalities aren’t much advertised and I would say even quite unknown. So, let’s dig in !
Basically, this templating is about some text containing variables, for example ${variable}, whose values are provided through Java code.
Let’s take a simple example, a template file named javascript.tpl containing :
alert('${variable}');
Wicket is nice enough to provide an easy to access the templates as package resources, through the PackagedTextTemplate class :
public PackagedTextTemplate(final Class clazz, final String fileName)
For example :
PackagedTextTemplate jsTemplate = new PackagedTextTemplate(this.getClass(), "javascript.tpl");
Thus the template can be next to the .html page and the Java class using it, making the whole quite cohesive.
Providing the variables is done through a simple Map :
Map parameters = new HashMap();
parameters.put("variable","test working");
And then, you most probably want to include this template in some html. Wicket provides you different options :
- as an header contribution :
add(TextTemplateHeaderContributor.forJavaScript(jsTemplate, new Model((Serializable) parameters)));
- directly next to some element in the html file:
Java side :Label myScript = new Label("myScript", new JavaScriptTemplate(jsTemplate).asString(parameters)); myScript.setEscapeModelStrings(false); add(myScript);Html side :
<wicket:container wicket:id="myScript"></wicket:container>
You may have noticed that, in both cases, I didn’t provided the surrounding script tag (and the appropriate inner wrapping). Fear not, Wicket does it for you !
Indeed, the rendered html is :
<script type="text/javascript"><!--/*--><![CDATA[/*><!--*/
alert('test working');
/*-->]]>*/</script>
If the template was about some CSS stuff, one would just need to wrap it using a CssTemplate instead of the JavaScriptTemplate.
A bit more info are available there Including CSS resources.
++
joseph
m2eclipse workspace resolution not working ?
We have this "fix":
- Go to your workspace folder
- in the folder .metadata/.plugins/org.maven.ide.eclipse, remove all file ending with .container
- in eclipse, clear all projects
- hope for the best
For us, it has resolved a nasty issue we had : some projects’ dependencies weren’t resolved locally even if the projects in question were in the workspace.
Hope it helps
++
Fun with Java's syntax !
Have you ever prepared a certification ?
Well, for me, it’s the first time, and it proves a very nice occasion to learn stuff you should never do and hopefully will never meet in real code. Still, it’s fun like hell
So, what am I speaking about ?
Well, stuff like these :
class ExtractsFromTheExams
{
int[] array[]; // such a nice array declaration
String fooArray[] = new String[]
{ "a", "b", }; // yes, this last comma is fine
String bla = new String[]
{ "foo", "bar", }[1]; // seen in some tests...
Object a\u0001; // readable like hell
}
public class A // some sample class are very clear
{
public transient String foo;
Bar aBar = new Bar(10);
static Integer nb = 10;
public static void main(final String[] args)
{
A a1 = new A();
a1.nb++;
A a2 = a1;
a1.nb = 0;
System.out.println(++a2.nb);// BTW : what to expect from it ? Will
// this class even compile ?
}
class Bar
{
public Bar(final int i)
{
// TODO
}
}
}
class Huh{
char A = '\u000A' ;// this one for the end. Try compiling it...
}
Well, don’t understand me wrong, I appreciate working on this certification. Really. The unclear samples are made to make the reader think twice… And I’m pretty sure anyone having tried to figure out these lines above will have read some of them twice. Furthermore, it’s funky only from time to time, it can also be interesting. Overall, this in depth exploration of Java is valuable, even if mostly on corner cases.
++
Wanted : book/resources on Java certifications !
I’m currently looking seriously at some Java certifications. As such, Uwe kindly gave me lots of Java certification books, but they are about Java 1.2 (whaou, prehistory
) and 1.4.
Since Java 5 introduced quite some new stuff, extra resources/books would be welcome, as such feel free to comment. I’ll as well update this post with my own findings, even if I already have enough to learn with all these funky bit operators and the like… Funny how little I saw them used BTW… "Wondering about the use case am I !" (yes I played Stars War Lego recently
)
++
EDIT : For some mock tests, Javaranch is the way to go, as they provide some lists of mock test sites.
For books, uwe sent me this very usefull link (thanks by the way !): Javabooks timeline. But in the end, I settled for SCJP Sun Certified Programmer for Java 6 Exam 310-065 which I didn’t find in the Javabooks site.
Anyway, I’m eager to get the book, since certification looks like more useful than I previously thought, in terms of Java mastering and understanding. It really helps to go deeper into it.
EDIT – follow up some interesting links for certifications wanna be :
- JavaRanch SCJP faq
- Java keywords… special mention for true, false and null !
- regex quantifiers…
- explanations on the String pool
Digging in !
++ (re)
EDIT : this quest is now over. Thanks all