11 Mar 2010 @ 1:15 AM 

Today, a technology newsletter carried with an article about SCA (Service Component Architecture) which is outshone at IBM campus along with BEA.  Is it a another SOA specification?  Is it a SOA framework? or, alternate to SOA?  Michael Rowley who is the author/architect/inventor of this said that it depends.  Confused.  Yes, it has been mentioned that SOA is hyped much and many of the things are futile.

Concept behind SCA

Following are the key aspects of SCA:

  • Services – a set of operations that perform logically related tasks
  • Components – contains the implementation and configuration of services
  • Composites – responsible for configuring services
  • Domain – A physical environment where the components will be hosted for consumption

A service contains a service contract and address.  Service contract specifies the operations available in the service, the inputs for which to operate and the promised outputs.  Service address provides where the service contract is available for consumption.  Components is nothing but C++ libraries or Java JARs.  Composites are XML file which contains the map between service contract and its implementation.  The domain enables to manage the components and apply policies for their access.  It provides common communication infrastructure and extensibility stuffs.

Technology behind SCA

Although in the specification it has been mentioned that SCA is technology and language independant, it is majorly on Java.  It has been mentioned that SCA is a concept as well as a framework but does not contains anything for presentation layer and data persistence.  However, it integrates with Java based UI and DB framworks.

So…What?

Instead of web services, SCA lets you connect and composite through web services, RPC or anyother means, unlike today protocol based SOA approach.   This is what mentioned and marketed in the SCA specification.  When you are crossing the border of “Concept behind SCA” section of this post, you have surprised that what is new in SCA for SOA, since WCF  incorporated these few years back when this specification was only on the paper.  More interesting and confusing thing is the specification team invited Microsoft for adopting this into .NET.  One more buzz is that this specification is based on WSDL.  These two make me what else have been proposed apart from what WCF has now with such the level of maturity.

For those who want clear map between above concepts and WCF:

  • Services - C# interface with WCF declarations
  • Components – C# classes with WCF declarations
  • Composites – Service model section in app.config/web.config file.
  • Domain – Service host (IIS/WAS/Windows Process)

What does it has….What doesn’t?

It provides the following:

  • Service reference – dependency with other services
  • Composition – way to encapsulate technical/vertical components such as validation, logging and auditing components within service and hide these to the outworld.
  • Policy - a statement that controls the operations that provided by the infrastructure.
  • Wire – a way for service aggregation and topologies (oneway, duplex, request and response)
  • Bindings – provides the means to communicate to the consumers.

It doesn’t have the following:

  • Service orchestration – but supports JSR based on BPEL
  • Service extension
  • Service inventory

Unfortunately, WCF has all the above with the power of .NET platform.  So, beware of SCA jargon in .NET world, where an elephant WCF has all the capabilities.  As of my understanding, SCA is WCF avatar in Java world.

Michael Rowley saluted the WCF proposals and its features, however he tried to oversight it with SCA.  Its confused.

Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
Tags Tags: , , , ,
Categories: Architecture, Design, WCF
Posted By: udooz
Last Edit: 11 Mar 2010 @ 07 23 AM

EmailPermalinkComments (1)

 09 Mar 2010 @ 7:09 AM 

Continue to my previous introductory post about AppFabric, it is very fundamental to know the architecture IIS 7.0 and WAS.  So, this post.

IIS 7.0 Architecture

In the above diagram, you can see two regions in Windows. The kernal mode and user mode, and you know that processes in the kernal mode touches the CPU and other hardwares without any interface and have the rights to access physical memory without any virtual address mapping. The user mode processes are our own applications along with Windowing Subsystem which also includes Windows Network Subsystem.  Processes in the user mode requires processes in the kernal mode such as thread scheduling, memory, cache or IO related activities. So, it would require a thread context switching means that kernal model thread has been created and the data in the user mode thread has been transferred into kernal mode thread.  Ahhh, I’m explaining too much about Windows processing.  Lets cut off.

IIS 7 Components

Application Pool and Worker Process

Worker process is a windows process which is specifically designed for hosting and running static, ASP or ASP.NET web applications in IIS.  w3wp.exe is responsible for loading the appropriate ISAPI (a lower level programming module for handling specific web application, for example aspnet_isapi.dll for ASP.NET) filters and starts a new worker process for a request.

Application pool is a grouping of web applications those are routed to one or more worker processes.  Processes in one application pool will not be impacted by another application pool’s failure.

Request Processing Pipeline and Modules

A request processing pipeline is created for every request.  In the previous versions of IIS, if a request is for ASP.NET application, the application needs to exit from the IIS pipeline and load aspnet_isapi for handling ASP.NET code which inturn creates its own request processing pipeline.  In II7, both IIS and ASP.NET request pipelines are combined and called as “Integrated Pipeline“.  This pipeline contains one or more modules.  Module is a component which contain a specific set of features for IIS to handle a request.  For example, BasicAuthenticationModule is a module for performing basic authentication and FileCacheModule is a module for caching files and file handles.

The integrated pipeline has following benefits:

  • Eliminating the duplication of features between IIS and ASP.NET, for example authentication
  • One inventory for all IIS modules
  • Performance…performance…

WWW Service and WAS

It is necessary that a dedicated component is required for listening for requests and managing application pools and worker processes.  In IIS 7, WAS (Windows Process Activation Service) is dedicated for this.  Requests coming from different transports like HTTP, TCP/IP, NetPipe and MSMQ are handled by respective listener adapters configured in the WAS.  When a request is coming which is directed to respective listerner adapters which passes the request to appropriate worker process, where the application manager directs the request to the specific application.

WWW Service (World wide web publishing service, simply w3svc) is the listener adapter for HTTP.  Apart from this, it manages the configuration stuffs required for HTTP related.

Protocol Listeners and HTTP.sys (Kernal Mode)

As its name reflects, protocols listeners receive appropriate requests and passes them to the IIS.  Note that protocol listener are kernal mode processes.  This model allows to handle any protocol, and the only thing we require is appropriate device drive as like as HTTP.sys for HTTP requests.

Whenever a HTTP request is entering into the server, HTTP.sys receives the requests and pass it to appropriate worker process if exists, otherwise it puts the request in the request queue.  When a response for a request is already in the response cache, it fetches that and reply it back without noticing and invoking worker process.

Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
Tags Tags: , , , , ,
Categories: ASP.NET, AppFabric
Posted By: udooz
Last Edit: 09 Mar 2010 @ 07 21 AM

EmailPermalinkComments (0)

 07 Mar 2010 @ 10:03 AM 

After a quite while, I’d a chance to start looking into Windows Server AppFabric.  This is one my long pending middler tier component from Windows/.NET combo.

What is AppFabric?

A set of components provide service hosting, in-memory caching, stateful services persistence and management services, management consoles and API to access these services.  The following figure shows the major responsibilities of AppFabric components.

AppFabric components responsibilities

Hosting services extends WAS (Windows Process Activation Service) with some default configuration, workflow management and, administration tools.  In-memory caching, previously code-named as Velocity, is a solution for scalable caching of enterprise/web applications.  Its cluster architecture and provision to configure various caching options enable us to prepare feast for small to large crowd.  Not know in detail about what makes different from WF 3.x and SQL Server combo, and state persistence service in AppFabric.  Let us see in detail on future logs.  To manage these aspects, AppFabric provides variety of management services which includes dashboard, service deployment, monitors and APIs.

Setup your AppFabric Environment

Windows Server AppFabric is actually designed for Windows 2008, but has development stage avatars for Windows Vista/7.  AppFabric beta 1 targetedc .NET 4.0 beta 2 and AppFabric beta 2 is targeted .NET 4.0 RC.  It will act as extension of IIS 7.0.  The following figure shows the IIS MMC for this.

The Windows 7/2008 beta 1 can be downloaded at http://download.microsoft.com/download/0/A/E/0AEB3BC1-506E-4954-8AB1-4FA2EE75985C/AseSetup_x86_6.1.exe.

Beta 2 can be downloaded at http://download.microsoft.com/download/F/D/4/FD4F05A5-016B-40F8-A61F-1D38E202A32A/WindowsServerAppFabricSetup_x86_6.1.exe.

Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
Tags Tags: ,
Categories: .NET
Posted By: udooz
Last Edit: 07 Mar 2010 @ 10 03 AM

EmailPermalinkComments (1)

 15 Feb 2010 @ 10:38 PM 

Parameters with default value. Hence, explicit values not specified in the calling place, default value has been taken.

static void Power(int v, int p = 2)
{
 Console.WriteLine("{0} Power of {1} = {2}", v, p, Math.Pow(v, p));
}

p is the optional parameter here. By default Power does calculate square of v, if p value provided explicitly, does calculate v to the power of p.

Power(2, 3);  // 2 ** 3 = 8
Power(4); // 4 ** 2 = 16

Actually, two parameter target attributes help to make this feature available. These are:

  • OptionalAttribute
  • DefaultParameterValueAttribute

in System.Runtime.InteropServices namespace.

The OptionalAttribute marks the parameter as optional as like


static void Power(int v, [Optional] p) {...} // p's default value is to default(int) i.e. 0

Power(5); // prints 1

The DefaultParameterValueAttribute constructor takes value parameter of type object is used to initialize the default value of the target parameter.


static void Power(int v, [Optional][DefaultParameterValue(2)] p) {...} // p's default value is 2

Points to be noted on “optional” parameter usage:

  • Optional parameter should be the last parameter as like “param” usage
  • ref and out parameters.

Named Parameters

Optional parameter will not be useful in real without named parameters. Yes, the name itself tells the answer. What will you do if you have more than one optional parameters and at the calling place, you want to pass actual value for less number of optional parameters. For example


static void MoreOptionalParamMethod(int a = 0, int b = 1, int c = 2)
{
 Console.WriteLine("a= {0}, b= {1}, c= {2}, ", a, b, c);
}

Now, you want to pass the value of variable b only. Named parameter will help you.

Instead of parameter order, you can explictly specify parameter name along with the value using “:” in the calling place

See the following calling place

MoreOptionalParamMethod(b: 5); // prints a= 0, b= 5, c= 2

There is no surprising in the IL code, the compiler replaces optional parameters with default values as like below

MoreOptionalParamMethod(0, 5, 2);

The only thing to be considered is named and normal parameters can be mixed but normal parameter should be come first.

Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
Tags Tags: , , , , ,
Categories: .NET
Posted By: udooz
Last Edit: 16 Feb 2010 @ 09 51 PM

EmailPermalinkComments (0)

 22 Jan 2010 @ 9:47 AM 

Caching is one of the vital aspect for enterprise applications.  ASP.NET Cache is not enough and even not suitable for service layer which is now more predominantly occupied by WCF. A robustic and scalable memory caching solution is required to cache different types of data.  I’m the beliver of “RAM is disk” for service layer.  Enterprise Library Caching Application Block (CAB) from Microsoft PnP team provides an in-process memory caching, however it is not scalable and robust. But, its provider pattern is an elegant model for application design, so that you can plug any caching solutions.

Recently, I was in a situation to find out suitable caching solution for our WCF based service layer.  Although, Microsoft yet to avail its “Windows Server AppFabric” to the .NET/WCF world (which might be the filler of .NET peoples’ decade old expectation), there are some caching solutions available from third parties. 

I did a small evaluation on the following caching solutions:

  • NCache Express
  • Shared Cache
  • Memcached
  • Enterprise Library 4.1

Disclaimer: The test was done at very small scale and not included the scalability factors.  Memory and CPU consumption were not covered.

NCache supports different caching topologies and types with many features like Object Query Language, remote clustering, etc.  I’ve taken its express edition for this evaulation.  Shared Cache is 100% written in C# with distributed caching and three different topologies.  It supports WCF DataContractSerializer in addition with BinarySerializer.  Guys from *nux world knows the defacto caching solution “memcached“.  It has Win32/64 avatar too and some open source managed client libraries also available.  I used Danga Interactive 32-bit version of memcached 1.2.6 (http://code.jellycan.com/memcached/) and BeIT Memcached managed client (http://code.google.com/p/beitmemcached/).  64-bit Windows version is available at http://labs.northscale.com/memcached-packages/.

I’d done a small performance testing on the above solutions.  In addition to these, I’ve used Enterprise Library 4.1 CAB provider model and implement provider for these solutions.  So, following different solutions had been tested:

  • Enterprise Library 4.1 CAB
  • Memcached
  • Enterprise Library 4.1 based Memcached
  • Shared Cache
  • Enterprise Library 4.1 based Shared Cache
  • NCache Express
  • Enterprise Library 4.1 based NCache Express

Following three different test had been done on every solutions, totally 21 test:

  • Adding 1000 items & Getting these items
  • Adding 1000 items & Getting 5th element
  • Adding 1000 items & Getting 995th element

The testing was performed on Intel Pentium 4 3.2GHz, 2GB RAM running WinXP SP2.

Let us see the results and, pros and cons of these solutions.

Enterprise Library 4.1

Not surprisingly excellent performance due to in-process memory caching, however not suitable for enterprise scale.  This supports primitive and Serializable objects.

  EntLib 4.1
  R1 R2 R3 R4 Avg
Adding 1000 items (in ms) 21 13 23 12 17.25
Getting 1000 items (in ms) 9 5 9 5 7
Get 5th item (1000 items) (in ms) 4 3 3 2 3
Get 995th item (1000 items) (in ms) 4 3 3 2 3

The “R” deonotes “Run”.  I did 4 runs for every test.

Memcached

Since, the OS calls for *nux memcached and Windows memcached is different, some bloggers cautioned memcached on windows is might not be a win-win.  But, I could not find any degrades in my testing.  It takes small memory foot-print and CPU usage.  It supports primitive and Serializable objects.  However, the Win32 service version does not have flexible configuration.

  MemCached
  R1 R2 R3 R4 Avg
Adding 1000 items (in ms) 166 160 203 164 173.25
Getting 1000 items (in ms) 154 140 175 138 151.75
Get 5th item (1000 items) (in ms) 5 5 5 5 5
Get 995th item (1000 items) (in ms) 5 5 5 5 5
  EntLib MemCached
  R1 R2 R3 R4 Avg
Adding 1000 items (in ms) 178 164 202 193 184.25
Getting 1000 items (in ms) 5 3 6 3 4.25
Get 5th item (1000 items) (in ms) 2 0 0 0 0.5
Get 995th item (1000 items) (in ms) 2 0 0 0 0.5

Shared Cache

Like Enterprise Library 4.1 CAB, this solution uses provider like model and come out with IndexusDistributionCache which supports WCF data contract serializer too in addition with binary serializer.

  SharedCache
  R1 R2 R3 R4 Avg
Adding 1000 items (in ms) 4723 3441 3904 3592 3915
Getting 1000 items (in ms) 3357 3633 4582 3722 3823.5
Get 5th item (1000 items) (in ms) 12 14 17 13 14
Get 995th item (1000 items) (in ms) 13 14 13 14 13.5
  EntLib SharedCache
  R1 R2 R3 R4 Avg
Adding 1000 items (in ms) 3649 3612 4379 4992 4158
Getting 1000 items (in ms) 5 2 5 3 3.75
Get 5th item (1000 items) (in ms) 3 0 0 0 0.75
Get 995th item (1000 items) (in ms) 3 0 0 0 0.75

NCache

This is more matured and tailored solution for .NET world.  The best is the object is not necessarily Serializable.

  Ncache
  R1 R2 R3 R4 Avg
Adding 1000 items (in ms) 365 282 382 296 331.25
Getting 1000 items (in ms) 257 248 287 234 256.5
Get 5th item (1000 items) (in ms) 12 8 10 8 9.5
Get 995th item (1000 items) (in ms) 12 8 8 8 9
  EntLib Ncache
               R1 R2 R3 R4 Avg
Adding 1000 items (in ms) 317 277 367 278 309.75
Getting 1000 items (in ms) 5 2 5 3 3.75
Get 5th item (1000 items) (in ms) 2 0 0 0 0.5
Get 995th item (1000 items) (in ms) 3 0 0 0 0.75

The results shows Memcached performed better for its consistent performance and simplicity.  The surprising fact is that the above all solutions perform well in Enterprise Library 4.1 CAB provider model than their default mode.

Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
Tags Tags: , , , , , ,
Categories: .NET
Posted By: udooz
Last Edit: 22 Jan 2010 @ 09 47 AM

EmailPermalinkComments (1)

 11 Nov 2009 @ 11:55 PM 

Finally, Google makes its contribution apart from “www” after its yet another linux distro Google Chrome OS.  This time in language space.  Its name is “Go”.

Its released for Linux and Mac only.  After downloading the source from https://go.googlecode.com/hg, building the packages and set some environment variables (guide @ http://golang.org/doc/install.html), tried a small sample which greets the arg(0) given from console.

The syntax is neither smart nor friendlier at my first sight.  Seems it is a mix of JavaScript, Java and ofcourse, C++.  For each and every compilation you need to specify target machine architecture, 6g – for AMD, 8g – for 386.

See the following sample hello, <user> sample:


package main

import (
"fmt"; // formatted stdin
"flag"; // command line parser
)

func main(){
 flag.Parse();

 fmt.Printf("hello," + flag.Arg(0) + "\n");
}

After the compilation with 8g, invoke the linker 8l and generate the executable (normally 8.out).  Since I did not evaluate this language at some level and did not read its architecture, I could not give any comments of this early stage compiler. However, at my first sight,

GO = Neither C# Nor Ruby

Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
Tags Tags: ,
Categories: Uncategorized
Posted By: udooz
Last Edit: 12 Nov 2009 @ 07 33 AM

EmailPermalinkComments (2)

 27 Aug 2009 @ 11:14 PM 

In my previous post, we have seen basis of Task Parallel Library, where I have mentioned new task scheduler in .NET 4.0 thread pool.  In this post I brief about it along with “Task” class.   Before this, let us see how to make LINQ as parallel using PLINQ.

PLINQ

PLINQ has implementation of  all LINQ to Objects extension methods in System.Linq.ParallelEnumerable for IEnumerable.  To make an IEnumerable parallel, you simply call AsParallel() extension method.  AsParallel() internally calls System.Linq.Parallel.ParallelEnumerableWrapper which is of type System.Linq.ParallelQuery<TSource>.  Let us take the same customer-order example as shown in my previous post with  PLINQ enabled.

var customersForOrderId7 =
    from c in customers.AsParallel()
    from o in c.Orders
    where o.OrderId == 7
    select c;
 

customersForOrderId7.ForAll(c =>
    Console.WriteLine(c.ToString()));

The above code selects customers who have ordered OrderId 7.  AsParallel() at line 3 makes Customer[] as parallel enabled.  In this example, you can see that instead of typical for…each, I’ve used ForAll().  This differs from for..each, means that for..each preservs the final order of the results.

Thread Pool and Work Stealing Queue

Until .NET3.5, we can queue our work items as thread in to ThreadPool using QueueUserWorkItem().  In .NET 4.0, improvements had been made in the thread pool.  It is now based on System.Threading.Tasks.Task

Task

Task is a work item which can be executed independently along with other tasks, technically it represents an asynchronous operation i.e. System.Action.  It is defined in System.Threading.Tasks.Task which enables you to do the following actions on a task instance:

  • start – to start the instance
  • wait – to wait to for a task to complete
  • cancel – cancel the task asynchronously

It seems that task is a lite version of thread.

Thread Pool

Following diagram shows the conceptual view of .NET 4.0 thread pool.

.NET 4.0 Thread Pool

Previously, thread pool had only one queue on which all the work items were queued and enqueued in FIFO order (ofcourse, thats why queue).  The worker threads are allocated for every work item access the work item from this queue.  In .NET 4.0, it has been improved by introducing local queue for every worker thread, in addition to qlobal queue.  Tasks those are created by program thread queued on global queue.  The task scheduler enqueues the tasks from global queue in FIFO order and distributes to respective worker thread’s local queue.  The worker thread enqueues the tasks from its local queue in LIFO order.  Interesting!

The introduction of local queue makes these threads can be executed on different processors without contention issue which normally occur in single queue thread pool.  The reason for worker thread picking up the tasks in LIFO order is the assumption that “last-in” is hot to act which results no qurantee in task ordering, but better performance.

Work Stealing Queue

Let us assume that worker thread 1 completed all of its tasks in the queue.  It scans the global queue for any task and if nothing there, it scans other worker thread’s local queue.  In this case, let us assume there are two tasks in WT2 queue.  WT1 enqueues first-in task from WT2 queue which avoids contention issue.  Getting tasks from other local queue is called as work stealing.  This again results better performance.

References

MSDN article: Task Parallel Library Overview: http://msdn.microsoft.com/en-us/library/dd460717(VS.100).aspx

Daniel Moth’s videocast and PPT deck: http://channel9.msdn.com/pdc2008/TL26/ and his article about thread pool at http://www.danielmoth.com/Blog/2008/11/new-and-improved-clr-4-thread-pool.html

My Code sample for PLINQ as used in this post is at http://www.udooz.net/file-drive/doc_details/9-tpl-and-plinq-example.html

Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
Tags Tags: , , , , , ,
Categories: .NET
Posted By: udooz
Last Edit: 27 Aug 2009 @ 11 18 PM

EmailPermalinkComments (0)

 26 Aug 2009 @ 11:49 PM 

We are in the multi-core era, where our applications are expected to effectively use these cores.  Simply, go parallel, means that partitioning the work being done into smaller pieces those are executed on the available processors in the target system.  Until .NET 3.5, parallel means we are used to use ThreadPool and Thread classes.  We are not in a situation to have a component which partition and schedule work into work items on different cores.  A craft-and-weave parallel framework from Intel is available while for MC++ and not sure how easy it is to use.

Even though threads are basic to parallel, from a developer perspective, what required for parallel programming is not the thread, work items in a work, named “Task”.

.NET 4.0 Parallel Extensions 

Task represents a work item being performed independently along with other work items.  This is the approach taken by the experts in Microsoft Parallel Computing division, and released parallel extensions (Task Parallel Library and Parallel LINQ) in .NET 4.0 beta 1.  As like Microsoft’s other frameworks, developers need not worry about the internals.  The task partitioning and scheduling of the work items are taken care by parallel extensions.

Task and Thread

Let us first understand the relationship between task and thread.  See the following figure.

Thread and Task Relationship

Typically task is resided in a thread.  A task may contain one or more child tasks those are not necessarly resided in the parent task’s thread.  In the above figure, Child Task M2 of Task M resided in Thread B.

Task Parallel Library (TPL)

This library provides API to perform task based parallel programming under System.Threading and System.Threading.Tasks namespaces.  The partitioned tasks are automatically scheduled on available processors by Task Scheduler which is in ThreadPool.  The work stealing queue algorithm in the task scheduler makes the life easier.  I’ll explain about this in the next post. 

Scheduling the tasks on the processors is the runtime behaviour of the task scheduler, so it does support ’scale up’ without recompiling the program on the target machine with few or more cores. 

There are two types of parallelism you can do using TPL.

  • Data Parallelism
  • Task Parallelism

Data Parallelism

It is very common to perform a set of actions against each element in a collection of data using for and for..each.  Parallel.For() and Parallel.ForEach() enable to make your collection processing actions to be parallel.  The following figure depicts this.

 Data Parallelism

Let us see this with typical customer-order collection.  The following code shows Customer and Order declaration.

public class Customer
{
    public string Name;
    public string City;
    public Order[] Orders;
 

    public override string ToString()
    {
        return String.Format("Name: {0} - City: {1}",
            Name, City);
    }
}

public class Order
{
    public int OrderId;
    public int Quantity;

    public override string ToString()
    {
        return String.Format("Order Id: {0} - Quantity: {1}",
            OrderId, Quantity);
    }
}

Let us create a in-memory collection for this as like below code.

var customers = new Customer[]
{
    new Customer{Name="Hussain", City="Vizak", Orders =
        new Order[]
        {
            new Order{OrderId=1, Quantity=10},
            new Order{OrderId=10, Quantity=5}
        }},
    new Customer{Name="Abdul", City="Chennai", Orders =
        new Order[]
        {
            new Order{OrderId=7, Quantity=2},
            new Order{OrderId=10, Quantity=4}
        }},
    new Customer{Name="Daniel", City="Texas", Orders =
        new Order[]
        {
            new Order{OrderId=12, Quantity=3},
            new Order{OrderId=7, Quantity=1},
            new Order{OrderId=10, Quantity=1}
        }}
};

Let us write a simple parallel code which iterate through each customers and its orders.

Parallel.ForEach<Customer>(customers,
    customer =>
    {
        Console.WriteLine("**** {0} ****", customer.ToString());
        Parallel.ForEach<Order>(customer.Orders,
            order =>
            {
                Console.WriteLine("\t{0}", order.ToString());
            });
    });

In the above code, printing customer detail is one task and printing order detail for a specified customer is the child one for that.  I’ve taken simple overloaded version of For…Each

public static ParallelLoopResult ForEach<TSource>(IEnumerable<TSource> source, Action<TSource> body);

The task scheduler partitions the customers and orders, and schedule them into available processors.

Task Parallelism

In cases like multiple distinct actions to be performed concurrently on the same or different source.  The following figure depicts this.  Note that task count need not be equal to number of actions.

Task Parallelism

Parallel.Invoke() is used for this.  See the following code.

Parallel.Invoke(() =>
    {
        Console.WriteLine("Task 1.  Getting total quantity ordered for OrderId 10");
        var orderId10Sum =
            (from c in customers
            from o in c.Orders
            where o.OrderId == 10                       
            select o.Quantity).Sum();
        Console.WriteLine("Quantity: {0}", orderId10Sum);
    },() =>
    {
        Console.WriteLine("Task 2.  Getting number of customers and their city ordered OrderId 7");
        var items =
            from c in customers
            from o in c.Orders
            where o.OrderId == 7
            select c.City;
        Console.WriteLine("Count: {0}\nFrom following City:", items.Count());
 

        foreach (string city in items)
            Console.WriteLine(city);
    }
);

I’ve taken the following overloaded version of Parallel.Invoke().

public static void Invoke(params Action[] actions);

I’ve specified two different actions those are acted on customers.

The source code for this article is available at http://www.udooz.net/file-drive/doc_details/8-net-40-tlp-demo-1.html.

In the next post, I’ll explain the more about tasks, Parallel LINQ portion and task scheduler.

Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
Tags Tags: , , , ,
Categories: .NET
Posted By: udooz
Last Edit: 27 Aug 2009 @ 08 13 PM

EmailPermalinkComments (1)

 15 Aug 2009 @ 7:23 AM 

Two security issues really surprised me. One is with Linux and another one is Adobe Flash.

Linux Kernals and NULL Pointers

To handle unavailable operations for some protocols, Linux kernal has methods that are not doing any NULL pointer check before deferencing those methods.  An attacker can put his code that will get executed with kernel privileges.  For more details, visit: http://blog.cr0.org/2009/08/linux-null-pointer-dereference-due-to.html.

Flash’s Vulnerability Pitch

Flash is one of the premium vechile for web sites with extravaganza contents.  A critical vulnerability allows attackers can compromise the system with Flash 9.x and 10.x for all platforms.  Visit: http://www.adobe.com/support/security/bulletins/apsb09-10.html to download the patch for the pitch.

Finally, one good news about IE 8.

IE8 – Highly Secured Browser in the Universe (Google’s promo style!)

NSS Lab is one of the leading product security testing and certification independent body has published comparative browser security testing in IE 8, Firefox 3, Safari 4, Chrome 2 and Opera 10.  The report said that IE 8 (83%) followed by FF 3 (80%) are most consistent in the high level of protection from phishing URL block rate.  Chrome and Safari score 26% and 2% respectively.

The  socially engineered malware block rate for IE8 is 81% which surpassed all the other browsers in the earth (again Google’s promo style!).  FF3 scores 27% and Chrome2 7%.

Read the complete report at http://www.nsslabs.com/browser-security.

Okey, now let me brief the reason for this post’s title.  Always, people from OS (open source) said that they are more stronger in skills than the engineers at Microsoft and other CS (closed source) No.1s.  Now, they have to understand that skill is not at all related to open source.  It is a myth. 

PS: I am not against OS.

Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
Tags Tags: , , ,
Categories: General
Posted By: udooz
Last Edit: 16 Aug 2009 @ 07 39 PM

EmailPermalinkComments (0)

 12 Aug 2009 @ 8:47 AM 

As a response to growing Bing and Facebook search engines, Google is developing next generation search engine with new architecture. It keeps the features and internals secret.

The development version is available at http://www2.sandbox.google.com/. The only difference I found when I googled “Next generation Google search engine” is search result. Current engine gives 37,300,000 results, and the new one gives 10,100,000 results (could be more accuracy!).

Differences between these has been explained at http://www.betanews.com/article/Googles-next-search-engine-Whats-the-difference/1250012846.

Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
Tags Tags: ,
Categories: General
Posted By: udooz
Last Edit: 12 Aug 2009 @ 08 50 AM

EmailPermalinkComments (0)




\/ More Options ...
Change Theme...
  • Users » 1
  • Posts/Pages » 51
  • Comments » 38
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight