Monday 27 April 2009

Live Mesh Part 2

In my previous entry about Live Mesh I mentioned that you could use it to transfer data to and from the cloud in addition to straightforward file-sync operations.

To develop Mesh enabled applications you need to sign up to the Mesh developer site, but this is straightforward. You do need to remove the Live Mesh client to install the Live Framework Client and connect to https://developer.mesh-ctp.com rather than http://www.mesh.com, but presumably this will be rectified for final release You can download the SDK from here.

In the Live Framework SDK there are samples to demonstrate Mesh functionality. The Live Folders sample creates, edits and deletes files from the Mesh. These files and folders appear exactly the same as the synchronized folders created with Live Mesh. I would expect that long term you could synchronize with these folders, but at the moment the Live Framework Client is sandboxed and does not support the synchronization or remote control features of Live Mesh.

The following code creates a Live Mesh folder and you can see that the resource type is LIVE_MESH_FOLDER:

public static string CreateRootFolder(Mesh mesh, string title)

{

// Check if a folder with the same name exists.

foreach (MeshObject oneObject in mesh.MeshObjects.Entries)

{

if (oneObject.Resource.Title.Equals(title))

{

return "Folder already Exists!!!";

}

}

// Create folder object

MeshObject meshObject = new MeshObject(title);

// It is a mesh folder

meshObject.Resource.Type = MeshConstants.LIVE_MESH_FOLDER;

// Add folder to collection of mesh objects

mesh.MeshObjects.Add(ref meshObject);

// Create feed for files (required)

DataFeed fileDataFeed = new DataFeed(MeshConstants.LIVE_MESH_FILES);

// Set type and handler type (required)

fileDataFeed.Resource.Type = MeshConstants.LIVE_MESH_FILES;

fileDataFeed.Resource.HandlerType = MeshConstants.FILE_HANDLER_TYPE;

// Add new data feeds to collection

meshObject.DataFeeds.Add(ref fileDataFeed);

//this.LoadMeshObjects();

return "Root folder " + title + " created successfully";

}


There is also a Project Manager sample in the SDK. This is a simple application to create projects and milestones. It creates non-standard objects in Mesh. As you can see in the project code below, you can create your own class of object and are not constrained by standard folders and files:


///
/// UUID of the parent MeshObject
///
[DataMember]
public string MOID { get; set; }
///
/// Title of the milestone (during save/update, this matches MeshObject.Resource.Title,
/// but is stored here when the custom object is databound instead of the resource)
///
[DataMember]
public string Title { get; set; }
///
/// Date when project will be started
///
[DataMember]
public DateTime KickOffDate { get; set; }
///
/// Estimated Date for Completion
///
[DataMember]
public DateTime CompletionDate { get; set; }
///
/// Date when project was shipped
///
[DataMember]
public DateTime ShippedDate { get; set; }
///
/// Description of Project
///
[DataMember]
public string Description { get; set; }


When you deploy a Mesh application it appears both on the users Live Mesh website and also as a shortcut on their desktop. In this way, a user can just run the app without any knowledge of Live Mesh. Furthermore, because the data is synchronized between the local machine and the cloud, they can run the application when they are disconnected and it will automatically synchronize when connected although there is no conflict resolution built in.

This does come with some caveats. This is currently CTP and is not fully functional. As previously mentioned the developer environment does not currently integrate with the Live Mesh client. Also every time I tried to run an application from the desktop it said it was waiting for me to sign in with no opportunity for me to do so and regardless of whether I was signed in or not. There is also a risk that this is a solution waiting for a problem. It looks interesting, it’s quick and straightforward to Mesh enable applications, but there needs to be a compelling requirement for this to go beyond the trying out samples stage and into developing real applications.


In the code samples above, these are just snippets of the complete solution, but you can see that Live Mesh has both straightforward user file and folder synchronization, as well as an API to enable you to create a cloud-based solution.
As a final note, I looked into this as a way to synchronize favorites in IE8. You can now do this by signing up to SkyDrive and reinstalling the Live Toolbar.

Monday 20 April 2009

Table and Index Partitioning in SQL Server 2008 Enterprise Edition

Introduction

SQL Server 2008 Enterprise enables you to horizontally partition individual tables and indexes so that data storage is spread over multiple drives. Horizontal partitioning is the process of dividing the data in a table or index by rows, so that some of the rows are contained in one location, some in a second location, some in a third, and so on. For example, with SQL Server 2008 Enterprise, you can partition large tables by date, so that each partition stores rows that correspond to a specific time period.
Partitioning has multiple benefits:
• Firstly, it enables you to make efficient use of the available disk capacity by controlling the placement of data from a single table or index across multiple disks. Partitions are mapped to filegroups, which in turn contain the files that hold the actual data.
• Secondly, partitioning enables flexible management of larger tables, for example by enabling you to backup a just subset of the rows in a table. Because partitions are mapped to filegroups, you can use SQL Server backup to backup just the filegroups that contain changed data.
• Thirdly, partitioning can make the loading new data a much faster procedure using the SWITCH option, which we’ll discuss shortly.
• Finally, and perhaps most significantly, partitioning can improve query response times for users.

Partition switching

Faster data loading can be achieved when you use the SWITCH clause of the ALTER TABLE statement. This enables you to swap a populated table or partition with an empty table or partition, provided that the they both have the same design structure, including the number, order, naming, and nullability of columns. For example, you could load new data by switching a populated table into a partitioned table and switching a named partition – say, partition 1 - out of that table. All that actually happens with this operation is that the metadata of the table and partition, including the table name and the partition name, are switched. No data actually needs to be moved, and as a result the process is very quick. You can also use the ALTER PARTITION FUNCTION statement with the MERGE and SPLIT clauses to merge two partitions together and to split an existing partition.

Performance improvements

Partitioning improves query response times on partitioned tables when users issues queries that filter rows by date, as is very often the case in large databases such as data warehouses. This is because SQL Server only needs to search through the partition or partitions that contain the relevant rows, which is more efficient. You can also limit lock escalation to the partition rather than the table, reducing the risk of blocking and deadlocking.
SQL Server 2008 offers a considerable improvement in performance over SQL Server 2005 for queries against partitioned tables that run on multiprocessor systems. In SQL Server 2005, if a user issued a query against a partitioned table and the query touched only one of the partitions in that table, all available threads could be allocated to that query, resulting in fast response times. If, however, the query touched more than one partition, then only one thread could be allocated per partition in the query, resulting in comparatively slower response times, particularly in cases where the majority of the data resided in just one of the partitions. This behaviour was by design and was actually intended to provide improved performance in the special case of a query touching only one partition, but from the users’ point of view, it sometimes meant that execution times seemed unpredictable. SQL Server 2008 addresses this issue with improved partitioned table parallelism. Queries that touch a single partition behave in the same way as they do in SQL Server 2005, and all available threads are allocated to the query. Queries that touch multiple partitions now have all available threads allocated to them, with the threads being distributed in a round-robin fashion. For example, on a server that has four cores, a query that touches one partition will have all four threads allocated to it. A query that touches two partitions will have all four allocated again, with two available per partition. In SQL Server 2005, this second query would only have had one thread available per partition. This new behaviour can result in drastic improvements in performance, with some queries running ten to fifteen times faster.

Summary

Table and index partitioning is a powerful feature that offers many benefits to administrators who manage large databases. SQL Server 2008’s enhanced partitioning delivers impressive performance on multi-core servers, enabling you to get more out of your existing hardware.

Monday 6 April 2009

Live Mesh

I came across a new Windows Live component the other day called Live Mesh
when searching for a way to synchronize my favorites. In IE7 you could synchronize favorites with Live Favorites. It worked pretty well, although by no means perfectly. This functionality was removed from IE8, which annoyed me somewhat. I work from home most of the time, but occasionally go into the office and take a laptop. Virtually all documents I use are checked into SharePoint, so I don’t lose any data when I switch machines, however there are always useful bits and pieces that I pick up on the Web and I usually just add these to favorites. This is where the upgrade to IE8 is giving me problems. Not insurmountable, obviously, but I want everything to work smoothly. A blogger called Laurent Duveau has used Live Mesh to do just this. Looking further into Live Mesh made me realise its other capabilities. It interested me through a connection with the Azure Services Platform, of which it is a part, and through its data synchronization and remote control functionality.
Live Mesh allows you to synchronize folders with the cloud. You set up a device and then simply right click a folder to begin synchronizing data. This sounds a bit like functionality already provided by Live Sync and SkyDrive, however Live Sync requires both computers to be connected at the same time and SkyDrive is just online storage with no more advanced functionality.


So what more does Live Mesh offer? Well, for a start, the whole process is automatic and painless. You add a folder and the folder is synched. You can add another device and keep the data synched across multiple devices. These devices will include Windows Mobile and Apple Macs in the future. The data is both held locally, so that it can be accessed offline, and in the cloud, so that it can be accessed anywhere. This solved my favorites problem, but also made me curious as to the capabilities of Live Mesh.

Other features include remote desktop. Now not only do I have all my data synchronized, I can also connect to my desktop PC from anywhere. So far, these are all features available with the use of a few tools, but there is another trick up the Live Mesh sleeve. There is a Live Framework with various APIs including .NET, Silverlight and JavaScript to use Live Mesh services. This not only allows you to share folders as you normally would with Live Mesh, but also allows any data to be stored and synchronized between devices. I’ll leave the Live Framework for another day, but it appears to offer interesting possibilities.
Of course, this is a beta, but when the minor errors are ironed out this could be a valuable data synchronization tool.