Griffith's blog

Node.JS

Griffith's picture

Node.js is an evented I/O framework built on top of Google’s V8 JavaScript engine; its design is influenced by systems like Ruby’s Event Machine or Python’s Twisted. Node’s goal is to provide an easy way to build high performance, real-time and scalable web applications.

JavaScript has traditionally only run in the web browser. In recent years, projects such as CommonJS, Jaxer and Narwhal reflect the considerable interest in bringing JavaScript into the server side as well. In contrast to these concurrency models where OS threads are employed, Node is event-based rather than thread based. Thread based model often has the disadvantage of not scaling well with many long-lived connections necessary in real-time applications, becoming relatively inefficient and complex.
Node takes an alternative approach by telling the OS that it should be notified when a new connection is made, and then it goes to sleep. In the event of a new connection, the callback is executed; each connection is only a small heap allocation. This results in a much better memory efficiency under high-loads than systems which allocated 2mb thread stacks for each connection. Furthermore, Node is free of locks: almost no function in Node directly performs I/O, so the process never blocks. The programmers won’t need to worry about dead-locking the process.

Node’ advantage comes from the fact that most thread based models spend the majority of their time waiting for I/O operations which are much slower than memory operations. Node’s I/O operations are asynchronous, which means that it can continue to process incoming requests while the I/O operation is taking place.

The following is an example of a web server written in Node which responds with “Hello World” for every request.

var sys = require(‘sys’), http = require(‘http’);

http.createServer(function(request, response) {
response.writeHead(200, {‘Content-Type’: ‘text/plain’});
res.end(‘Hello World\n’);
}).listen(8124);

sys.puts(‘Server running at http://127.0.0.1:8124’);

This simple script imports the sys and http modules, and creates an HTTP server. The anonymous functions passed to http.createServer will be called every time a request is made to the server.

Node is a very exciting technology built on top of another powerful technology, V8. It has gathered a lot of attention within the technology community, and with its great module system, there are many third party modules available for just about everything.

SimpleDB

Griffith's picture

Amazon SimpleDB is another service from Amazon that uses its Dynamo technology. With SimpleDB, Amazon has at last incorporated database as part of the company's web services. SimpleDB is currently available to the public as a beta service, with several technical limitations, including:
A single query will timeout after 5 seconds.
Only strings are available as data type.
Data query, write, retrieval are type casted into strings.
Strings cannot have more than 1,024 characters.
An item can have a maximum of 256 attributes.
In open beta testing, a SimpleDB domain is capped at 10GB capacity.

SimpleDB is not RDBMS (relational database management system), but it rather operates in a far simpler fashion. Amazon SimpleDB's data are stored as Domain → PKeys, PKeys → Attributes, and within each attribute, Key → Value. For instance:

Key:1
Attributes:
Category: Company
Name: Cellopoint
Website: http://www.cellopoint.com

Being a database, SimpleDB comes with its own querying API.

Installing the PHP Library for Amazon SimpleDB:
1. Download PHP Library for Amazon SimpleDB at Amazon Web Services (AWS) website.
2. Extract the file.
3. Request and retrieve Access Key ID and Secret Access Key from AWS.

Client connection testing:
1. cd to PHP Library for Amazon SimpleDB directory.
2. vim test_client.php
<?php
$AWS_ACCESS_KEY_ID = …
$AWS_SECRET_ACCESS_KEY = …

require_once('Amazon/SimpleDB/Mock.php');
$service = new Amazon_SimpleDB_Mock();

require_once('Amazon/SimpleDB/Client.php');
$service = new Amazon_SimpleDB_Client($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY);
?>
3. Run test_client.php

Inserting data:
1. PHP aplication
$domain= “MyDomain”;
$item = “Product01”;

$attr1 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attr1->withName('Category')->withValue('Device');

$attr2 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attr2->withName('Name')->withValue('D01');

$attrArr = array($attr1, $attr2);

$request = new Amazon_SimpleDB_Model_PutAttributesRequest();
$request->withDomainName($domain)->withItemName($item)->setAttribute($attrArr);

invokePutAttributes($service, $request);
2. Service response

Service Response
==============================
PutAttributesResponse
ResponseMetadata
RequestId
...
BoxUsage

Retrieving data:
1. PHP application
$request = new Amazon_SimpleDB_Model_QueryRequest();
$request->setDomainName('MyDomain');
$request->setQueryExpression(“['Category' = 'Device']”);

invokeQuery($service, $request);
2. Service response
GetAttributesResponse
GetAttributesResult
Attribute
Name
Category
Value
Device

ResponseMetadata
RequestId

BoxUsage
..

Google Omaha

Griffith's picture

Google client products are capable of updating themselves to a newer version without end-user intervention. This is known as “auto-updating.”

Most of Google client products possess the auto-update feature, but with different implementation. Some has their own auto-update solutions, while others utilize the common auto-updater code and the common auto-updater server.

Google sought for client products to minimize code duplication and avoid maintaining multiple servers that essentially perform identical functionality. As result they considered unifying all client products under a single auto-update solution. This decision was influenced by the fact the evolution of Microsoft Windows, which made this unification almost mandatory. Window Vista has a strict security model that restricts the ability of most applications on a machine to perform system-changing activities, including: modifying the Windows registry, writing to the Program Files directory, and in some cases writing any persistent change to the system at all. The update of an installed program requires all these modifications, which would lead traditional auto-updating to fail on Microsoft Vista.

The lack of shared code brought another issue: each auto-update implementation had its own subset of desired features. Many of them failed to have multiple update tracks, or define a consistent versioning mechanism. Code unification allowed Google to deploy a rich set of auto-update capabilities to all its client applications.

As the number of Google applications increased, the improvement of the overall install user experience became increasingly desirable. Traditionally, the browser would prompt the end-user with a series of technical and confusing dialogs which encouraged the user to abandon their installation. Then the user was led to a wizard filled with choices that they did not need to know or know how to decide amongst. These result in a bad user experience during the product installation process.

In order to meet all the requirements and challenges mentioned above, Google developed a shared client infrastructure that handles all installation and auto-updating tasks for Google Windows client products. This client communicated with a single Google auto-update server. This server, together with the client, is named Google Update. And the project is known as Omaha.

jQTouch

Griffith's picture

jQTouch is a jQuery plugin with native animations, automatic navigation, and themes for mobile WebKit browsers such as iPhone, Nexus One, and Palm Pre. jQuery is a fast and concise JavaScript library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. The combination of jQuery and jQTouch allows any web application developer with little experience in jQuery to build mobile applications.

As an example, consider a simple home panel. This is the HTML for Home panel:

<html>
<head>
<title>To-Do</title>
<link type=”text/css” rel=”stylesheet” media=”screen” href=”jqtouch/jqtouch.css”>
<link type=”text/css” rel=”stylesheet” media=”screen” href=”themes/jqt/theme.css”>
<script type=”text/javascript” src=”jqtouch/jquery.js”></script>
<script type=”text/javascript” src=”jqtouch/jqtouch.js”></script>
<script type=”text/javascript”>
var jQT = $.jQTouch({
icon: ‘todo.png’,
statusBar: ‘black’
});
</script>
</head>
<body>
<div id=”home”>
<div class=”toolbar”>
<h1>To-do</h1>
</div>
<ul class=”edgetoedge”>
<li class=”arrow”><a href=”#about”>About To-Do</a></li>
</ul>
</div>
<div id=”about”>
<div class=”toolbar”>
<h1>About To-Do</h1>
<a class=”back” href=”#”>Back</a>
</div>
</div>
</body>
</html>

The HTML is simple, its body composed of two divs as children. The integration with jQuery and jQTouch is in the HTML head. An analysis of the HTML document head:

• jqtouch.css is a required file, defining structural design rules specific to mobile devices, including animation handling, and orientation.
• theme.css is a CSS theme included with jQTouch.
• jquery.js is the core file of jQuery framework. jQTouch requires jQuery, and it comes with its own copy of jQuery.
• jqtouch.js is the core file of jQTouch.
• variable jQT is the jQTouch initiated object. Two properties are defined in the Home panel: icon and statusBar.

jQTouch has several properties that allow users to customize the behavior and look of their apps. In this case, icon indicated the custom Web Clip icon, and statusBar controls the color of the strip at the top of the app in full screen mode.

All in all, jQTouch is a framework that facilitates developers to add native-looking animations to a web app.