blog | projects | resume
Filed under

gov2.0

 

It started with this tweet.

Screen_shot_2012-01-02_at_5
... and then I found myself on the couch during New Year's Eve with a really bad movie. Laptop out...  in the wee hours of the New Year, I released a new web service for Madison. It provides a simple JSON wrapper around Madison's recently released data for parking availability on the isthmus. I added it to the list of services available in the SMSMyBus API.

http://smsmybus.com/api/v1/getparking

I was greeted in the morning by a lot of great feedback so I hooked it up to the SMSMyBus interfaces - SMS, xmpp and email - to create an app for it. For example, you can find the percentage of open spaces in downtown lots by texting 'parking' to the service...

Parking-app
... but what I really hope for, is that others take this and build something creative with it.

Although it's great to get so much positive feedback from the Madison community on these little projects, it's really (really) important to recognize that the work I've done with the API is going in the wrong direction in many ways. I'd rather be building the apps on top of services created by Madison. Eventually, this great city of ours needs to stop building websites and start producing the core feeds that I've done. That's the foundation. That is the government as a platform.

Filed under  //   gov2.0   madison   opengov   projects  

Comments [0]

This post revisits my earlier evaluation of Google App Engine's post-preview pricing changes and how it affected my project, SMSMyBus. As I noted, the app was projected to cost between $6 and $7 dollars per day under the new platform pricing.  
 
Since that post, I’ve been rolling out small, incremental changes to optimize the code and combat all of the known issues. I’m thrilled to report that I have the price down to $0/day. And I’m once again impressed by the snappy and reliable App Engine platform.

Looking back on the changes, I can say that I was doing some bad things, some abusive things, and App Engine was making some bad choices as well. But the end result proves that if its developers optimize and do smart things, they are rewarded. App Engine remains a great solution for my transit API service.

Here’s a history of the changes over the last two months that got me down to $0/day...

Platform Configuration

1. Instance allocation
The new pricing model charges applications based on their use of instances (hardware resources where your application is running) rather than CPU utilization. A key to keeping your instance cost down is to simply reduce the number of instances that are spinning. Duh. So I grabbed the instance slider in the application settings and yanked it to the left. This doesn't prevent scaling, it just limits my billing for normal traffic flow.

2. Delete data
App Engine data storage (for your database) costs $0.008/GByte-day. Doesn’t sound too expensive, but I had been storing every single API call I had ever gotten. I thought it would be useful for API developers and for analytics. My drive to $0 outweighed that, however, so I deleted all of the history data and got under the free quota for storage.

Application Configuration
3. Memcached the application's route listings
I was surprised to find that I wasn’t doing this already, but there it was. I have a data structure that maps bus routes and bus stops to scheduling data on the Metro website and it never changes. In some cases - like the static calls from the kiosk clients - I was looking up route listing details in the datastore once every minute!! Fail. I used memcache to keep the common queries in memory and avoid the extra datastore reads.
 
4. Limit access during off hours
One thing that never changes is when the Metro service is running. There are five+ hours a day where the buses aren’t on the street. But some clients are still asking for data. I stubbed out most of the API during these off hours before the code ever gets close to making a datastore or memcache call.

These four changes brought me down to $0.70 per day. Bam!

Algorithm Changes

5. Asynchronous screen grabs
If you don’t know, behind the API curtain is an ugly screen scraping task that extracts the arrival estimates from the Metro website. So when a client requests arrival data for a stop, the app goes off and requests multiple web pages, machine-reads the information and aggregates all of the results.

The original implementation of the SMS interface did this by creating multiple tasks (one for each route traveling through the respective stop). When a task ran, it stored the results in the datastore. An aggregator task would read those results out of the datastore and piece together the response to the caller.

When the API was created, I couldn’t use background tasks because I had to respond with results in the same HTTP context. That’s when I discovered the great feature, asynchronous url fetch. This essentially let me grab all of the different Metro web pages at the same time. But when I implemented this, I continued to use the datastore as the mechanism for storing and retrieving results. This was just lazy. Under the old pricing, I wasn’t incented to change it other then the fact that it was a bit slow.

Under the new pricing model, this solution was very expensive. The API is continuously running this aggregation algorithm - constantly writing and reading to the datastore for model instances that have a lifespan of under a minute!

I rolled out a change that removed the use of the datastore and instead sorted the aggregated results in memory. This had a dramatic effect on my API quota for datastore reads and writes as well as overall performance and latency for my users. Especially the write operations, where you get penalized by an order of magnitude for this type of behavior because index updates work against your API quota as well.

6. Dogfood
After optimizing the API, I realized that the original SMSMyBus apps (SMS, chat, email and phone interfaces for the Metro) were now the long pole. Those apps were implemented before the API existed so they weren’t benefiting from the API optimizations. Solution... re-implement to use the SMSMyBus API.

It should have been done long ago simply as a validation exercise of the API methods. Credit to the eligence and simplicity of the API - this port was simple and only took a couple of hours.

These two changes brought me down to $0.10/day. Badda-bing.

AppStats

7. Run Appstats on all application interfaces
The last stop on the optimization train was Appstats. A truly great tool in the App Engine toolbox. In just a matter of minutes, you can find the hidden datastore operations that are dragging you down. In my case, it led me to one area that wasn’t being memcached at all. And it revealed an area that was simply using the memcache incorrectly! Love this tool...

This change brought me down $0.00/day. Winning.

Results
App Engine remains a great platform for developers that don’t abuse it and take the time to optimize their applications.

The SMSMyBus API now serves over 6,000 transit requests per day. It’s fast, reliable and flat out fun to use. I’m as proud as ever that I brought this to Madison.

Next step... find a way to fund my SMS users. :)

 

 

Filed under  //   appengine   gov2.0   opengov   programming   projects  

Comments [19]

Over a year ago, I smiled when I found SMSMyBus getting repurposed in the form of a kiosk at the Mother Fool's Coffeehouse.  I wrote then about the personal satisfaction of seeing a pet project growing into something bigger.

Well, last week, that satisfaction blossomed into gratification when I learned that the University of Wisconsin had included the SMSMyBus API in the latest version of their app released for the 2011 academic year. Now students using the app can get real time bus arrival estimates throughout the city rather than relying on the fixed schedule right from their iPhone and Android devices.

Super proud.

Mostly because this is exactly the kind of application that can get the attention of the Metro and the City of Madison as an example of what can be accomplished if more public data becomes accessible in an easy to consume (programmable APIs) interface.

Dear Mayor, please take note. We can achieve more, do so at a lower cost, and generate more economic development if we work together.

Filed under  //   gov2.0   madison   opengov   projects  

Comments [2]

This was the talk I gave at last night's PechaKucha in Madison prior to HTHH. It's the story of my epiphany relative to leverage my technical skills as a way to give back to my community.

 

Filed under  //   gov20   madison   opengov   programming   projects  

Comments [0]

Img_5409

I had a huge smile on my face this morning when I scrolled through my Twitter timeline and found @gl33p's pictures of the new display at Mother Fools Coffeehouse. Coffeehouse patrons are now enjoying real time arrival estimates for the Madison Metro buses passing by at the corner of Ingersoll and Jennifer courtesy of SMSMyBus!

It's amazing and gratifying to see this project come to life the way it has. And it reinforces the importance of doing rather than talking when a problem presents itself. You just never know where it will lead you.

A few months ago, Twilio ran a developer contest for their new SMS API. Having already built one Twilio app for blogging to Posterous, I was anxious to create another one and I immediately knew what I'd build with the SMS tools. 
 
I have long wanted a way to query the Madison Metro bus system to understand where my bus is when I'm standing in two feet of snow. I knew that Metro tracked their buses using GPS so I figured why not put that information in my hand using a mobile phone.
 
I was able to build the app in a weekend of hacking and SMSMyBus was born. I could query any bus and any bus stop in the city from my phone. My problem solved... But I quickly discovered that I wasn't alone. Several people around me were having the same problem and immediately started using the service as well. Feedback and bug reports came flying in and the number of users grew without an ounce of publicity outside of a few tweets. Today there are over thirty individuals using the service to make their bus experience better.
 
Since its initial release, I've added a number of other interfaces to extract scheduling data.... You can now receive real time arrival estimates via the phone, email, Twitter, and Google chat.
 
Through the prodding of my first user and biggest evangelist, Preston Austin, I was encouraged to build a truly platform agnostic interface and make the data available through a simple web service. Once made available, Preston championed the creation of the display at Mother Fools and implemented a terrific presentation layer that continuously refreshes throughout the day.
 
This has opened the doors for a number of different opportunities for partnerships throughout the city, and we're looking forward to expanding the number of displays to make the data more accessible and make riding the bus more enjoyable.
 
Do you have an itch? Have a problem that needs to be solved? Go solve it. You never know what it will turn into...

Filed under  //   appengine   gov2.0   madison   opengov   programming   projects   twilio  

Comments [7]