Tuesday, October 20, 2009

Keeping Seaside session alive

I've created a simple Seaside app to monitor the state of our servers. It does this by screen-scraping multiple service status webpages hosted on our servers. The monitoring was coded as a sUnit set of tests which can run standalone or as part of the Seaside application. Any service breaches are sent via Growl or Snarl. All status responses are persisted using Magma and so far it's been working well.

There have been a few minor issues though.

Memory consumption was a little high and I pinpointed it to Magma + Squeak. It seemed the MaTransaction's and the oid's were not being garbage collected even though they were in a WeakDictionary. I fixed this by registering the WeakDictionary with the WeakArray finalization process in MaTransaction. Memory problem fixed :)

Another issue was that sessions were expiring after 10 minutes and since we typically look at the results every 2 hours or so. Reconnecting to the Magma store and re-establishing the session was slightly slowing down the responsiveness of the app, so I decided to add a Javascript session keep-alive hack. I created a little Seaside component that I render in my main Seaside component. It's renderContentOn: method reads
>>renderContentOn: html
(html periodicalEvaluator frequency: 5 minutes asSeconds) callback: [:renderer | "do nothing"].
All this does is call back into the app every 5 minutes and now the responsiveness has improved and we still have session management (when the browser is closed).

The other issue was really to a poor design decision on my part. The status responses received from the servers are persisted using Magma and I had created a few indexes and used a MagmaCollection. One of the monitoring pages show the total number of tests and the total number of failures. This query was progressively getting more expensive as the status response objects were being materialised to see if the response was successful or not. The answer to this was to create another index for this boolean. So I created a BooleanIndex added it to the MagmaCollection and bam, much better performance. Queries are now coming back in under 1.5 seconds whereas before it was taking about 90 seconds. Magma DB has about 20000 entries at the moment, so I'm pretty pleased with the response times.

Overall I am pleased with the use of Seaside, Magma and Pharo. What I want to do now is make the site look better and maybe add some ajax calls to make the site more usable. But then again this is a hack, maybe I'll live with it.