Tuesday, May 27, 2014

A picture is worth a thousand words

I have spent the last little while sorting out Sancho's logging along with the recording and visualization of statistical information.  No, it isn't the most thrilling thing to do, but I'm convinced that it will be worth it.

Up until now, Sancho has had an assorted collection of System.out.println calls with the odd System.err.println for good measure.  We even dumped occasional performance figures (number of MCTS iterations in the last turn, thread utilization, etc.) in amongst all the other output.  That's all very well, but soon we discovered that you can't see the wood for the trees.

So, if you're still developing a player, I'd recommend that now's the time to get to grips with logging.  The sooner you do it, the more you'll benefit from it.  And whilst I'm offering advice, here are the tools that I've used - all of which are great.

Log4j 2

Log4j 2 is an excellent logging framework that's simple to integrate and easy to configure to suit your needs.  This was an easy decision for me because I use Log4j (the original) at work.  Log4j 2 has sorted out all sorts of things that weren't quite right in first edition and it's a great product.

Sure, it was a bit tedious replacing all the println calls with LOGGER.debug/info/warn/error, but I can now trivially, for example, print info level logs and higher to the console in a concise format and debug level logs and higher in verbose format to a per-match log file (which means we'll always have the logs from every game we've played - avoiding the 'doh' moment when you realise that you failed to save off the console output and have now closed the window).  Statistics information is written to its own file in machine-readable format.


Highcharts is a super javascript graphing library.  I've dabbled with this before, although not very much.  However, it's really easy to pick up and has great documentation.

By graphing our statistical output, Steve & I have already spotted a couple of significant issues which we'd never have seen otherwise.  On one of my boxes, something is causing performance to regularly fall off a cliff.  (I suspect page faulting, but haven't investigated yet.)  On Steve's box, he has seen excessive garbage collection which we hope to address with additional object pooling.

Tiltyard log upload

If specified in a player's registration, Tiltyard will hit a URL after each match.  Whatever is returned, Tiltyard stores in the match database.  Then, when you look at the detailed record of a game on Tiltyard, your player will then have a little graph icon next to it.  Clicking on that will show the uploaded information.  Furthermore, if you add a log visualization URL to your player registration, you can produce your own custom viewer.

(I'm still having a few teething troubles with log uploads, but expect to have them available for all Sancho's matches soon.)


So still very much a work in progress, but here's that promised picture.  (And, once I've sorted out the Tiltyard wrinkles, just take a look at any of the recent matches Sancho has played in.)

No comments:

Post a Comment