Wednesday 10 August 2011

Object Pool - Quick and Short in .NET 4.0

A simple object pool that could be used to maintain a set of objects readily available in memory, especially if you see that the object creation time is heavy. Eg:- creation of a MemoryStream on a need basis is typically time consuming in a server based app. In this case, it could best to have a set of MemoryStream objects readily available in memory. But, we definitely have to make sure to couple of things first :

1.) The way the object pool is filled happens is async.
2.) Access to a pool instance from the client app is thread safe.

To solve 1, we could exploit the AsyncMethodCaller together with its BeginInvoke(), while to make sure that the access to the pool is thread safe, we could check out the ConcurrentBag in .NET 4.0. So, where is the code?!

namespace HoC.Client
{
    /// <summary>
    /// maintains a pool/list of objects, provides it on request
    /// usually used for classes whose construction call is heavy
    /// </summary>
    /// <typeparam name="W"></typeparam>
    public class ObjectInstancePool<W>
    {
        private const int objectCount = 20; //can be updated to receive through the constructor
        private ConcurrentBag<W> objectList = new ConcurrentBag<W>();

        public ObjectInstancePool()
        {
            //refresh the bag first
            new AsyncMethodCaller(Filler).BeginInvoke(null, null);
        }

        public W GetInstance()
        {
            W result;

            if (!(objectList.TryTake(out result)))
            {
                result = Activator.CreateInstance<W>();
            }
            else
                new AsyncMethodCaller(Filler).BeginInvoke(null, null); //refresh the bag
            
            return result;
        }

        public delegate void AsyncMethodCaller();

        private void Filler()
        {
            while (objectList.Count < objectCount)
            {
                objectList.Add(Activator.CreateInstance<W>());
            }
        }
    }
}


I totally like it short and sweet :)



Friday 15 July 2011

Tree-Of-Trust

Overview

Enterprise applications of today are no longer independent, but dependent on other applications, services and components for completing their functionality. Authenticating/Trusting another application typically requires having a new authentication/identity management module written for each new application that is integrated. With the advent of claims based/token based authentication, this pain has been eased very much for a developer. Supporting protocols, standards and frameworks such as SAML, WS-Security, WS-Federation, WIF, ADFS etc playing a huge role.

As of today, A developer for application A requiring access to use services of application B would configure the identity providers supported by B to trust A. As this task is most of the time manual and done as part of the deployment phase, the identity management today can be treated static as such. In a world where SOA is exploited, there comes a need to build trusts dynamically, in the same manner as a service is discovered dynamically.

Influences:
Similar to humans who build trust based on relationships, introductions, recommendations etc, what is proposed in the "dynamic tree of trust" topic area is to have a mechanism that includes new frameworks, protocols, markups, standards that collectively assist in building trust dynamically.

Possibility 1:
An application A wanting to access the functionality/services of an application B can claim that its trusted by another set of applications and provide this set of trust using a markup language to application B. Application B can go through its list of internal tree of trusts and figure out if the trust claims are authentic.

Possibility 2:
An application A wanting to access the functionality/services of an application B can send its identity to application B. Application B internally can apply its 'tree-of-trust' locator algorithm to check if there is any identity provider that appears to know this application A.

Ranking trust:
A ranking mechanism can be used by application B to get the effective-trust index using :
a.) Number of providers that support/trust application A
b.) Depth/level within the 'tree-of-trust'.

Research Possibilities:
1.) Research into dynamically building trust; devise a fool-proof mechanism.
2.) Research into developing a set of
(1.1) protocols
(1.2) standards
(1.3) markups and a
(1.4) sample framework for applications to more easily build trust dynamically without any human interventions, while considering any current trends in claims based authentication/WS-* standards. Especially WS-Federation, WS-Trust.
3.) Research into machine learning mechanisms can be included within the framework to have more robust trust learning mechanism such that the effective ranking is based on prior identity success/failures.
4.) Research into more effective traversal algorithms when the logical structure (not necessarily implementation) of the trust-tree is tree based.
4.1) Research into querying identity providers n level deep on the authenticity of the requestor.
5.) Research into applications in mobile devices.


Applicable thoughts:
1.) Hard Trust - A direct trust setup on an identity provider
2.) Soft Trust - A trust that was build up dynamically. ST (0.5), ST(0.8) etc, wherein the index indicates the effective trust index/rank
3.) On-Behalf-Of – A trust that is directly vouched by another.

Saturday 20 November 2010

Enterprise Architectures - skills, perspectives and insights - Tom Graves replies

Tom Graves has given deep insights (bit philosophical, but reality ) on building up skills on enterprise architecture from a professional and personal perspective; a query I had raised him earlier.

Read more here : http://weblog.tomgraves.org/index.php/2010/11/20/creating-a-career-in-enterprise-architecture/

Tuesday 5 October 2010

HoC is up on codeplex

HoC - A distributed cache implementation using .NET 4.0 is now available for download with source at http://hoc.codeplex.com/

HoC = Herd Of Cache.

Tuesday 13 July 2010

Azure opens up for Private cloud - Windows Azure Platform Appliance

MS announced yesterday that Azure would soon be available for deploying on your local datacenters. Effectively, you could soon create private clouds using MS Azure. This is a great move especially if you were concerned about data security in the public cloud and subscription costs.

But still, the upfront cost could be high; this is not yet published. Check more here

This is also interesting since my last blog entry did refer to this thought!

Tuesday 15 June 2010

Cloud Thoughts - 2

What if there was a mechanism to provision PaaS cloud environments (say MS Azure ) on public servers? Theoretically, if I had a free server(/cloud), I would install the "Azure runtimes" and add it to an existing cloud for others to use.

Registering a server to this free public cloud would then be a voluntary effort. This could have been a possibility if Azure allowed in-premise setup in the first place.

Can I call the end result as "Distributed Cloud Computing" ? Cloud computing that is distributed.

Monday 14 June 2010

Cloud Thoughts - 1

A few cloud related thoughts


Cloud Cumulus

A single cloud access point that internally seamlessly talks with the subscribed cloud providers. Eg:- Subscriber A could subscribe to the services of Amazon, Google and Micrsoft (yes, Subscriber A is quite well off) cloud services. Subscriber A would deploy the same app on each of these servers and provide a single service URI. Subscriber A's customers would be serviced by one of the cloud provider seamlessly - perhaps with parts of the request being handled by more than one provider. Session states, data etc being shared across clouds is interesting.

For A's customer, there is only one cloud. The cloud of cloud providers / Cumulus Cloud accessed with a single entry point.

Perhaps, once the Unified Cloud Interface (UCI) is in place, this could be built?


Upgrade Ease

How easy is it to upgrade a cloud based app that is actively serving hundreds of users? Came across this for Azure :  http://msdn.microsoft.com/en-us/library/ee517254.aspx

Not sure what happens to the application state. If an 'In-Place' upgrade is followed, does it mean that at a particular point in time there could be two instance of the same application running on different versions?


Chess On Cloud

Though there are numerous instances of distributed chess engines, has anyone attempted to get a chess engine on the cloud? I guess the only person who can try this out today is Bill with his Azure and his $'s.

Everyday Enterprise Architecture - The book - full download

It appears that Tom has put the full version of his new book for download for a limited period of time. Check out if it is still available here

Note: though the page might say its a preview edition, its actually the full book.

Monday 10 May 2010

Review - Book - CLR via C# 3rd Edition by Jeffrey Richter

Having been a die hard fan of the second edition of CLR via C#, couldn't wait to get hold of the third edition. The third edition keeps up to the Jeffrey standard on covering from the basics to the internals of .NET 4.0 with C# 4.0. Starting with the rather interesting foreword by his wife, this book can be read end to end if you are already comfortable with .NET and have enough time to read through ~850 pages of pure core stuff.

There is so much of deep insight in most of the pages that it might take some time to absorb stuff. The best recommendation to attack this book is to read one chapter a day while preparing notes. Once you are done with the book, your notes together with the book can be one hell of a reference at any point. If there is only one book you read as a .NET developer, this is it. Even if you have been the best .NET developer of your league, each time you read this book there is something new learnt. This book covers a good wide area of .NET topics, sometimes delving deep too.


Sharing Richter's deep experience and know-how of .NET in plain non-geeky language has worked out well. Additionally, there are various tips and notes provided in the boxes and shaded text that are pure gems. Richter has made sure that the reader is thoroughly introduced to CLR concepts and in turn how things work out from the C# layer to the IL layer. Richter had made sure that most discussed basic stuff like hashcodes, interface v/s class, explicit v/s implicit interface definitions are discussed to a level such that no further questions arise. There are various instances where he has provided guidance on what to use and why, while sometimes providing historical background to these decisions.

There is good introduction to advanced topics like application domains in the context of hosting. With multicore and concurrency the talk of the town, new to 3rd edition are the 5 new chapters dedicated to discussion on threads and related classes in .NET. Discussion on TPL, PLINQ, spinning and locking etc are dealt quite thoroughly.

At the end of the book you would feel a better .NET developer, ready to take on your next development task in a more elegant manner - believe me.

Tuesday 23 March 2010

Setting Physical Memory Limit for a .NET application

We needed to limit the physical memory used by a .NET application as it was taking too much of it and the other apps appeared to be in a struggle mode.

The straightforward way appeared to use Process.GetCurrentProcess().MaxWorkingSet. Strangely, no matter what we tried, this never worked. Yet to figure out why it does not work - if anyone has a clue, please ping.

Anyways, looking at options we came across job objects in Windows that allow setting the max working set. So the approach that finally worked was this:

1.) Create a Job object using CreateJobObject() Win32 call

2.) Setup the memory limits against this job using
SetInformationJobObject()


3.) Assign our process to this job using AssignProcessToJob().

Now, when we look at the task manager, the physical memory assigned to this process never goes over the specified limit. All good.

Note that this is applicable only for the physical memory and not for the virtual memory - no limits can be set for this [?]. The physical memory limit is affected when the application is paged-in from the page file into the memory.