I did some investigation of the new System.Collections.Concurrent namespace today, because I considered using them for my private server project. I know collections are not the place to put synchronization, but in my use case I believe it’s justified, as it is the classic producer/consumer pattern.
My custom server is built to handle a lot of concurrent tcp/ip connections and receive and send data constantly.
It will also likely run on machines with at least 8 cores, possibly a lot more. Thus I need a collection ( mostly a simple queue ) that is high performance and scales well with the number of physical cores. However after looking at the implementation of ConcurrentQueue in the .NET 4.0 Beta1 release I had to rule them out. While certainly a very clever piece of code, they still rely on the the dreaded monitor and spinlocks.
Therefore as soon as you go over the 4 core mark ( depending CPU architecture of course ) they will not scale well. This is of course no problem for software that just uses them for a little amount of data, but in my server they are under high load all the time.
So for now I still have to use my own queue that uses atomic cpu operations for doing implicit synchronization. While this lock free queue implementation certainly has worse performance, it scales very nicely on more than 4 cores under high load.
For C# we have of course the new dynamic dispatch features, as well as optional and named parameters, and better co/contravariance support for generics. I still don’t like dynamic dispatch support, simply because I think it will be used for all the wrong reasons, and because it throws out a lot of the investment in static source code analysis technology, and proofing program correctness. On the runtime side of things, of course we have additions to WCF/WPF a completly rewritten Workflow Foundation, and many other small things like a few conveniance methods ( string.IsNullOrWhiteSpace ). The Task Parallel library is a godsend, but I am still in fear of it’s usage patterns. I see a lot of developers who are not experienced in multithreading just use things like Parallel.ForEach or PLINQ because it’s so damn easy thereby ignoring the concurrency issues, producing code that will just fail at unpredictable times.
At least we have some by default threadsafe collections now, but the performance implications of those must not be overlooked, collections are rarely the right place for some last effort “catch all” synchronization.
Things like native support for Memory Mapped files, the inclusion of Code Contracts which were previously available as an addon, as well as conveniance data structures like tuples or sets round off the framework itself.
The client GC can now do parallel garbage collections under certain circumstances ( during full collections a certain number of allocations can be still be done while the collection is running ).
The server GC does not support this apparently because of lack of development time, which is really not nice, since especially there it would have resolved certain issues in long running applications that have bitten me in the past.
Last but not least ADO.NET Entity Framework is in it’s second release, supports forward engineering finally, and generally seems much more mature now, time to take it for a spin in the next few days. All in all a great release, and the nice WPF UI of Visual Studio just make working that little extra spicy, so in conclusion: I really like it !
Thanks to the new WPF based GUI of Visual Studio 2010 there are some noticeable cosmetic improvements. Most of you might already know this, but the text editor supports arbitrary zooming now. Simply hold down your CTRL key and use the mouse wheel to zoom in and out. Thanks to the much improved text rendering support in WPF ( ClearType and sophisticated hardware anti aliasing using shaders ) the results are quite gorgeous in my opinion and make for great presentations on large displays or projector screens:
The theme i am using is Vibrant Ink by the way, a quite natural port of the same theme from TextMate.
Recently a slew of new web “RIA” technologies have been brewing up a storm. Adobe released Flash Player 10 with a quite capable JIT compiler and AS3 which now actually can be called a real programming language. Microsoft is hot on it’s heels with Silverlight 3.0 Beta, which I personally like much better since it’s more of a developers technology gone design than the other way around. Both technologies now use 3D hardware acceleration for their rendering, and both expose a low level API for defining pixel shaders. Right now both implementations only use a software implementation of the pixel shader pipeline, without using the GPU for what it was actually designed for. At least there is still hope that Microsoft might support GPU acceleration with the RTM of Silverlight 3. Adobe cites concerns of platform compatibility for not using GPU shaders, but come on, capable hardware has been on the market since 2002 and even the most low end embedded GPUs in Laptops support it ( even Windows Vista and above need at least PS2.0 support for their Aero theme ). How hard can it be to check if capable OpenGL or DirectX drivers are available and then using the native pixel shader capabilities ? The drivers have been quite stable for the last 5 years in that regard, and nobody prohibits you from falling back to software emulation if you deem the installed hardware not compatible enough.. Since they actually already go through OpenGL or DirectX for their rendering, there is not that much investment into developing a new rendering pipeline too. Hopefully both vendors will soon integrate that particular feature, since I already have some very weird dreams about what we could do with it.
Today I launched my new blog. The last few years have been quite a ride and many things have happened, both personally and professionally. My friends probably know what I am talking about on the personal front, but everything is on the up and up again, and I am looking forward to a productive 2009. Professionally since I am currently working on a long term contract for an Austrian company, my partner and I have closed down our consulting business simply because there is no time left to tackle any other projects right now. Of course I am still a 100 % geek, and thus you will hopefully find regular updates about things I play with in my little spare time here.
subscribe via RSS