Peter Ledbrook took an amazing session on tuning your grails Application here at SpringOne2GX in Chicago. In this session Peter talked about tuning the various aspects about in your application starting from server side optimizations to the caching and zipping of static resources.
One of the most important thing that Peter pointed out was to “Avoid Premature Optimizations”. You first have to know that where the bottleneck exists(i.e. if it exists at all). So the first step towards performance tuning is actually profiling the application. So, its Profie then optimize
For profiling, we need to understand and identify where things can be slow.
As we can see, the bottleneck can be at any of the layers. We can broadly classify the layers into
- Server Side
- Client side
Some of the tools that are available on the server side include
- The profiler plugin from Peter
- Turning on hibernate logging or using P6Spy plugin.
- New and shiny Spring Insight: The stats that it provides are truly amazing and informative. Its indeed a thing to look out for. However, being a grails user, the only thing that I didn’t like was that i had to create a war out of my application and deploy it on the Spring TC Server. Will love to see a grails plugin that provides these capabilities :-).
On the client/UI side performance profiling, Peter demoed a couple of tools:
- Google’s speed tracer for Google Chrome. Its a client side performance profiling tool for Google Chrome which integrates nicely with Spring Insight to provide all your client side as well as server side performance stats at one place.
- “YSlow” extension for FireFox (needs firebug) : This is a trusty old partner that actually tells you in clear words what you need to do to improve performance of your application on the UI level.
Once you have diagnosed the problem(s) aka done the profiling, then you need to get down to some dirty (hard) work to fix these issues: For the database performance improvements, Peter explained the various things that can be done like :
- Reduce the number of queries
- Tune your queries to use indexes or even change the model if the need be
- Caching: how to use the hibernate 2nd level cache or using someother caching strategies like Distributed cache (e.g. Terracotta, Gemfire and the likes)
- And if the need be, use an Alternative Data Store
For other server side improvements, Peter also pointed out the use of the Spring cache plugin and also how it can be used to cache complete pages or even page fragments.
For improving the performance on the UI level, there are a number of things that can be done such as:
- Reduce number of requests (latency)
- Expires HTTP
- Image spriting
- Reduce amount of data transferred to browser (bandwidth)
- Compress data
For doing all these things the grails way, there are plugins like UI Performance, JAWR, Resources et al. available I have worked with UI Performance and now can’t wait to get hold of the awesome Resources plugins family by Marc Palmer after hearing about it from Peter.
Well learnt a lot of new things and some learnings got re-enforced. Really happy to be here among this buzzing and vibrant community.
As someone at the conference said: “These are exciting times :)”