Tech Tock

Time is of the essence.

WPF Range Slider

I’m using Marlon Grech’s Avalon Controls Library Range Slider.  It’s a 2 thumb slider with a middle section, so its really 3 thumb. The middle piece will slide the range up or down.

Its quite full featured and comes with a good demo app:


It does have a funky way of letting the lower bound go through the upper bound and vice versa:


This doesn’t happen in the sample app that comes with the controls, so it could just be my problem.

I’m considering using Josh Twist’s Range Slider.  It worked nicely on the first try, but its more of a demo than a full fledged control.



November 17, 2009 Posted by | Uncategorized | , , , , | Leave a comment

Top of the Charts – XCeed is fast

I’m doing an interesting charting project which will plot up to 500 thousand points, so I’m learning a bit about charts.  There seems to be about a million different vendors selling .Net charts, so there’s a lot to choose from.  The problem is there’s about a million different charts, so there’s too many to choose from.  I’ll tell about a couple I’ve used today.

I started with Chart FX, its incredibly feature rich and can do surface charts that we wanted.


Chart FX Surface Chart

Unfortunately, when throwing a few thousand points at it, the performance wasn’t stellar.

I just switched to XCeed.  It can do surface plots too, but its literally a thousand times faster at ploting points.  They say they use GDI, but I think there’s a flux capacitor hidden in there somewhere.  The only downside, is its not WPF, its windows forms.  That doesn’t seem like too much of an issue though.  The XCeed example code is a lot more focused and comprehensive than Chart FX, so far its been a win, but I’m just getting started with it.


XCeed Chart Surface Chart

The code I uploaded was a big hit, so here’s a quick and dirty app showing that the XCeed chart is 1000 times faster than Chart FX for plotting points:


XCeed Vs. Chart FX Point Charting Speed

With the same 5000 points given to both charts, XCeed charted in 9 ms and Chart FX took 3.5 seconds.  When resizing the form, Chart FX will freeze up again for 3.5 seconds.  The code is also a good sample of how to use a Windows Forms Control in a WPF application.  Click here for code, with the usual no warranties.

November 7, 2009 Posted by | Uncategorized | , , , , , , , , , , , | 6 Comments

So many quotes — All fake

I was interviewing with an interesting company the other day and I was asked how I would achieve the maximum throughput for a data feed of financial instrument quotes (not just stock quotes, but maybe foreign exchange, or bonds, etc. — its just an example, but I like to generalize :).

So we worked through the problem a little and as always there’s a couple things I left out that I could have said, but I think I did ok. My last statement was — doing it this way will be pretty good, but probably still not good enough.   There’s something in me that just wants to optimize and admitting “not good enough” bugs me.  The next day I was doing normal stuff and an interesting solution struck me out of the blue.  Multithreaded Stacks, enough said.

So I set out to make a demo program to test the theory and lo and behold, you can easily push 50,000 quotes per second through a WPF application!  50K!  On my crappy 2 year old duo 1.66GHZ/T5450.  I couldn’t believe it. Take that AJAX.

It took a while to setup the demo program and I didn’t get to anything I consider innovative or advanced, but I don’t think I’ll be needing any Multithreaded Stacks today.  Just seeing 50,000 quotes flowing through was enough for me.

Here’s the test program:
Mind you its just a demo. The quotes just consist of a random 3 letter id and a random price. But it does have a fun interactive graph thanks to Microsoft and the quotes do update in the grid. Actually all the numbers you can see in the pictures update through the automagic of WPF databinding. I even colored the quote process count with databinding.  This isn’t your daddy’s old Windows Forms, this is W P F.  This actually does more with less effort.  MS may have gotten something right.

The app is all about allowing the user to modify different parameters and combinations that may affect the system.


On the left side are all the parameter settings. I’ve really just been playing with the Calls Per Second and Quotes Per Call options.  I made 2 quote servers, one in WCF which is a little flaky at higher revs and one that runs a timer to send quotes from the ThreadPool within the application.  I did the WCF first, because it seemed to replicate the problem domain, but its not really germane and I’m moving away from it.

The timer tick, simulates a data push, that I’m calling a “Call”.  Within each data push, the number of quotes requested is sent.  Multiplying “Calls per sec” and “Quotes per call” together gives you the expected quotes that will be pushed at the interface. I say expected, because the implementation of the “quote generator” yields less than the expected amount.

The calls per second can only go so high before it stops increasing the quotes generated number which displays on the bottom statusbar. This is probably because it comes to the resolution limit of the simple System.Timers.Timer I’m using.  In the picture above, its set to 66 calls per second.  Setting it higher does not increase the number of quotes pushed.  Setting the quotes per call higher will increase the throughput and the UI for displaying quotes only gets sluggish over around 60K per second.  CPU usage at 55K quotes per second is only 30 – 40% so maybe I could even do better.

I just put the quote display in a simple ListView/Grid:


Those quotes are jumpin’ 5 times per second.  Take my word or download the code and see for yourself.


This statusbar shows Snapshot Quotes Per Second (TPS — I use the word Tick and Quote interchangeably — bad habit) at 59,165, Expected Pushed Quotes at 103,563 and Total Processed and Total Served (Pushed) Quotes within 1000 of each other.  Either the consumer is 1/60 of a second behind the producer or just as likely there’s a synchronization issue between those 2 numbers.

You can download the code here and run in Visual Studio or stand alone.  Just hit the Start button to see things go.  Of course the code is AS IS, NO WARRANTY and freely distributable.  See here for additional warnings.

If anybody’s interested I’ll do some more writeups on what’s going on in the code.

September 28, 2009 Posted by | Uncategorized | , , , , , , , , , , , | 3 Comments