Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼


Continuous LINQ


We actually had an interesting time testing the performance of CLINQ. Without being bound to any GUI, we are able to pump over 1,000,000 changes per second into a source collection (with an upper cap on collection size to avoid running out of resources) with a large CPU load, and at 100,000 changes per second the load looked to be sustainable indefinitely.

The real tricky part came when trying to bind CLINQ to a WPF GUI. Thanks to Pavan Podila from the WPF Way (pavanpodila .spaces.live.com), we were able to track down a potentially fatal problem with data binding. In our ListBox, the height wasn't explicitly set, which prevented the item container style from being a VirtualizingStackPanel. Added to that was the template selector for picking the alternating grid style that could get invoked every tick for each of the hundreds of thousands of bound rows. Lesson learned: Make sure that your bound control remains virtualized and be very careful with item styles and item container styles when working with large data sets. Taking these precautions, we were able to get nearly the same throughput into CLINQ when databound as we were when using no GUI at all.

Using code like Listing Two, I've constructed a sample Order Book demo that lets you open windows into arbitrary symbols with simulated market data coming in at fixed intervals; see Figure 2.

[Click image to view at full size]

Figure 2: Sample Order Book Demo using CLINQ.

This window contains two listboxes. Each listbox is bound to a subset of market data. The BUY listbox is bound to the bid ticks for AAPL and the SELL listbox is bound to the ask ticks for AAPL. As new market data comes in to the central market data store (could be from network messages or, in my case, from a background thread on a timer), each set of query results is updated dynamically. If new market data for symbols other than AAPL comes in, the query results are not affected. If a new tick comes in for AAPL, it is placed in the appropriate listbox based on the side of the tick. All of that work, decision making, and data propagation is done automatically by the CLINQ language extension.

Fortunately, language extensions and CLINQ specifically can be used for pleasure as well as business. The following query is one that might be used in a strategy game to detect all nearby ships within your particular radar range:

_visibleObjects = 
  from radarObject in _rawRadar
   where radarObject
            <= RADAR_RADIUS 
   select radarObject;    

Such a game could receive a continuous stream of network messages from connected peer applications and store those messages in a ContinuousCollection (such as _rawRadar). The collection _visibleObjects would automatically update everytime an object in the _rawRadar list changed position or objects were added or removed.

Figure 3 shows the results of that query bound to a custom-style listbox to create a WPF-based radar view of nearby enemies.

[Click image to view at full size]

Figure 3: Having a little fun with CLINQ.


Continuous LINQ is just one expansion made possible through language extensions and LINQ on the .NET Framework 3.5. By embracing these features of the upcoming version of .NET, you can be ready to not only provide the most advanced features in your applications, but you can be assured that if there are domain-specific query features that you want in your application, you can create them yourself quickly and easily.

You can download the samples used in this article, as well as the CLINQ code itself, from my blog at dotnetaddict .dotnetdevelopersjournal.com.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.