The most exciting thing about this world is its ever changing quality.

Wednesday, June 03, 2009

VS2010 and .Net 4.0 Beta 1 - first taste!

  • Parallel programming
  • Just to be clear, similar to parallel python, JavaSpaces, this package is a MS way of dealing with multi-core age.

      • Task Parallel Library (TPL) - Basic abstraction is Task (Tasks <> Threads). System.Threading.Parallel, System.Threading.Tasks. These types rely on a new Task Scheduler (replacing Task Manager in previous drops) that is integrated with the .NET ThreadPool. Here is a good summary from MS.
        • For example, Parallel.For() will automatically partitions the work into tasks based on the number of processors on the machine. Parallel class provides method-based parallel implementations of for and foreach loops. (In data parallel operations , the source collection is partitioned so that multiple threads can operate on different segments concurrently.) When a parallel loop runs, the TPL partitions the data source so that the loop can operate on multiple parts concurrently. Behind the scenes, the Task Scheduler partitions the task based on system resources and workload. When possible, the scheduler redistributes work among multiple threads and processors if the workload becomes unbalanced. (You can control each involved thread's state via ParallelState.). Here I stole an image from Aviad.
        • By using Parallel.Invoke() to invoke any number of asynchronous, concurrent operations with a single method call.
        • Manipulate the Task explicitly.
        • Apparently, you can write your own Task Scheduler or Partitioner if you are really keen at scheduling.

      • Parallel LINQ (PLINQ) for .NET - A parallel implementation of LINQ to Objects, ParallelEnumerable vs. IEnumerable.
        • PLINQ runtime library analyses the overall structure of the query whether it is likely to yield speed by parallelism. PLINQ partitions the source sequence into tasks that can be run concurrently. If it is not safe to parallelize a query, PLINQ simply runs the query sequentially.You can use the WithExecutionMode method to instruct PLINQ to select the parallel algorithm.
        • Parallel Performance Analyzer in Visual Studio Team Server can be used to compare the performance of various queries, to locate processing bottlenecks, and to determine whether your query is running in parallel or sequentially.
        • In sequential LINQ queries, execution is deferred until the query is enumerated either in a foreach loop or by invoking a method such as ToList, ToArray orToDictionary. In PLINQ, foreach itself does not run in parallel and it therefore requires that the output from all parallel tasks be merged back into the thread on which the loop is running. In PLINQ, you can use foreach when you need to preserve the final ordering of the query results. For faster query execution when order preservation is not required and when the processing of the results can itself be parallelized, use the ParallelEnumerable.ForAll() method to execute a PLINQ query without performing final merge step.
        • Parallel query CAN be cancelled. (Thanks God for that!). It could be done via WithCancellation method and CancellationTokenSource class.
        • Aggregated Exceptions (To catch exceptions thrown from user code via PLINQ, you must uncheck the "Enable Just My Code" checkbox under Tools, Options, Debugging, General).

      • Concurrency debugging and profiling tools
        • New Parallel Stacks window and Parallel Tasks window. Of course Task is another level on top of thread, I find these windows are useful if you are really interested in Task <-> Thread relationship in run time, and a very good visual tree presentation of all threads. Unfortunately, you can't freeze a Task. Here is a nice walkthrough.
        • Visual Studio Team System Developer Edition Profiling Tools. Very nice set of tools to create performance profile for your applications. No need for external tool such as IBM Rational PurifyPlus. You can profile CPU timing, memory usage and even able to look at the locking time among different threads. Also, a nice report plugin can make the managers happy too, which is always a bonus :). With built-in code metrics and analysis tool. It looks like MS is finally taking coding seriously. The dependency walker has finally evolved into 21st century - a nice tree structure, by assembly, namespace and class. I do hope CLRProfiler is going to be supported still though.
      • Coordination Data Structures
        • System.Collections.Concurrent, the one I have been long waiting for! You don't have to worry about locking for using generics as it was in previous versions. This is how easy to implement a standard P&S. There are also concurrent queue, stack, FIFO, Dictionary classes available.
        • The new synchronization primitives in the System.Threading name-space enable fine-grained concurrency (spinlock) and faster performance by avoiding expensive locking mechanisms found in legacy multi-threading code. New types such as Barrier and CountdownEvent are very useful. It starts to get clearer that as a developer, you are encourage to draw the picture of multiple concurrent running streams in mind and really sure about the dynamic data flows.
        • With lazy initialization, the memory for an object is not allocated until it is first accessed. Lazy initialization can improve performance by spreading object allocations evenly across the lifetime of a program. You can enable lazy initialization for any custom type by wrapping the type Lazy(T). You can use LazyExecutionMode to specify the initialisation needs further

        • Office Development
          • You can now create either document-level or application-level project for MS Office suite within VS IDE. Supposedly you have to be familiar with different Object Model in various office applications such as Excel, Word, Visio etc. (For long time, I have always wanted to be able to reuse some nice features built in Visio elsewhere. However this was very difficult until VS2008 (well, not before MS publishes Visio interop assembly reference documentation.) ) Kiss goodbye to the old VBA and macroes!



      • Azure cloud development - With Azure cloud development kit. You will have to move to at least Vista SP1 though, which is NOT a good release!
      Visual studio 2010 comes with many tools to support apps development, build and deployment on different layers, via individual SDK for various Services.
        • A bit of background on Azure cloud from MS:
          • Layer zero (not on this slide) is Microsoft’s Global Foundational Services. GFS is the lowest level of the software that interfaces directly with the servers.
          • Layer one is the base Azure operating system. This is what used to be codenamed Red Dog. Red Dog was designed by a team of operating-system experts at Microsoft, led by Amitabh Srivastava, Dave Cutler, father of VMS and Windows NT, focusing heavily on how the hypervisor/virtulisation technology could be made to scale across datacenter servers. Red Dog, a Microsoft-hosted cloud, consists of Storage (like a file system), a management system for modeling/deploying and provisioning, virtualised computation/VM, and a development environment, which allows developers to emulate Red Dog on their desktops and plug in Visual Studio, Eclipse or other tools to write cloud apps against it.
          • Layer two is the set of building block services that run on top of Azure. Developers are not required to use these services and will be able to mix and match among them. The initial set of services include Live Services (the Live Mesh platform), SQL Server Data Services, .Net Services, SharePoint Services and Dynamics CRM Services. Developers will be able to build on top of these lower-level services when constructing cloud apps. (Windows Strata = Azure platform = Layer one + Layer two)
          • Layer three are the Azure-hosted applications, i.e. SharePoint Online, Exchange Online, Dynamics CRM Online.



      • Extension for WCF & WF
        • Service discovery - To discover the available services on the network seems to be easiest extension step to take.
        • Built-in tracking and monitoring
        • Workflow Designer Programming Model . I copied a couple of workflow models here. As you will find out, VS 2010 is pretty good at providing a visual presentation of a workflow, as long as you are clear about it yourself :)

      • functional programming - the F# programming language. (I simply have not got up to speed with MS functional language as yet!)

      After this blog was first written, I have picked more and more nice things. I can not go over all of them but I will try to update this list as I go along.

      - Dynamic type, which allows you to declare type to be resolved at runtime. This finally enables MS stuff like C#, VB can talk to others like Python, Ruby etc. via DLR.
      - IDE extension. MS started to emphasize the IDE open extentibility from VS2008 based on add-in style. VS2010 introduced MEF and Dashboad is just so coooool. It even intergrated with Twitter.

      No comments: