Debugging Restlet connector problem

February 8, 2010 by Robert Brewer

In the course of developing WattDepot, I ran into an annoying intermittent bug in my JUnit tests. I would sometimes get a failure in one particular test class, but not always in the same method of that class. The failure manifested as a 60 pause on the affected test, followed by the WattDepotClient method returning a 1001 miscellaneous failure status code. Maddeningly, it would only fail sometimes, making it much harder to track down (and making continuous integration comical). Further, running the test from within Eclipse would work fine every time, so I was unable to use the debugger to figure out what was going on.

Philip pointed out that this sounded like a classic deadlock problem between threads, perhaps in Derby which I’m using for persistence. He suggested that I use VisualVM to see if I could track down any deadlocks. Mac OS X comes with VisualVM installed as “jvisualvm”, and it’s pretty easy to use. Luckily, since the failure manifested as a 60 second pause, I could start the test, and then attach to the JUnit process and obtain thread dumps to see what was going on.

After a few thread dumps, I tracked it down to HTTP communication. The failure happens when the client is using PUT to send a new resource to the server, and the server is waiting for the end of the entity body from the client. This happens before any Derby call, so it looks like Derby is ruled out (at least for this bug).

WattDepot uses the Restlet framework to make it easier to implement the REST API, and to perform all the HTTP client and server work. Restlet provides a variety of connectors for both the client and server HTTP connections. In fact, there are enough options that it is somewhat confusing trying to pick one. Restlet has internal HTTP client and server connectors that come in the core Restlet jars. According to this email thread, the choice of connector is done automatically by scanning the classpath, with the first match winning.

When first setting up WattDepot, I based the set of Restlet jars I was using on Hackystat. Hackystat’s SensorBase includes org.restlet.jar (API classes), com.noelios.restlet.jar (reference implementation, including internal HTTP connectors), com.noelios.restlet.ext.net.jar (client connector based on JDK HTTP code), and com.noelios.restlet.ext.simple_3.1.jar (server connector based on Simple framework). So it appears that WattDepot is using the Net connector for client HTTP connections, and the Simple connector for server connections, both overriding the internal HTTP connections in the reference implementation.

Since my problem was taking place in the HTTP code, I decided to try experimenting with removing Net and Simple from the classpath, thereby allowing the appropriate internal HTTP connector to kick in. Since I’m using Ivy and Ivy RoundUp for dependency management, this turns out to be as easy as changing the configuration parameter in the Restlet Ivy config, deleting the project “lib” directory and rerunning the tests.

After trying all combinations (all internal connectors, internal server & Net client, Simple server & internal client, Simple server & Net client), I found that only the combination of the Simple server connector and the Net client connector leads to my unit test failure. I guess I’m just lucky that way. :)

The solution is then to stop using either the Net client or the Simple server. Since the WattDepot server is likely to be the more performance-sensitive aspect of WattDepot, I opted to keep the Simple server on the assumption that it is higher performance than the internal Restlet server. It would be nice to figure out which of the variety of client and server connectors is recommended as the best performing, but this will do for now.

In the future I plan to post something to the Restlet mailing list to see if anyone else has run into this problem so it can be tracked down and perhaps fixed.

Future publication venues

February 1, 2010 by Robert Brewer

Updated Feb 2, 2010: added IEEE upcoming journals and IEEE Sensors conference.

So I’ve been thinking lately about where I might publish my research on WattDepot, and later on the UH dorm energy challenge. Here’s what I have come up with so far.

Conferences:

  • IEEE Smart Grid Conference. The deadline for papers is May 1, with the conference happening Oct 4-6 in Maryland. Philip has suggested this might be a good place for a paper on WattDepot, and I agree. The maximum page length is 6 pages.
  • Behavior, Energy, Climate Change 2010. Philip attended BECC 2009 and it seems like an ideal conference for the dorm energy competition results. The call for abstracts (presentations & posters) goes out in March, with a mid-May deadline to submit abstracts. The conference is November 14-17 in Sacramento. There is no paper required for the presentation, just slides, so we could potentially present some actual results in the presentation (which wouldn’t be available in May when the abstract is submitted).
  • Hawaii International Conference on System Sciences 44. This is happening on Kauai January 4-7 2011. The deadline for papers is June 15. The Jennifer Mankoff’s group has had a series of papers about StepGreen and related work at HICSS so this seems like a good venue, and the travel will be much easier. :)
  • CHI 2011. Apparently this is happening May 7-12 in Vancouver (BC I assume?). There have been a variety of papers on supporting green/sustainable behavior in CHI before, and the CHI community is a large and vibrant one.
  • Ubicomp 2010. There was plenty of sustainability work at Ubicomp 2008 (including a workshop I attended), so this is a possible venue. However, the submission deadlines are rather soon (March for papers) so it’s probably more realistic for 2011.
  • Pervasive 2011. This is similar to Ubicomp, but happens in May in Europe. Submission deadline is mid-October.
  • IEEE Sensors 2010. May 4 is the abstract submission deadline, with the conferencing happening November 1-4 at the Hilton Waikaloa. Maximum paper length is 4 pages. This is perhaps less relevant than the IEEE Smart Grid conference, but still worthy of consideration.

Journals:

  • International Journal of Sustainability in Higher Education. This is where the Oberlin dorm energy contest paper was published, so it seems an obvious choice. Not the broadest appeal though.
  • Environment & Behavior.
  • IEEE Transactions on Smart Grid. Journal to be launched soon.
  • IEEE Transactions on Sustainable Energy. Another journal to be launched soon. The smart grid one looks more relevant, this looks to be focused on energy generation from renewables.

I’m sure more will come up as I read more, but this is a good starter list.

Community-Based Social Marketing

January 25, 2010 by Robert Brewer

I just finished reading this quick-reference guide to Community-Based Social Marketing by Doug McKenzie-Mohr. This is a condensed version of the concepts from the online book, which appears to be an updated version of the book Fostering Sustainable Behavior from 1999.

With an eye towards the dorm energy competition we are planning at UH, I found the concepts very useful and it seems like our initial requirements for the website are headed in the right direction. For example, we plan to have participants make public commitments online through the site, in particular commitments that should be visible to other residents on the participant’s floor. We also plan to make the commitments very public via large-screen displays in the lobbies of the dorm(s). This is in keeping with McKenzie-Mohr’s recommendations on the use of commitments.

One member of the design team (Shanah) suggested that we have a weekly individual winner for each floor, so that each floor would have someone to look for assistance and encouragement. This is a great example of using the concept of “norms” to encourage people to alter their behavior.

The current design calls for extensive incentives in the form of coupons, pizza parties, and maybe iPods. McKenzie-Mohr cautions that removing incentives (which will happen at the end of the competition) can actually reduce internal motivation that existed before the provision of incentives. It will be interesting to see what happens to electricity usage after the competition is over.

The other lesson we need to take heed of us the use of focus groups and possibly surveys while we are designing the competition. We need to know what our target audience thinks about the competition, and the design of the website.

The Community-Based Social Marketing website has more information and lots of links to articles and case studies.

Snow Leopard Server upgrade hoses Apache config

January 18, 2010 by Robert Brewer

I recently upgraded an Xserve running Mac OS X Server from 10.5 (Leopard) to 10.6 (Snow Leopard). The upgrade was mostly uneventful, except for the web server configuration. We have a lot of manual changes (two instances of Plone using mod_rewrite, some local directories that are served up as is, and user directories). This is a rundown on the changes I had to make after the upgrade was complete to restore web service.

As part of the upgrade, Snow Leopard Server runs a script that reads the Apache config files and tries to bring them into compliance with the default configuration under Snow Leopard. The result of all the configuration munging (for all services) can be found in /Library/Logs/Setup.log. I found several problems with the changed Apache configuration. Kindly, the configuration munging script leaves unmodified copies of all the files it modifies with the suffix “.saved-Pre-SnowLeopard-unmodified”, so it is straightforward to diff the old configuration with the new one to see what changed.

First, mod_userdir was commented out in httpd.conf, preventing “~username” URL rewriting. Snow Leopard also adds an “mod_apple_userdir” (which supposedly improves security of this feature [PDF]), but also left that disabled. So by default, “~” URLs just stop working, with no notification beyond a bullet point in one of the supplemental PDFs. This is poor form, IMHO. I ended up re-enabling mod_userdir.

The next problem was the configuration file munger decided to remove all RewriteRule lines from each of the virtual host configurations. Obviously, this broke many things, but it was easy enough to copy each line back from the original configuration.

Even after fixing those issues, web service wasn’t working properly. I noticed that there was a “0000_any_80_.conf” configuration in the “sites” subdirectory (in addition to “0002_any_80_.conf”), which wasn’t being used in Leopard, but appeared active in Snow Leopard. I moved this config to the “sites_disabled” directory, and that made things much better. I’m not sure if this was some vestige of an upgrade from Tiger to Leopard, but it was causing problems.

Finally, the config munger added “ServerAlias *” to my first virtual host configuration (prefixed with “0000″). While this might be appropriate if this was the default host, as a virtual host it grabbed all URLs and prevented them from matching virtual hosts with later sequence numbers. Removing this line fixed the last issue (which was that all requests went to the first virtual host).

Admittedly, Apple faces a difficult proposition in performing automated server OS upgrades. Many of the OS services are based on industry standard open source packages that overwhelmingly use custom text configuration files. Advanced administrators will frequently want to edit those files by hand to installĀ  3rd party open source packages that build on those services. But Apple also provides GUI tools to make things easier, tools that must read and write the configuration files. This leads to the desire to keep the configuration files canonicallized for easier parsing. So at the end of the day, some poor engineer has to write an upgrade script to read all these (possibly arbitrarily modified) configuration files and bring them into line with the versions that ship with the new OS version.

That said, it seems like the upgrade scripts could do a better munging job. Turning off modules is uncool, as is dropping lines from the config on the ground.

Prepping for screencast

December 14, 2009 by Robert Brewer

Last week I focused mostly on non-programming tasks of reviewing the NSF proposal and preparing for the WattDepot screencast. I did close one refactoring issue that I generated when rolling out the Google Visualization support.

This week will be focused on the issues identified as critical for a WattDepot 1.0 release.

Plans from last week:

  • Review grant proposal
    • done
  • Plan script for 10 minute screencast
    • in progress
  • Close some additional WattDepot issues
    • closed refactoring issue 24

Other accomplishments from last week:

  • Created WattDepot issues for items discussed with Philip

Pointers to work products:

Plans for this week:

  • Create stress tests for WattDepot (issue 32)
  • Benchmark WattDepot API using stress tests
  • Optimize Derby implementation based on performance data
  • Finish script for 10 minute screencast
  • Make 10 minute screencast?
  • Start support for energy counters in Energy class
  • CSDL firewall reorg

Cool links:

WattDepot, now with Google Visualizations

December 9, 2009 by Robert Brewer

After discussion with Philip, decided to prioritize the Google Visualization data source work over performance testing. WattDepot now provides a data source for the Google Visualization API that allows plotting multiple types of data on the same graph, and expanding virtual sources into their component subsources. I have written a wiki page about using WattDepot’s Google Visualization data source.

Plans from last week:

  • Test performance of Derby implementation
    • deferred for now
  • Make GVisualizationServlet work with virtual sources
    • done
  • Review grant proposal?
    • not done, working on it this week
  • Close some more WattDepot open issues
    • closed some issues, but opened more new ones

Other accomplishments from last week:

  • Registered for Spring 2010 classes
  • Tracked down CSDL’s copy of Snow Leopard Server from UHM Bookstore
  • Pushed out new WattDepot release and notified 413/613 students of visualization availability
  • Watched some crazy big-wave surfing in Waimea Bay without getting sunburned

Pointers to work products:

Plans for this week:

  • Review NSF proposal
  • Plan script for 10 minute screencast
  • Close some additional WattDepot issues

Cool links:

  • Google Goggles is an Android application that lets you take pictures of objects (only some are recognized) and does a search for relevant information. Will do OCR on text found if it doesn’t know about that type of object.

WattDepot has persistence

November 30, 2009 by Robert Brewer

The Derby persistence implementation is now complete. This week I will start performance testing the Derby persistence implementation, and work on the GVisualizationServlet so we can visualize virtual sources. Loading default data into WattDepot using Derby for storage (no network traffic) is running at ~876 sensor data entries per second, which seems pretty good.

Plans from last week:

  • Remove last of HashMap code from DerbyStorageImplementation
    • done, along with some other cleanup (like running unit tests on both DB implementations)
  • Start performance testing of Derby storage implementation
    • just started

Other accomplishments from last week:

  • Ate lots of delicious food

Pointers to work products:

Plans for this week:

  • Test performance of Derby implementation
  • Make GVisualizationServlet work with virtual sources
  • Review grant proposal?
  • Close some more WattDepot open issues

Cool links:

WattDepot Derby storage almost complete

November 23, 2009 by Robert Brewer

The Derby persistence implementation is mostly complete. SensorData is temporarily still stored both in memory and in Derby, to simplify the initial implementation. The next steps during this short week are to remove the final in-memory tables, and start performance testing the Derby persistence implementation.

Plans from last week:

  • Keep working on DerbyStorageImplementation
    • almost done
  • Finish implementing missing methods in REST API
    • not done, deferred until Derby work is done

Other accomplishments from last week:

  • Wrote up directions on running WattDepot locally

Pointers to work products:

Plans for this week:

  • Remove last of HashMap code from DerbyStorageImplementation
  • Start performance testing of Derby storage implementation

Cool links:

  • New acronym I encountered: LOHAS. Lifestyles of Health and Sustainability (LOHAS) is a demographic defining a particular market segment related to sustainable living, “green” ecological initiatives, and generally composed of a relatively upscale and well-educated population segment.

WattDepot presentation & Derby started

November 16, 2009 by Robert Brewer

Last week was holiday-shortened by Veterans’ Day. I spent most of my time working on my slides for my ICS 690 presentation, and helping the REIS seminar substitute videographer. Now that the presentation is done, I have begun implementing persistence in WattDepot using Derby.

Plans from last week:

  • Finish slides for presentation to ICS 690
    • done
  • Start working on DerbyStorageImplementation
    • done

Other accomplishments from last week:

  • Finally got video from 11/5/2009 REIS seminar uploaded
  • Attended ITS update seminar
  • Upgraded to 64-bit Cocoa version of Eclipse
  • Wrote up my Java 1.6 & Eclipse experiences

Pointers to work products:

Plans for this week:

  • Keep working on DerbyStorageImplementation
  • Finish implementing missing methods in REST API

Cool links:

Java 1.6 & Eclipse on Mac OS X

November 16, 2009 by Robert Brewer

These are some notes on using Java 1.6 on Mac OS X with Eclipse.

Mac OS X lagged behind for some time on adopting Java 1.6, but it was finally released as Java for Mac OS X 10.5 Update 1. Unfortunately, this release has some limitations: it only runs in 64-bit mode and only on Mac OS X 10.5 (Leopard). This meant no Java 1.6 support on Mac OS X 10.4, no support for PowerPC systems, and no support on the early 32-bit Intel Macs released in 2006.

To make Java 1.6 the default Java execution environment, run the Java Preferences application (found in the Utilities subfolder of the Applications folder). There you can drag the Java versions into any order you wish for both applications and applets. So to default to using Java 1.6 for everything, you can just drag Java SE 6 to the top of both the application and applet lists. The Java Preferences application will change around symlinks to correspond to your new choices. Mac OS X 10.6 (Snow Leopard) appears to include only Java SE 6, but includes both 32 and 64-bit versions, so it should allow Java 1.6 to be run on the oldest Intel Macs (no PPC because Snow Leopard does not support PPC).

Some command line scripts expect the JAVA_HOME environment variable to be set to the directory that contains the Java distribution being used. Also, some scripts might require different versions of Java. To support this, Apple introduced a new utility called /usr/libexec/java_home. By default, java_home just returns the home value appropriate based on the selection in the Java Preferences utility, but command line arguments can request different versions (see the manual page linked earlier). The output of java_home is intended to be assigned to the JAVA_HOME environment variable in a shell initialization script (like .profile or .cshrc).

This brings us to Eclipse, the Java development environment. Eclipse can be used to develop for multiple Java versions. When creating a Java project, Eclipse prompts for the desired JRE version in the new project dialog box. To ensure that Eclipse tracks the language differences between versions, also select the desired version in Preferences->Java->Compiler->Compiler compliance level to match your project.

However, despite these changes, Eclipse itself does not necessarily run using the Java version being used for the project being developed. Initially, the latest version of Eclipse (3.5) was released only in 32-bit mode for both Carbon (an older and deprecated Mac OS API) and Cocoa (the modern Mac OS API). Since Leopard only supported Java 1.6 in 64-bit mode, this meant that Eclipse was always running under Java 1.5. With the release of Eclipse 3.5.1, there are now 64-bit Cocoa downloads available, and these will run under Java 1.6. For some users, this may not be important, but for those doing Eclipse tool development (such as the Hackystat Eclipse sensor) it is very helpful. I use JAXB in some of my Ant build scripts, and JAXB is built into Java 1.6 but not Java 1.5. When running Eclipse in Java 1.5, many of my Ant scripts report spurious errors about being unable to locate JAXBException, but these all vanish when running Eclipse under Java 1.6. I should note that at least some people disagree with this advice, and suggest using the 32-bit Cocoa version on Leopard instead of the 64-bit version. Everyone apparently agrees that on Snow Leopard you want the 64-bit Cocoa version of Eclipse (unless you are on a 32-bit Intel Mac).

So if you want to use Java 1.6 for your application and run Eclipse under Java 1.6 there are two options:

  • Use Mac OS X 10.5 Leopard (with all software updates) on a Core 2 Duo Intel Mac, with Java Preferences set to use Java SE 6 as the default Java version, and use the 64-bit Cocoa version of Eclipse 3.5.1.
  • Use Mac OS X 10.6 Snow Leopard on an Intel Mac, and use the 64-bit Cocoa version of Eclipse 3.5.1 [note, I have not specifically tested this configuration, but it should work. Confirmed, this works]