Saturday, February 13, 2010

Reflecting on the US trip

As I wait for my flight in Albuquerque's Sunport Airport, enroute to Hong Kong, it was a good time to reflect back on what was learned on this trip. I have been working in the application space for quite a while now, and it is interested to look at it at the infrastructure/facility perspective. On this trip, I get to meet some very experienced people in the realm of data centre cooling and it is interesting to compare and contrast their approaches.

Wally Phelps from AdaptivCool is very knowledgeable in the science of fluid dynamics and equipment cooling in general. Their "active" approach to data centre cooling probably stem from their deep experience in equipment cooling and heat dissipation design for electronic devices. Their complete suite of active components (fans with controls and sensors) combined with a web-enabled air-flow management software allow the system to actively sense changes in temperature and move air around to manage the cooling of the data centre.

I also got to meet Lars Strong from Upsite Technologies, the company founded by Ken Brills, who also founded the Uptime Institute, a leading body in data centre management. In comparison, the products from Upsite Technologies first appears much more primitive. The main products include, blanking panels, brush seals from cable openings and temperature sensing strips. These simple plastic-looking material will be a tough sell when they command such a high price. Would their brand name, design and quality assurances worth the price premium? After talking to Lars, he did point out some interesting points which show a lot of thoughts has actually been put into designing the products. Here are some of them I remembered:
  1. The blanking panels are designed such that they can be easily stacked. This allows the blanking panel shipments to be unpacked on site outside the data centre and brought in to the equipment rooms. Why is this important? For a well managed data centre, it is important to keep the equipment room clean. Cardboard boxes and packing material can create a lot of debris and dust when the unpacking is done inside the equipment room.
  2. The blanking panels and brush cable opening seal are made of conductive material (not simple plastic) which prevent buildup of static electricity and help dissipative static build up.
This is it for now, I am about to board my flight.

Monday, October 19, 2009

My experience with Google AppEngine - Java (Part 2)

In continuation of My experience with Google AppEngine - Java (Part 1).

After uploading the same DTA file which work local to Google AppEngine, I received a big fat Internal Server Error message. I diligently checked the Logs available through GAE admin console, and I found a suspicious error. I no longer have the exception information, (GAE rolled-over the logs), but it was quite obvious the problem is due to the file upload code. The example on Apache Commons File Upload User Guide, does not work out of the box on GAE.

The answer was not too hard to find after some googling. GAE/J does not support File system. The proper example is available even on the GAE/J FAQ: How do I handle multipart form data? or How do I handle file uploads to my app?

After updating my code according to the example in the FAQ, I no longer get an Internal Server Error, but my page would not refresh with the new information. It works fine locally, but will not work on GAE/J!

This is one of the tougher problems since the symptom is not specific, it is difficult do even know what to google about. There was no error message which I can google about. One of the best approach I find to resolve this issue is to think like the system. It is similar to the good old say of "think in someone else's shoe". However, the someone else this time is actually Google App Engine.

Going through the thought experiment combine with code inspection was a powerful way to troubleshoot a problem these kind of problems. It does require a good understanding of the different layers of abstraction in a distributed computational system. Good thing the early days of tinkering with PC parts + reading random computer articles/books + education did paid off. It all came down to this small segment of code.

Object myObject = request.getSession().getAttribute("mySessionObject");
// do something with myObject
return;

All I had to do was:
Object myObject = request.getSession().getAttribute("mySessionObject");
// do something with myObject
request.getSession().setAttribute("mySessionObject", myObject);
return;

Long and behold, the code is now working properly.

After going through the issue above, I am convince writing stateful code over a technology (HTTP) which was inherently stateless is difficult task. With the computer ecosystem getting increasingly complex, layered with abstraction on top of abstraction, it is getting harder and harder to find people who understanding the stack of technologies.

With the increase advancement in browsers, libraries that normalize the difference between browser, I think it is a good time to re-examine moving the state back into the browser (except security). No more 50+ MB session objects.

The plotter code stores the raw data of what to plot in the J2EE session, and I would like to move it out and maintain that information on the client side. In fact, I would like to re-architect the page such that no function will require a page load.

With that goal in mind, the only real reason the page requires a reload is the file upload form post. Some googling around, I was excited to find DWR3 is moving to support file upload.

After many tries, I was still unable to get DWR3 file upload to work on GAE. Even just including the DWR3 libraries into the GAE project, the project will fail to start up properly in the local sandbox environment. This is actually a good thing this failed locally, instead of having to find out after hours of writing the code that it would not work on GAE.

The error I was getting was:

javax.servlet.ServletException: org.directwebremoting.extend.ContainerConfigurationException: java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
at org.directwebremoting.servlet.DwrServlet.init(DwrServlet.java:77)

To give DWR3 credit, it is still in a pre-release stage and the code-base I worked with was RC1 and RC2. Although DWR3 was explicitly listed as "Compatible" the the "Will it play on App Engine" list from google, it looks like I am not the only one who is out of luck.

Issue#376 has been open against DWR to hopefully get it to support GAE and other platforms.

There are many posting online from different people on different mailing list with the same problem.

The most useful post online I found was this. Basically, the problem has to do with DWR3 spawning threads during start up. These threads are responsible for some house keeping within the DWR3 library, but spawning threads is a big no-no in GAE/J. There are workarounds in the mailing list to override those house keeping code, but is it really worth investing all these energy towards it?

Maybe DWR3 is moving towards supporting the GAE/J platform, however, at the time of my investigation, only DWR RC1 and RC2 was available.

Inspecting ContainerUtil version 1.35 tagged for RC2, the problematic code of using the DefaultScriptSessionManager in the setupDefaults() method during initialization is still there. (DefaultScriptSessionManager is the one spawning threads).

container.addParameter(ScriptSessionManager.class.getName(), DefaultScriptSessionManager.class.getName());

There are later versions of the file, and the setupDefaults method in ContainerUtil has changed, but I don't think investing the energy at this stage to get DWR3 just to start up in GAE/J is a wise decision. There may be a lot more compatibility issue between DWR3 and GAE/J down the road.

So with all these rambling, what is the moral of the story?

GAE/J is a great platform which promise to reduce a lot of infrastructure and system administrative cost. However, there's a catch. The power of Java is its ubiquitousness. There are Java libraries for many many purpose, from game engines to integration with mainframes. But GAE/J does not fully support the J2SE/J2EE standards, and a lot of libraries which you or your enterprise relies on may not work on the GAE/J platform.

Secondly, writing truly distributed server side code on J2EE is not easy. I suspect there are many code out there running on the J2EE platform is either working because it is running in a single JVM, or relies on load-balancer session stickiness to make the non-distributable code works in a "cluster". You will lose that "luxury" moving to the GAE/J platform. The above example of remembering to set you session attribute back into the session is only the tip of the iceberg of the challenge in distributed code on J2EE. There are many applications out there with enormous session objects which will grind to a halt if the session object needs to replicate across nodes, as in the case on GAE/J.

Saturday, October 3, 2009

My experience with Google AppEngine - Java (Part 1)

Recently in the Information Technology space, cloud computing is the latest buzz words. One of the players in town is Google. Their offering, Google App Engine (GAE), provides Platform as a Service (PaaS). Python and Java are the two platforms provided by GAE, aka GAE/P and GAE/J.

Recently, I had a chance to worked on a mini web application project. The application is simple, where a user can upload a file captured by one of these nifty device, iButtons, and the information are charted out similar to the OneWireViewer desktop application.

A few years back when Google first came out with GAE/P, I toyed with it a bit, writing a simple (and ugly) bulletin board application. It was a good introductory experience, and PaaS idea looks promising. Unfortunately, my *real* work project went into crunch mode and I can no longer devote my time to study Python and Django framework on GAE/P.

Then Google came up with the Java Edition of GAE, which reinvigorate my interest in PaaS. With my background in Java, GAE/J is a nature choice to build my mini web charting application.

Although GAE/J was still in "Preview-Edition", it already came with a pretty decent eclipse plugin. I still remember the early days with GAE/P where I have to memorize command-lines in order to build, compile and run the local GAE/P environment to test. With this eclipse plugin, it freed up some of my brain cells to focus on the actual application development.

Armed with a sample data file, the first thing to do is to build a parser to read-in the file and transform it into a POJO data model which can be manipulated easily. Simple enough, no issues there.

Next up was to create the upload functionality. Apache Commons fileupload comes in handy. I follow the instruction available on their website and so far so good. The functionality works seamlessly on the local GAE environment (build on Jetty). After integrating the upload functionality and the parser, I have half the application completed in a few hours.

Lastly, the charting part. With my new found love for all things Google, I gave Google Chart API a spin. The concept of Google Chart is simple and elegant. It is a REST-ful API which you supply all the input to the src attribute of the <img> tag, and viola, you get a chart image back. Elegant yes, but not without its flaw. By simply looking at the API, the inherent limitation of the design became apparent. Since the <img> tag basically using a HTTP GET command, the payload of the API is limited by the inherent length of a URL!

http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World

You know how people say "Love is Blind"? Yes it is true. Even in the nerdy world of software development. Damn Google with its slick API and sexy looking charts. It is so hard to resist! With my new found love for all things Google, I ignored my intuition and solidered on.

Another hour or two, I have a local working prototype. Time to celebrate? ... Not yet. Let's upload the application and test it on the Cloud!

Being all things new and shiny, of course it did NOT work on the actual GAE/J cloud. Upon uploading a the test file, I get a nice big:

Internal Server Error

To be continued ...

Wednesday, September 23, 2009

TTC losing money again?

TTC is on the news again. http://www.thestar.com/news/gta/article/699522. I love the first line "The TTC's success has helped create a $17.4 million deficit". I can be very successful at spending/losing money too. If only I can find a job where success is measured by ones ability to lose money. However, consider TTC has $1.2B operating budget, missing the mark by less than 1.5% is not that bad. The chronic budget shortfall is the bigger issue. Perhaps management should pad their budget with more contingency :)

The whole article or the shenanigan around budget shortfall because of metro pass is really not that interesting. Just some political/media verbiage to justify a fare hike. With the complexity of balancing a $1.2B operation, I am sure the shortfall is a lot more complicated than "because of our success with the metro pass". It is kind of like answering the "what is your weakness" job interview question with "I sometimes work too hard" or the like. Just plain silly.

What is far more interesting are the comments and unverified facts in the readers' comments section of the article:
  • Over paid Union, fire them all, privatize it, 100K ticket collector, blah, blah blah ...
  • TTC's ~70% cost recover from users is better than most cities in North America
  • TTC's drivers' contract has a "GTA clause" which TTC drivers are guaranteed the best paid job in the GTA area.
  • TTC claims the the rider defraud rate is low, approximately 5%. Anyone who has use the system will question how on earth did they come up with that number with their stone age equipment? Survey?

Saturday, September 19, 2009

Previous PATH system variables

After using SETX commands on windows, I have accidentally set my system PATH to empty! The good news is your previous/other system PATH is available from the windows registry.

Simply run "regedit" and go to "HKLM\SYSTEM\ControlSetXXX\Control\Session Manager\Environment\Path" to retrieve the path in previous/other configurations.

Thursday, September 17, 2009

MS Windows' SETX command

I was sick of clicking to control panel > system > advance properties > environment variable just to update the system PATH variable. Fortunately, the new Vista build comes with the command SETX.

To add to the system path, now all I have to do is run the following command in an administrator mode command prompt:
SETX -m PATH "%PATH%;"
I also think it is available to XP user by downloading Windows XP Service Pack 2 Support Tools

Sunday, September 13, 2009

Freeundelete from OfficeRecovery.com

I got in to the bad habit of just doing straight file deletes on windows, skipping the recycling bin all together. To do this, simply hold down the shift key when you press the delete button. Explorer will still prompt you for a confirmation, but anyone who has done this enough times will have their muscle memory take over and hit enter key right after.

Unfortunately, I have done this to one of my pet project which I have been working for a few days now. Pet project also means no SCM, no backup. Lesson learned.

The good old undelete is no longer available from DOS! In a frantic search to recover the files, I came across the "FreeUndelete" tool available from OfficeRecovery.com, and it worked like a charm.

Although there are a few corrupted files, most of the files restored without any problems. I hope I don't have to use this tool every again.