2015-05-04

Polishing your Portal with a High-Load Page

When your servers become overloaded with requests, they're unable to your end users with the experience you desire.  It's important in these situations to fail gracefully so that your end users (customers, employees or whomever it may be) don't become frustrated with your site.  We wanted to provide a customized high-load page so that our site:

  • Fails gracefully for users trying to connect, and minimally affects users who are already connected
  • Looks a more polished and professional
  • Is guaranteed to provide a known QoS to our customers

The portal we're customizing is based on Liferay.  In our case, we didn't like the error page that Liferay provides by default when using the session.max.allowed property, so we decided to do some customizations.

To do so we added a redirect to a high load page based on the user session count.  The high load page is an extremely simple page.  We're using static HTML served by Tomcat, and we made it as light weight as possible.  Serving the page with Apache HTTP would be better, however we don't have the option to do so in our system.

There were 4 steps to adding this page:

1. Add custom properties to portal-ext.properties file

2. Create a class that tracks the session count
 - Use a listener to track the number of sessions , increasing count on creation and decreasing count on destroy
 - There are several examples of doing this on the web, i.e.
 - http://tomcat-configure.blogspot.ca/2009/01/tomcat-session-listener-example.html
 - The listener must be added to the web.xml in your Liferay ext plugin

3. Check session count in all desired classes that extend HttpServlet
  - Must be done in the Liferay ext plugin, follow proper ext patterns explained at www.liferay.com
  - If too high (above threshold in portal-ext.properties), redirect to low load page and invalidate session
    - Redirection page should be in portal-ext.properties to allow it to be reconfigured without recompiling the code (and redeploying the ext plugin)

4.  Create a very simple target page that will result in minimal server load
 - In our case I just created a directory in webapps (using tomcat) with an index.html file
 - index.html contained simple message explaining we're experiencing higher than normal load, please re-visit the site later


2015-02-13

Automatically Email Zigbee/Z-wave Sensor Changes from the Almond+ WiFi Router

Disclaimer: I do not work for Securifi

Last year I backed the Almond+ WiFi router on Kickstarter (Securifi).  After a couple of delays which weren't entirely unexpected from this type of project, I received it in the mail.  Since then, it has been working quite well.

Before delivering the Almond+, Securifi sent out an option for backers to order sensors from them.  Since they were ~$30 each, I figured I would get a couple and try them out.  I ordered a flood sensor, AC switch, window/door switch and a motion sensor.

Securifi has a cloud service that allows you to remotely connect to your router, monitor sensors, etc...  They're working on pushing sensor statuses to a mobile app you install on your smartphone, however last I checked they have some bugs they're still fixing.  There are several people waiting patiently for this functionality, including myself.  I also decided to quickly code a poller.

Since you can get sensor statuses from the routers web interface, I decided to write a python polling script that will scrape the sensor values from your router and send an email whenever they change.  I threw the script together pretty quickly, so it's not the greatest code but it works.

I setup the script as a service that automatically runs on startup on a computer running Ubuntu Linux.

A couple of quick notes:
  • Update all the xxxx in the Python source code as appropriate
  • You may have to tweak ALMOND_URL for different versions of firmware
    • I have version Software Version : AP2-R070-L009-W016-ZW016-ZB005
  • I did have issues with the gmail password, and had to follow some steps found at the accounts website (see comment above variable) to setup the application
  • With a couple of changes, I'm sure you can get it working with email services other than gmail, or if you're more ambitious change it entirely to use some other communication (twitter, ifttt would be very powerful, etc...)
  • I added a bit of code to interpret the status of the sensors I have, I haven't tried it with any other sensors but I don't see why they wouldn't work
    • Custom code can easily be added for other sensors to make their status more human readable
Click here for the Python source code.

Post any questions, suggestions, and changes/additions you make in the comments section below.