Posts Tagged google io

Presenting spring4speedtracer

One of the biggest “wow” moments for me at Google IO a few weeks back was seeing Google’s Speed Tracer display performance data from the server right alongside the client. I immediately downloaded a copy of Spring’s TC Server to see how they did it, and quickly realized that it’s very container-dependent: custom deployers, configuration, etc. all of which make it a really power tool for simply dropping in any web application and getting their whole performance dashboard, but difficult to use in a broader context. It seemed to me like a simpler solution could give the same great end-to-end snapshot of a request in Speed Tracer without the heavy footprint, not to mention an option for those of us with applications that simply can’t run on TC Server.

A couple days and much caffeine later, I was right! It’s become my newest Google Code project, spring4speedtracer. Not a very inspired name I know but it gets right to the point.

I spent a little time digging into the mostly undocumented Speed Tracer API an quickly learned that the key to displaying server data is just a response header on any request that it traces. If the header is present, Speed Tracer will query that URL for a JSON payload containing the additional data and display it in a tree for the user. Really all an application needs to do is bundle the data in the right format, set the expected headers, and support retrieving it via some URL.

This was enough to convince me that a simple library could be built just to take advantage of the Speed Tracer API and present server trace data without all of the other monitoring and tracking features of TC Server. I decided to drive my approach by that immediate goal: I want to see end-to-end profiles of my GWT applications in Speed Tracer where the server is a Spring application running embedded in Jetty, on JBoss using JEE features, or really anywhere else. Some minor configuration (editing web.xml or a Spring application context, and dropping in an extra jar) would be a fair tradeoff for it working in any container.

The first cut will happily trace any public method invocations on @Service or @Repository beans throughout an HTTP request and show them in Speed Tracer just like Spring Insight does. It does this with three beans and one filter: basically a repository for the trace data, an aspect to perform the trace, a writer to turn it into JSON, and the filter intercepting HTTP requests to enable the traces and publish them to Speed Tracer.

Adding spring4speedtracer to an existing project consists of adding the jar and dependencies (really just Gson since the Spring jars are probably already there!), adding the filter to web.xml, and importing the provided Spring context inside the existing one. Or, for more customization the beans can be wired in directly, possibly using extended versions that have different pointcuts determining what gets traced, integrating with a more long-running tool like Spring Insight, etc.

For some basic safety I’ve added support for toggling traces with both a Java system property and a request header, allowing it to be controlled globally at the server and/or per-client. When traces are disabled the overhead is very trivial (just a boolean check inside the aspect). I was a little worried that adding another proxy to every @Service and @Repository would cause problems, but after trying it out in a couple complex projects it’s been working fine. The main caveat I’ve seen is that it’s important to follow the AoP dynamic proxy vs. weaving conventions: if the bean has at least one interface then it’s going to get a dynamic proxy, so other beans must inject the interface, else if it’s just an implementation then it will get byte woven. But any beans lingering around with multiple interfaces and some beans still injecting the target type will break. Removing the interface or changing everything to use the interfaces fixes the problem.

The result is definitely cool. I can now pull up end-to-end Speed Tracer traces running these applications on any server! When I get time I’m hoping to add support for tracing deeper functions like JDBC operations and somehow reporting work that’s farmed out to multiple threads during a request.

, , , , ,

5 Comments

Google IO 2010 day 2

Plenty more fun on day 2! There was lots of general iPhone and iPad killing with Android 2.2 demos during the keynote, along with the announcement of Google TV. The keynote is up here.

More on GWT from the sessions:

Widgets
There is lots of client-side performance improvement to be had using LayoutPanels, UIBinder, and ClientBundle. Another great workaround, which does have some risk and complexity for “maximum performance”, is innerHtml. The new components in 2.1+ help abstract that out so as consumers we don’t have to dip into innerHtml directly as often to get the benefits. There are also some good organization and code clarity benefits to UIBinder, like declarative views and replacing the monolithic app css file with bite-sized package files where possible.

Testing
This session made me happy because the testing best practices at Google seem to align really well with what my team is already doing. They stressed heavily using MVP to create unit-testable code and then test in a JVM as much as possible, keeping views so simple that there is very little which can break. They also use Selenium/WebDriver for high-level integration tests that walk through the app as a sanity check. There was a little bit of discussion about GWT unit tests (the compiled ones), by for the most part everyone agreed that they are too slow for the value they provide so it’s an intermediary step for special cases where not a whole lot of testing occurs. Most importantly teams should just acknowledge up front that there are multiple scopes of GWT tests and try to use them all correctly. Another good idea out of this was developing UI test harnesses for complex UI views, especially anything browser-specific or with performance constraints, so that it’s possible to write “Selenium unit tests” that bring up just the harness page with the widget and hit them really hard in a tightly controlled scenario rather than in the larger application (even a mock application).

GWT in Production Applications
This was Ray Ryan’s (of the infamous 2009 MVP session) architecture talk this year. The overall theme around MVP was the same, with some focus on broader topics like supporting bookmarkable/crawlable pages. However it was interesting to learn that GWT core is finally going to bring in some version of GWTLog that implements the Java logging API. The main tool used for demoing these was Spring Roo with GWT which in a nutshell is “Grails for GWT” – really cool to run a few commands and auto-generate your whole project, JPA entities, service endpoints, etc. but not something I’ll use on an existing, well-established product. For brand new products or teams just learning GWT it could be cool, and for the community overall certainly lowers the barrier of entry to get a full-stack Java/GWT project running quickly. Finally, in addition to logging there’s some new support in 2.1 for manipulating headers and some SafeHtml utils for using innerHtml in a way that doesn’t introduce security holes.

, , ,

No Comments

Google IO 2010 day 1

What a great way to kick off the conference! There was lots of GWT focus even starting during the keynote, which I honestly didn’t expect; HTML5 and browser video was big but GWT was right there behind it. Real backing from SpringSource/VMware was good to see and the SpeedTracer and 2.1 widget demos were impressive. The keynote is up on YouTube already, with sessions to follow in June.

My big takeaways the first day relating to GWT are:

Widgets
GWT 2.1 is just around the corner and is heavily performance-focused with more general purpose widgets that will let us display data quickly. Specifically they seem focused on high performance grids and layout strategies, which really started taking off in 2.0.

SpeedTracer
SpeedTracer has some really powerful new features like being able to add arbitrary benchmark points in code that show up in its UI, and ability to link back to the actual line of Java code for a GWT project (not just the obfuscated JS), along with the server-side integration via Spring from the keynote; while I haven’t tried yet it’s all in the latest milestone and should essentially be available now.

GWT Compiler
There are a lot of undocumented compiler options to further reduce code size and some other JVM options you might not have expected can help too (like -server and a 64-bit JVM), but using code splitting really makes the biggest difference (yay!), as well as some other things I’ve suspected like avoiding singletons and other static initializers at all cost.

GWT Linker
Linkers are really easy to build and are a powerful way to handle the final creation of an app with far more metadata available than, say, manipulating files with ant. Unfortunately something like static linking – an idea many of us have thought about to reduce the coupling between different GWT modules that inherit each other – needs heavy interaction between both the compiler and linker, and even though it’s open the core compiler is far less documented/outside developer friendly right now. However, there is really cool work being done to support distributed compiles that’s separating the work out in a way which might be divided not only among a cluster of machines across permutations, but used to save artifacts and re-use them if the underlying module hasn’t changed. I chatted with some people after the session and there is just a lot of work to be done in that smart splitting/change detection that puts it in at least the 2.2+ timeframe.

Architecting for Performance
Most of these best practices were things my team is already familiar with like putting serious thought into how the application is bootstrapped, how many RPCs we’re making, and what the payload is, specifically the importance of having UI-focused meta-services that return exactly what a UI function expects rather than simple generic services with heavy lifting in the client, plus more “use code splitting!”. However some new ideas are using UIBinder to separate out (and obfuscate, in production) css, using LazyPanel to defer rendering as late as possible without affecting the contract of widgets to their consumers, and designing UI’s with more optimism when an RPC takes place (assume it will work and begin the “success” case immediately, finishing as the data arrives, but potentially more work to handle failure).

A theme here was orders of magnitude, and the idea that performance is just a characteristic of usability:

  • 100ms = “instant” to users, almost everything should be faster than this – I related to this to anything that’s purely client that I expect to be unnoticeable
  • 1,000ms = “keeps focus”, this is a pretty big deal but things above this can be managed with explicit feedback – I related this to anything requiring a potentially slow RPC load and putting up some kind of “Searching…” or “Waiting…” dialog
  • 10,000ms = “upper limit”, the longest you can possibly ever take before a user has surely alt-tabbed, gotten up from their desk, force-killed your app, etc.!

HTML5
There’s a ton of buzz around this right now, but the short story for the moment is that any app forced to stay seriously in the IE7-8 world (which, sadly, mine does), is going to be crippled. To take advantage of what, as they like to say, “all modern browsers” are capable of, apps are going to need a user base comfortable running Chrome, Safari, and Firefox (and I guess Opera), else they’ll be left in the dust.

, , ,

No Comments