Tuesday, 17 January 2012
jqPlot, IE7, dateAxisRendering and "Object doesn't support property or method 'getTime'"
Friday, 22 April 2011
Another simplistic Groovy and Java comparison
The webapp is a Groovy web app using Spring (not grails) and is backed by the most excellent mongodb.
So, firing up jprofiler and just hydrating a bunch of items that would appear on the home page showed it took 903 seconds to load 7143 items. Wow - too slow. Looking at the netIO threads shows that only 16.5 seconds are spent waiting for Mongo. Considering there are hundeds of thousands of lookups (each item is pretty large and has many associations), I was pleasantly surprised.
This unfortunately meant the cost was in my code :) shucks.
The cpuview in jprofiler didn't really point out any obvious candidates (i.e. the time was spread equally amongst lots of methods).
The code itself is written in groovy and uses a lot of closures and method calls. I thought I would run a little experiment myself to see exactly how much this costs. Turns out that it costs *a lot*.
The experiment basically called a gazillion loops, which is pretty similar to the code I am profiling. The performance code:
package sandbox.performance;
public class TestPerformance {
private static final int ITERATIONS = 1000000;
public static void main(String[] args) {
long groovyDuration = testGroovy();
long javaDuration = testJava();
System.out.println("Groovy: " + groovyDuration + ", java: " + javaDuration);
}
private static long testJava() {
JavaClass counter = new JavaClass();
long start = System.currentTimeMillis();
for (int i=0; i
counter.callPlusOneTenTimesTenTimes();
}
long end = System.currentTimeMillis();
return end - start;
}
private static long testGroovy() {
GroovyClass counter = new GroovyClass();
long start = System.currentTimeMillis();
for (int i=0; i
counter.callPlusOneTenTimesTenTimes();
}
long end = System.currentTimeMillis();
return end - start;
}
}
JavaClass:
package sandbox.performance;
class JavaClass {
int callPlusOneTenTimesTenTimes() {
int total = 0;
for (int i = 0; i < 10; i++) {
total += callPlusOneTenTimes();
}
return total;
}
int callPlusOneTenTimes() {
int total = 0;
for (int i = 0; i < 10; i++) {
total += plusOne(i);
}
return total;
}
int plusOne(int x) {
return x + 1;
}
}
GroovyClass:
package sandbox.performance
class GroovyClass {
int callPlusOneTenTimesTenTimes() {
int total = 0
0..10.each { total += callPlusOneTenTimes()}
total
}
int callPlusOneTenTimes() {
int total = 0
0..10.each { int x -> total += plusOne(x)}
total
}
int plusOne(int x) {
x + 1
}
}
(I wish I could figure out the tags for code!)
The results were pretty terrifying: Groovy: 1759, java: 4
Wow - groovy is 439.75 times slower!!!
(This is running on ubuntu 11.04 with sun-java6-jdk and groovy-1.7.5)
And whilst this test is pretty simple it turns out to be pretty similar to the production
code. Time to rewrite it in Java I guess!
Wednesday, 23 March 2011
First, if you are a Java programmer you really need to get hold of http://www.ej-technologies.com/products/jprofiler/overview.html!
Long story short, I profiled a long running application thinking I knew exactly where the performance penalty was - it wasn't anywhere near there :) It was in the equals() method of a groovy class which was implemented as:
boolean equals(Object other) {
other instanceof ThisClass && other.hashCode().equals(other.hashCode())
}
hashCode:
int hashCode() {
this.name ? name.hashCode() : 0
}
(This class had a single property which was a String and set in the constructor so I could easily cache the hashCode) but flip me, who knew this would be a bottleneck accounting for 17% of the CPU time. OK, it was called over 3 million times, but still....
The solution? I don't know if it is the cost of groovy or what, but my first call is to cache the hashCode and reference that in the hashCode and equals method. Run the profiler and see if that helped. Second step will be to re-implement in Java and see if that helps....
Long story
There was a Java/Groovy based app which used Hibernate and SQL Server which I migrated to use MongoDB. The app had some non-trivial complex hierarchies which were a pain to store in a relational DB but trivial to store in a document DB. There was an obvious aggregate root for the data structure so the conversion was very straight forward.
The application was fantastically quick for loading a single document but the user's home page displays all their active documents, of which there might be hundreds. The SQL server application uses a denormalised summary table which condenses each document into a single row so that is lightening quick but the mongo app was really slow.
Given that hibernate has a first level cache *and* given that the documents have lots of references *and* given that MongoDB has no such first level cache you might follow my line of thinking that the performance cost was in Mongo loading each referenced object over and over again.
Like me, you would be wrong :)
Lesson of the day - use jprofiler - it just might surprise you!
Monday, 21 March 2011
I wanted to move vcenter to a virtual machine running on one of the ESXi hosts that it was managing. Chicken and egg huh :) but this is actually a supported configuration.
So I removed all the hosts, shutdown vCenter, created the new virtual machine, installed vCenter and tried to add the first host and received a very cryptic 'You do not hold privilege "System > View" on folder ""'.
Hmmm....
Turns out it because I chose to turn on "Lockdown" mode on all the hosts which restricts who can administer them. Logging in via iLO to the host itself and disabling lockdown in the VMware console does the trick.
Thursday, 17 March 2011
This is the second part - please read part 1.
I don't care about synthetic tests like bonnie++ or dd if=/dev/zero etc. I am only interested in finding out which configuration runs my test the fastest.
However, it is nice to see the difference :) so these are the results of copying an 18GB file into each of the three configurations:
(recall, first config is XFS partition on single disk, second is RAID0 XFS and third is RAID1 XFS).
(Copying from the non-raid partition into a non-raid partition on the second disk)
time `dd if=test of=/data/singleb/test bs=1M ; sync`
18267+1 records in
18267+1 records out
19155058688 bytes (19 GB) copied, 164.756 s, 116 MB/s
real 2m52.385s
user 0m0.030s
sys 0m26.490s
(Copying from the non-raid partition into the RAID0 partition)
time `dd if=test of=/data/raid0/test bs=1M ; sync`
18267+1 records in
18267+1 records out
19155058688 bytes (19 GB) copied, 266.782 s, 71.8 MB/s
real 4m28.422s
user 0m0.010s
sys 0m27.840s
(Copying from the non-raid partition into the RAID0 partition)
time `dd if=test of=/data/raid1/test bs=1M ; sync`
18267+1 records in
18267+1 records out
19155058688 bytes (19 GB) copied, 400.644 s, 47.8 MB/s
real 6m47.905s
user 0m0.050s
sys 0m26.620s
Copying from one disk to another is the fastest, followed by RAID0 then RAID1. You might have expected RAID0 to be the fastest but recall that the 18GB file is being copied from a parition on the same disk so one of the disks in RAID0 (and RAID1) will be involved in reading as well as writing, hence the slow down.
OK, since I opened this door, maybe a fairer (but still meaningless :)) test would be to use dd if=/dev/zero so the disks are purely available for writing..... Results of that silly test (time `dd if=/dev/zero of=18G bs=1M count=18000; sync`) are:
single disk:
18000+0 records in
18000+0 records out
18874368000 bytes (19 GB) copied, 156.651 s, 120 MB/s
real 2m43.003s
user 0m0.040s
sys 0m16.760s
raid0:
18000+0 records in
18000+0 records out
18874368000 bytes (19 GB) copied, 82.0213 s, 230 MB/s
real 1m25.195s
user 0m0.030s
sys 0m16.800s
raid1:
18000+0 records in
18000+0 records out
18874368000 bytes (19 GB) copied, 189 s, 99.9 MB/s
real 3m16.593s
user 0m0.040s
sys 0m17.110s
All of this is meaningless really - the copy from one disk to another is probably the closest to the performance you will get in real life. Whilst RAID0 flies for a long sequential write it slows down significantly when it has to be read from as well - i.e. real life.
Based on this, I don't know whether it will be more performant to have the OS and one DB on disk1 and the second DB on disk2 or just both on RAID0... We shall see! :)
DISCLAIMER - RAID0 means losing all your data stored on that partition if *any* disk dies.
(part 1)
I need to run SQL Server in a VM on top of Linux (Ubuntu 10.10) using VirtualBox ('cause getting VMware Player running is just not worth it!).
I have two 640GB WS6402AAEX disks (fairly quick) and the OS is installed in a (software) 64 GB RAID1 partition.
In fact, to be clear:
- /dev/sda1 is 16GB SWAP
- /dev/sda2 is 64GB RAID1 (software)
- /dev/sdb1 is 16GB SWAP
- /dev/sdb2 is 64GB RAID1 (software)
The base machine is a quad core CPU i5 760 (2.80 GHz) with 16GB RAM (purchased from those great people at http://pcspecialist.co.uk/.
The question is, which is the best setup for virtualising SQL Server? My plan is to install a single Server 2008 64Bit VM with 12GB RAM (leaving 4 for the Ubuntu 10.10 host). That VM will have 48GB for the OS and 64GB for SQL Server data files. It will also have IntelliJ 8 (don't ask) configured to run a development job which sucks data from one database and sticks it in another database. The same configuration (using Windows 7) takes about an hour to run when installed directly onto the hardware.
I plan to test the following scenarios:
- guest OS on /dev/sda3 (XFS), data on /dev/sdb3 (XFS) i.e. no RAID
- guest OS and data on RAID 0 (XFS)
- guest OS and data on RAID 1 (XFS)
*remember* - the host OS is running on a RAID1 partition on the same disks.
part 2 will show some meaningless synthetic tests and part 3 will show the results of the real test.
Which file system to use for the OS? Quite simply, don't use XFS - use EXT (or whatever). Installing a minimal ubuntu server took absolute ages (hours) over XFS on RAID0 and RAID1.
Think about it - XFS *rocks* at large files but its weak spot is tiny files - what does an installation involve? Lots of small files.
Changing it to EXT4 and re-installing reduces it from hours to mere minutes (20 or so - I didn't time).
I will be using XFS for storing the virtual machines one though - for sure. Just not the OS.
(this isn't very interesting, but it is a test of a blogging client)
I find Linux really usable. I do a lot of work in a command line over ssh on lot of machines.
I also use XenServer (which requires windows)
I also do development with other developers using Git that *has* to have windows command lines.
So, up till now I have used Windows and putty, but it has always felt a bit lame - putty rocks, but it isn't the same as having a rich command line from which to launch ssh.
Cygwin didn't cut it for me because it runs inside the lame, crippled and just terrible terrible windows command box (whatever it is called).
Finally, I now have a box worth something (16GB RAM, two fast hard disks) which means I can run Windows inside a VM on top of Linux.
Yeah.
So, which distro to use? I really liked the look of kde 4.6, but I am a debian dude and I will never go near kubuntu. Ever. OpenSuSE seems to be the on-to-goto for KDE, so sure, let's give it a go.
Wow! This rocks - super speedy, YaST is infinitely better than it was 5 years ago. Everything just works.
Until it doesn't. After a few hours/days I noticed a few things just stopped working - the KDE panel at the bottom stretched beyond the edge of the monitor (I have a large and small monitor and the small one is the primary - I think it got a bit confused). The network icon was the last to go - sure, the network still worked but I don't want to see a red X. OK - easy enough to remove. Then I tried to sort out using my plugin-headset as the primary input and output. Phew - after trying to set it in three different places (!) I managed to get it to play sounds, but skype still didn't want to take the mic. Eventually, it worked, but don't ask me how.
I am looking for a desktop that *just works*, and the only one I know off that does that is debian. Debian squeeze has just been released so it isn't too stale (KDE 4.4.5 + upstream patches), so off to download that.
Wow - it flies! Install the NVIDIA driver - and lock up. Total lock up. I haven't got time for this.
Finally - Ubuntu - OK, means Gnome, but I am not so sure that is a bad thing after my recent play with KDE.
Wow - everything just works. I mean *everything*. It prompted me that I needed some "naughty" firmware, click the relevant button and off it goes. Ubuntu Software Center is pretty neat as well.
So, in conclusion - I am shocked. Ubuntu - you are my saviour - who would have thought.
Tuesday, 2 March 2010
When is a string not a string - when it is groovy :)
The keys are strings. Should be simple right?
The problem is that is you use groovy's excellent string facilities (i.e. "this is a string with a ${parameter}") then no, you don't have a java.lang.String you get a org.....GStringImpl.
The code that was inserting into the map was using this feature, the code that was retrieving it was using a plain java.lang.String. The solution was to cast the key to a string (actually no need to cast; String s = "this is a string with a ${parameter}" works fine).
Stupid that GStringImpl.equals doesn't take this into account.....
Thursday, 11 February 2010
Running pveperf from Proxmox on any distribution
So, off I go and install CentOS (aka poor man's RedHat) - if they don't support it properly then no-one will and I naturally typed 'pveperf'. pveperf is a lightweight performance profile tool that comes with Proxmox. Unfortunately it only comes with proxmox.
Unfortunately, it is the quickest way I know of how to find out the number of FSYNCS a second the drives will do, and that number is pretty critical for lots of virtual machines that wil be IO bound.
Anyway, turns out, pveperf is written in perl, so getting it working on any other machine is pretty trivial. Instructions here.
Wednesday, 10 February 2010
Virtualisation - it rocks!/what a nightmare!
Monday, 25 January 2010
Update on martial arts
- Monday - Jiu Jitsu (7.00-9.00)
- Tuesday - Thai Kickboxing and Jeet Kune Do (6.00-8.00)
- Thursday - Thai Kickboxing (6.00-7.00)
- Saturday - Thai Kickboxing and Jeet Kune Do (11.00-1.00)
Tuesday, 12 January 2010
Another Ju Jitsu review
- effective and accurate teaching
- it is true what they say about JJ - belts there are higher than equivalent belts in other arts
- nice social aspect to it
- level of detail was great
- investment in this class would pay dividends
- probably the least effective at increasing fitness - not a biggie, but to be noted
- I have *no* flexibility in my joints. I felt pain watching other people's locks :)
- going here removes a class from TKD and JKD making it very expensive
- grading is 3 monthly - although I am not sure I will progress faster
- do I really want to do this class? I think I do....
Friday, 8 January 2010
Review of Sahota's Taekwon-Do class
- cost is pretty good 25/month for 1 lesson or 49(?)/month for 2 or more. All gradings, insurance, association and your first gi are included!!!
- excellent teaching of the art form
- a grade from this place will be transferable, and therefore meaningful
- the main man is a 7th dan and his son (who I met today) has been doing it 20 odd years (no idea about his grade)
- it is a style that I find graceful and elegant
- the higher grades do do sparring
- they are quite renowned for their pattern work - which I like
- I think I could progress here quite quickly
- they maybe don't do enough sparring for me (although a weekly dose of UMA.com might satisfy that)
- they make me look like a complete beginner - I almost need to unlearn my previous techniques and start from scratch
- socially it isn't really my scene (mixed kids and adults - nobody my age)
- the beginner class is only 45 minutes long and it will probably take a while before I can join the senior class (if not because of technique then because of fitness, although it will be because of both!)
Tuesday, 5 January 2010
Review of urbanmartialarts.com
- excellent atmosphere
- high calibre of teaching
- passionate instructors who are there because they love it
- very mature martial arts school (in terms of the attitude of the instructors and students)
- real "street smarts" but with an art behind it
- will be fun getting fit
- familiar ground (or rather, I used to do this type of thing)
- made me realise how utterly unfit I am
- made me realise how much I had forgotten - I was pretty embarrassing - being beaten up by a 6 year old girl....OK, not that bad, but pretty bad
- I like the comfort of a strict belt structure - I want that false sense of security of a coloured belt :)
Monday, 4 January 2010
Review of Robert Phelps@Hinkley Ju Jitsu club
As indicated http://colinyates.blogspot.com/2010/01/returning-to-martial-arts.html I am looking for a decent (by my definition) school to study martial arts.
I have just returned from an hours training at Hinkley with Sensei Robert Phelps (http://www.leicesterjujitsu.co.uk/jujitsu_Training.asp) and thought I would give it a quick review.
First, let me state that this is a review against *my* criteria. If you are looking for a Ju Jitsu class then I would have no issue recommending it. Any negative assertions as related to what I am looking for, not ‘is this a good Ju Jitsu school’, to which the answer is yes!
The class is held in a school room with the standard blue break mats on the floor. There were about 10-12 (forgot to count :)) students (what are they called?) of differing ages and abilities. It was very friendly and laid back. Sensei Robert came over to chat to me and he was as friendly as his wife, who ran the ‘reception’.
The class started with the obligatory warmup and then Sensei Robert spent 5 minutes 1 on 1 with me going through basic breaks and rolls.
For the rest of the class I trained with three different people, two brown belts and one red belt. Both Sensei Robert and another black belt kept popping over to check on things when I was with the red belt. All of the training involved 1 on 1 in different scenarios, i.e. ‘if somebody is strangling you (by putting your hand here and here) then if you move your left hand over like this, and then your right hand over like that, and move your hips……..this happens. Now you try’. We went through 5 different moves using this teaching method.
So what do I think – I am undecided. It was a very comfortable and relaxed environment, and you could just tell that Sensei Robert knew his stuff. Watching the higher belts do their thing was quite inspiring. I just don’t know if it is what I am looking for. There was no teaching on the strikes at all – no bag work or patterns, it was all defensive. Also, the pace was a little slow – necessarily because it was all about the technique, but I didn’t really feel as if I had enough instruction. To me, there are two styles – ‘who cares about technique – hit them’ and ‘attention to detail – repeat this 1000 times’. If the style is in the second class, which Ju Jitsu clearly is, and should be, then I want to know exactly what I am doing right, wrong and how to improve it. Quite often I hear ‘well, we don’t want to discourage beginners’, but I am not really a beginner – I am there to learn, and if it is ‘technique heavy’ art, then I want to make sure my technique is excellent from the get go. Rather worryingly the red belt and even some of the brown belts didn’t exactly know either.
I am being harsh, and deliberately picking faults. Don’t misunderstand, I was impressed enough to consider going back – you really need to visit a place 3 or 4 times to get a genuine feel for it.
Pros:
- very safe and respectful – no egos that I could detect (although at 6 foot 2 and the wrong side of 18 stone I either put them off or encourage them ;))
- high skill level
- diverse age and skill range
- the man had some skillz
Cons:
- it is at least an hour round trip for a one hour lesson
- not enough ‘accuracy’ in the techniques that I could see (although I am being unfair as they thought I was a beginner)
- the second hour was for very high grades
- the grading takes a very long time – 3 months between grades, although I don’t know how rigid that is, or whether you can double up (grade for multiple belts at the same time), or whether you can skip a belt
- not enough rough and tumble for me
- this isn’t going to get me fit – the warm up had me breathing hard (yeah, I know :(), but the rest of the class required zero exertion
Have I ruled out Ju Jitsu? Not necessarily – if I could find somewhere that focused on the strikes as well with some sparing, then great. Have I ruled out this club? Not at all – I may well go back for another 3 or 4 weeks just to ‘give it a chance’.
As I said to my wife – if I could zip forward 3 or 4 years to when I receive my black belt in Ju Jitsu I would be ecstatic – I really want to do it, the problem is I am not sure if the journey is going to excite/interest me that much.
Tomorrow will be one of:
- Ju Jitsu at http://www.smrtj.co.uk/clubs/?id=2
- Tae Kwon Do at http://www.jfreer-taekwondo.com/club_training_info.htm (who disappointedly hasn’t rung me back!)
- Thai Kick Boxing and then Jeet Kune Do at http://urbanmartialarts.com/Timetable.html (who has so far demonstrated excellent customer service by responding to my email before and after Christmas)
Stay tuned to find out the next step on this epic journey to black belt!
Glad my backup was working only it isn’t
So I have re-installed proxmox, updated to the latest done the LVM partitioning dance and downloading the 50GB of backup data.
Our backup strategy involves:
- take a (compressed) snapshot of each virtual machine
- use rdiff-backup to capture deltas
- encrypt the rdiff-backup ‘database’
- copy the encrypted files to two different machines
So I checked the timestamp at the local backup and great the timestamps are for last nights back up.
Once the backups are on the production machine I restore them and start the virtual machines. Magic.
Only not – the data for some reason stopped on the 23rd of December. Hmm – strange. Check the backup logs/emails – yep fine. Check the timestamps – yep – fine.
Hmm – with a sinking feeling I start to realise that even though *something* was being backed up, it was the production data, not since December the 22nd anyway.
Thinking it through I had that terrible ‘doh!’ moment when I realised that fairly small, innocuous little item on my todo list is actually quite important…. We use encFS to backup a filesystem. This works by mounting an encrypted directory into another file system. In real world terms this means there is a directory which is an encrypted mirror of another directory. Create a new file in the plain directory and as if by magic a new encrypted file will appear in the encrypted directory.
The way that we encrypt the rdiff-backup database is by rsyncing it into the plain directory.
Guess what that last little todo was? To mount the encrypted filesystem after system reboots. Reboots like the one that happened on the 23rd of December.
So all the little pieces were happening – the only problem was that because the encrypted file system wasn’t mounted everything appeared to work except the encrypted file system was never updated.
Doh!
Luckily, we use git for our source code management which means the last developer to work on the code base would (as per best practice) updated their git repo. This means that developer simply needs to pull and then push and the source code server is up to date.
If only the wiki etc. was that simple :(
The one silver lining is that because this happened over Christmas we didn’t actually lose anything but we did find a critical problem in our (ok, my) backup strategy.
Oops – wiped out the production server
I have the privilege (ha!) or managing our infrastructure for our development team. This includes our source code server, our CI server, jira, wiki etc.
I decided for convenience these should all be virtual machines, running on one of the servers we rent from the very reasonable (and pretty helpful too!) http//ovh.co.uk. I use the excellent proxmox GUI from http://proxmox.com to manage them all.
Anyway, we need another server as we are outgrowing our existing one (or will do soon), so I rented another one and have been in the process of experimenting –> re-installing –> experimenting cycle that a new box always encourages.
For convenience, I number the physical machines host, host1, host2 etc. The new machine is called host, the existing production machine is host1.
OVH provide an excellent manager which remotely lets you re-install a (fairly large) number of preconfigured operating systems – one of which is proxmox, so for the fifteenth time I started the re-installation. And then yes, you can see where this is going, yep – I had selected host1 instead of host thus wiping out all 12 of our development machines in one foul swoop.
GULP!
And no, there is no way to cancel the installation….
Returning to Martial Arts
I have studied martial arts on and off for about 10 years – the first 5 were the most continuous and intense.
I loved it – although I am the first to admit that the club I trained in wasn’t exactly official. The instructor was very good, but we weren’t affiliated with any known body. The style was that good old generic ‘kick boxing, tae kwon do, thai boxing’ that was all the rage :)
Anyway, I have decided to get back into it for a number of reasons:
- it *really* helps with fitness. I need to lose a couple of stone, and this is the quickest way I know how
- helps keep depression and stress (both of which like to come knocking on my door) at bay
- it is just really good fun getting into it with a bag!
As a practicing (I hate that word!) Christian I will be staying clear of any martial arts which have a spiritual dimension to them. This is actually very hard and rules out a lot of the arts I would have chosen (aikido, bushido, kung fu for example).
My checklist for the art is as follows:
- clear strategy for charting progress (i.e. belts/gradings). I know they are meaningless, but I give up easily if I have cannot *see* the progression
- include offense and defence and optionally weapons
- focus on technique as oppose to ‘hit the other guy harder’
- include sparring – I love semi-contact
Note: I don’t really care about it’s suitability for getting out of a ‘real fight’.
My checklist for the school is as follows:
- an instructor I can learn from
- enough students to provide a varied learning experience
- friendly, but challenging
- similar beliefs – i.e. egos left at the door
The checklist for the school is more important than for the art itself. I definitely need the right external environment in which to learn – the subject matter in this case is less relevant, at least for the next year or so.
So, my journey continues/resumes. From looking around my local area, I have two choices:
- Taw Kwon Do
- Jiu Jitsu
My concern about JJ is that it will turn into a ‘how to roll around the floor’ which I am not particularly interested in. I get it’s potential, and I want it, but I want the offensive striking and the defensive throws as well.
My concern about TKD is that it doesn’t offer enough of the ‘intercept and throw’ skills – but I don’t really know enough about it.
Anyway, over the next few weeks I will either be visiting lots of different schools or I will have found one and studying there! Tonight is (hopefully) http://www.martialartsleicester.co.uk/page/where_we_train. I will let you know how I get on.