Performance of ALTER TABLE
April 30th, 2007
Reading a post from Diego Dagum’s blog I remembered about an interesting topic related to SaaS. In his article, Diego, talks about an experience he has with a customer that developed an application for multiple customers (multi-tenant). They had a performance issue because they were using shared-schema (i.e. extended fields stored in a separate table as rows pointing to the shared data table).
Figure 1 - Shared schema approach (Multi Tenant Data Architecture paper)
Diego and his colleague tried to convince the customer to move to the separate schema approach. In this approach each customer has its own table and every time he wants to customize an ALTER TABLE is used)
The customer immediately refused the ALTER TABLE because of the myth that altering the schema of a table is a *HEAVY *operation.
It seems the story ends with the customer afraid to go with that approach, but this is a very interesting issue for multi-tenant applications. Modern databases implement ALTER TABLE very fast depending on the structure of the table and the change that wants to be done.
Let’s enumerate the common scenarios and how SQL Server manage this:
- Adding a column: when you add a *NULLable* column to a table only metadata changes (syscolumns).
- Dropping a column: the same applies when you drop a column
- Changing a data type: this is tricky. Changing the data type to something larger should only be metadata change and the physical change in the rows should not happen until the rows are updated. When changing the data type to something smaller, SQL Server will have to validate to make sure current data fits in the smaller type
There is an interesting (paid) article that explore the insides of ALTER TABLE: http://www.sqlmag.com/Article/ArticleID/40538/sql_server_40538.html
PS: Talking about Diego, if you read Spanish make sure to read his architecture bulletins. There are already 3 of them:
Abril 19, Boletin Oficial de Arquitectura #3
The outlook bar moved to www.codeplex.com/cabextensions
April 29th, 2007
I’ve found some time to grab the outlook bar, fix some bugs and create a quickstart outlook with it.
Figure 1 - Outlook created with CAB and Outlook Bar Workspace
Figure 2 - Calendar module
I’ve started a project con codeplex to host extensions for CAB and SCSF. If you are interested in participate, fix bugs, add new stuff, let me know.
Splitter workflow - Workflow Services aka "Silver" WF 3.5
April 27th, 2007
While reviewing DinnerNow.net I found an interesting workflow implementation.
Scenario:
A customer place an order for food from multiple restaurants. DinnerNow acts as a hub that will grab the order, will check each item and will group them by restaurant.
How this is implemented? They have two workflows:
- Sequential: this workflow receive a customer order, splits and gorup the order items within a set of restaurant orders. For each restaurant order a state machine workflow is started.
- State machine: this workflow represents a single order workflow (open, ready for pickup, delivered, payed, complete)
You can download DinnerNow today and see this workinf in NET 3.0.
We’ve been working on some training material lately to show how to do this using NET 3.5. There is a new feature code-named "Silver" (read more on Matt Winkler blog) that basically are a couple of activities to integrate Workflow Foundation with Windows Communication Foundation: the ReceiveActivity and SendActivity.
The following illustration shows how to implement a splitter workflow exposed as a service with WCF:
This workflow is hosted using the new WorkflowServiceHost (that derives from the regular WCF ServiceHost). This new host will read the workflow and will associate the endpoints configured with specific contracts with the workflow implementation.
If you do the analogy with WCF, in WCF you create a service interface and then the implementation with a regular c# class. With Workflow Services you create the interface but the implementation is the workflow itself! And even more easy you can embed the contract metadata in the workflow and the host will read it and associate them with the endpoints.
When a client make a call to the PlaceOrder operation of the IOrderWorkflowService, a new workflow will be started (there is a property in the ReceiveActivity called CanCreateInstance to tell the runtime to do so). This call will be syncrounous but the workflow will start running and will split the orders.
The replicator is similar to a "foreach" statement but it can execute either in sequential or paralel. The first activity that executes is a "SendActivity". This is the counter part of the other activity and will allow calling a service. Either we can call a regular service or we can call another workflow that has a ReceiveActivity listening. And that is what we are doing here: a workflow conversation where the sequential calls the state and when the state finishes it will call the sequential again.
Of course, you will need to somehow manage a context between calls. If not how the workflow knows if you are refering to instance A or instance B.
We are provided with a new set of bindings that allow to do that (netTcpContextBinding and wsHttpContextBinding). This bindings provide a property to access the context:
proxy.PlaceOrder(order);
IContextManager cm = proxy.InnerChannel.GetProperty();
IDictionary<XmlQualifiedName, string> context = cm.GetContext();
This context will have the workflow instance id of the recently created workflow. You can add things to the context and read them on the client and the workflow.
IContextManager cm = proxy.InnerChannel.GetProperty(); cm.SetContext(context); proxy.UpdateShipping();
In the case of the child state machine workflow, how do we know which sequential workflow to return after we finish the order process? Simply, we bind the context on the ReceiveActivity of the initial state to a workflow depdendency property. This context is the one sent by the SendActivity of the parent workflow. Then when we get to the complete state we bind the saved context to the SendActivity.
More info:
Ezequiel Morito posted on his blog a hello world tutorial in spanish for the march ctp
VSIP Software Factory
April 9th, 2007
My good friend Pablo Galiano has been working on a VSIP software factory lately. I had never did a VSIP package myself, but it seems like a lot of work to do simple things like adding a command. This software factory provides a bunch of recipes (developed with GAX/GAT) that will do all the dirty job for you.
Check it out here: http://www.codeplex.com/vsipfactory