I went to the Microsoft Tech Days conference 2010 earlier this week. The main focus of the conference was Sharepoint 2010 but there were some other interesting topics covered as well. The one topic that I found very interesting was about StreamInsight. StreamInsight is a new complex event processing (CEP) component that ships with SQL Server 2008 R2.
It will probably be easier to explain what this platform does with an example:
Imagine being asked how many red cars there are in a parking lot at a specific moment in time. You would have to walk through the parking lot and count all the red cars. Then, later, you are asked how many cars are in the parking lot again. So you walk through the parking lot again and count the cars again – the number might have changed since you last counted.
Now imagine the scenario differently. You sit at the entrance of the parking lot and each time a red car drives into the parking lot you write a +1 down on a writing pad. Each time one leaves you write a -1 down. Now whenever you are asked how many red cars there are in the parking lot you can add all the +1′s and subtract all the -1′s to get the result.
You can see that the second scenario is a lot more efficient than the first one.
Now for a real world example:
You have an e-commerce web site selling products online. The product sales are stored in the database. Analysing the sales data from the database in real time is process intensive and hurts the sites performance – which is not ideal. As in our parking lot example what if you add a component at the analogous “entrance of the database” that records sales events? Then you would be able to get almost real time sales information without affecting your site’s performance.
This is what StreamInsight was designed for. In simplified terms you tell it which events to record and it will give you information about these events without having to scan the database over and over.
So what does it take to implement?
StreamInsight is relatively new so at the moment Microsoft only provides you with the CEP engine, and you have to do everything else yourself. But I am sure that as time progress this will change.
After installing StreamInsight you would need to write some .Net code. In oversimplified terms you would need to inherit some classes and implement some interfaces. I am not going to get to technical so have a look at some samples here: http://blogs.msdn.com/streaminsight/archive/2009/09/18/updated-sample-package.aspx and here http://www.sqlservercentral.com/articles/StreamInsight/69593/
Your CEP events come from a data source. If you are using SQL Server 2008 R2 as your data source you have to write some Linq queries but you can also write your own data source. A data source could be anything from reading text files from a folder to receiving messages on a tcp connection to receiving messages from MSMQ queues. Your in-house developed systems could even be a data source.
Once you are done with this you would need to host your component in a custom windows service or something similar. The platform supports running in the SQL Server process as well.
Interestingly enough it ships with SQL Server but you don’t have to use it with SQL Server. You can also download and install a separate installation for it.
Overall I think it could be very useful for the correct scenario and I think I will definitely spend some more time investigating StreamInsight in greater detail in future.
Related Posts

