Rajnish Noonia

Category: Architecture

  • Actor Model

    An actor is an isolated, independent unit of compute and state with single-threaded execution. The actor pattern is a computational model for concurrent or distributed systems in which a large number of these actors can execute simultaneously and independently of each other. Actors can communicate with each other and they can create more actors.

    The concurrency models we have considered so far have the notion of shared state in common. Shared state can be accessed by multiple threads at the same time and must thus be protected, either by locking or by using transactions.

    We now have a look at an entirely different approach but without the notion of shared state. State is still mutable, however it is exclusively coupled to single entities that are allowed to alter it, so-called actors.

    An actor is a computational entity that, in response to a message it receives, can concurrently:

    • send a finite number of messages to other actors
    • create a finite number of new actors
    • designate the behaviour to be used for the next message it receives.

    There is no assumed sequence to the above actions and they could be carried out in parallel.

    Actor-Model

     

    For communication, the actor model uses asynchronous message passing.
    When implementing the actor model, it is important to adhere to the set of rules defined by the original idea. First and foremost, actors must not share any state. This disallows actors to pass references, pointers or any other kind of shared data as part of a message. Only immutable data and addresses (i.e. “names”) of actors should be sent. Message passing between actors is often enriched with a few more guarantees compared to the entirely best-effort style. Most implementations ensure that two messages sent from one actor to another maintain their order at arrival. Messaging is always asynchronous and the interleaving of incoming messages sent by multiple actors is indeterminate.

    Frameworks for the Actor Model

    There are many frameworks for the development of a distributed system based on the actor model. The most popular are Akka, Orleans, Service Fabric, TPL Dataflow..

    TPL Dataflow model promotes actor-based programming by providing in-process message passing for coarse-grained dataflow and pipelining tasks.These dataflow components are useful when you have multiple operations that must communicate with one another asynchronously or when you want to process data as it becomes available.The TPL Dataflow Library provides a foundation for message passing and parallelizing CPU-intensive and I/O-intensive applications that have high throughput and low latency. It also gives you explicit control over how data is buffered and moves around the system.

    Service Fabric Reliable Actors is an implementation of the actor design pattern.Although the actor design pattern can be a good fit to a number of distributed systems problems and scenarios, careful consideration of the constraints of the pattern and the framework implementing it must be made.

    As general guidance, consider the actor pattern to model your problem or scenario if:

    • Your problem space involves a large number (thousands or more) of small, independent, and isolated units of state and logic.
    • You want to work with single-threaded objects that do not require significant interaction from external components, including querying state across a set of actors.
    • Your actor instances won’t block callers with unpredictable delays by issuing I/O operations.
  • Validate SSIS package on server

    SSIS server validation

    Untitled

     

    • Any change in database schema will break the associated SSIS package.
    • Generally each change is responsible to identify dependent components to be included in the change scope.
    • But what about any missed dependencies. E.g. Recent production issue.
    • Such broken SSIS can be identified in Pre-Prod only if pre-prod is well controlled and identical copy of prod environment.
    • Process is required to identify packages impacted by dependencies changes like database schema.
    • Proactive validation of SSIS package could help to identify the issue and reduce the system downtime.

    High level architecture

    Untitled2

     

    The solution is capable of validating all ssis packages for sql server version 2008 on-wards. Instead of publishing the full source code below is the pseudo code and sql scripts to validate the packages.

    1. Create C# console base project which takes the server name you want to validate. The app calls the web service to validate the SQL server (validate SSIS packages on that server).
    2. Create web api project and expose following methods (Job Controller)
      1. Validate – start the validation process by creating SQL agent job dynamically on target server
      2. ValidationFinished – this will be invoked by job when validation is finished.
      3. GetValidationStatus – this will provide the SQL agent job status currently validating server

    The Validate method works as follows..

    • Get the SQL Server version
    private Version GetServerVersion(string serverName)
     {
     var connectionString = string.Format("Server={0};Database=master;Trusted_Connection=True;", serverName);
     using (var connection = new SqlConnection(connectionString))
     {
     connection.Open();
     return new Version(connection.ServerVersion);
     }
     }
    
    • Create interface IProcessor and implement it for sql server 2008 and 2012 as they both have different way to validate package
    • Based on server version get the eligible concrete implementation.
    • The validation engine will create the validation job on target sql server. for each proxy account, the script will create job step to trigger a network share package running under proxy account. (for details see createValidationJob.sql)
    • Each validation step gets the package scheduled under the current account and validate the package, populate the results back on central server. and in the end extract the job history and delete the job.)
    • The network deployed ssis package uses same engine to validate 2008 and 2012 via IProcessor since validation is done differently for both servers.

    The common scripts used for both servers are here

    Common-Scripts

    The SQL server 2008 validation is done via DTEXEC with /validate command

    SQl 2008-Scripts

    The SQL 2012 validation is done via EXECUTE SSISDB.catalog.validate_project stored proc.

    SQL 2012 Scripts

    The centralized server which keeps the status of SSIS validation looks like

    Untitled3

    The font end to display the data was build on angular 2 API..

  • ViewModel First – ViewCaching

    With View model first approach, view are usually created via DataTemplate, and each time a view model is injected in the content control, the corresponding view is recreated.

    If you have complex view where it take bit time to create view, you may see the performance hits. To avoid the performance hit you may want to cache the view and use the cached view when available. This can be done via creating CacheContentControl and you choice of view factory.

    The basic idea is to wrap the view inside CacheContentControl and delegate the view creation logic to your view factory. The attached sample uses weakreference view factory,say if GC has not collected the view, you may use the cached view instead of creating view each time. This will work with controls like tab control docking controls etc.

    The CacheContentControl  code

    public class CacheContentControl : ContentControl
        {
            public CacheContentControl()
            {
                Unloaded += ViewCache_Unloaded;
                ViewFactory = WeakReferenceViewFactory.Instance;
            }
    
            void ViewCache_Unloaded(object sender, RoutedEventArgs e)
            {
                Content = null;
            }
    
            private Type _contentType;
            public Type ContentType
            {
                get { return _contentType; }
                set
                {
                    _contentType = value;
                   //  use you favorite factory
                    Content = ViewFactory.GetView(value);
                }
            }
    
            public IViewFactory ViewFactory { get; private set; }
        }
    

    In the DataTemplate, use the ViewCache, pass the type of the real view you want to use:

    <DataTemplate DataType=”{x:Type moduleB:Panel3Vm}”>

    <Border Background=”Green”>

    <local:CacheContentControl ContentType=”{x:Type moduleB:Pane3 }” Margin=”5″/>

    </Border>

    </DataTemplate>

    The example uses standard data template (red option) to demonstrate each time you navigate to panes the corresponding views are recreated with new hash code.

    If you select CacheContentControl (green option) and navigate the view is only created once. If you click on button to collected the GC then view are created on navigation if they are claimed by GC.

    Why ViewModel first ?

    I prefer to use view model first approach. For many reasons:

    • Vms are your application containing most of logic apart from glue code in form of behaviors or triggers.
    • If you creates views then you are responsible for its life and cleanup code. You have to deal with threading and other issues which are difficult to test. On the other hand of you create vms and leave the view creation logic with WPF via data template.. you don’t have to worry about threading issue. And there will be better separation of concerns.
    • With vm first approach zero code behind.
    • With a project level isolation for view and vms you can restrict developers using view specific things like dispatcher in the view model leaving more cleaner and testable code base. I.e view project sprojec to vm. And vm project should not refer to any presentation lib.
    • If there is clear boundary between view and vm. Both can evolve and will be less fragile.
    • Allows more complete testing of logic to open new Views and ViewModels
    • Tends to be DRYer (don’t repeat yourself ) as applications get larger
    • View and ViewModel are more independent and can be worked on separately more easily.

    For more details see attached source code (download and rename docx to zip)

    Viewcache Source Code

  • Asp.Net MVC flavours

    The main purpose of the MVC (Model, View and Controller) architecture is to make separation of the business layer (logic) and the application layer (data)  from the presentation layer to the user. Model-View-Controller is a software pattern for achieving isolation between different application components. Its always desirable for software applications (especially web-based applications) that there must be clear separation between business logic and the user interface. A model represents the state of a particular aspect of the application. A controller handles interactions and updates the model to reflect a change in state of the application, and then passes information to the view. A view accepts necessary information from the controller and renders a user interface to display that information. Over past few years many version of ASP.Net MVC were release moving towards more and more mature framework for web development.Below is brief comparison of features release in each version

    MVC 5 – October 2013

    • Bootstrap replaced the default MVC template.
    • ASP.NET Identity for authentication and identity management.
    • Authentication Filters for authenticating user by custom or third-party authentication provider.
    • With the help of Filter overrides, we can now override filters on a method or controller.
    • Attribute Routing is now integrated into MVC 5

    MVC 4 – August 2012

    • ASP.NET Web API, a framework that simplifies the creation of HTTP services and serving a wide range of clients.
    • Follow to create your first ASP.NET Web API service
    • Adaptive rendering and other look-n-feel improvements to Default Project Templates.
    • A truly Empty Project Template.
    • MVC4 also uses Razor View Engine as a default view engine with some new features like condition attribute and ‘Tilde slash’
    • Based on jQuery Mobile, new Mobile Project Template introduced.
    • Support for adding controller to other project folders also.
    • Task Support for Asynchronous Controllers.
    • Controlling Bundling and Minification through web.config.
    • Support for OAuth and OpenID logins using DotNetOpenAuth library.
    • Support for Windows Azure SDK 1.6 and new releases.
    • MVC4 provides better support for Jquery like Jquery Mobile
    • Client side validation, Jquery validation and enhanced support for asynchronous methods
    • Supports many new features for mobile apps and also provides new mobile project template and default templates are refreshed and modernized

    MVC 3 – January 2011

    • New Project Templates having support for HTML 5 and CSS 3.
    • Improved Model validation.
    • Razor View Engine (.cshtml for c# and .vbhtml for Visual Basic) introduced apart from Web Forms view engine (.aspx)
    • Having support for Multiple View Engines i.e. Web Forms view engine, Razor or open source.
    • Controller improvements like ViewBag property and ActionResults Types etc.
    • Unobtrusive JavaScript approach, Ajax and Client side Validation, Jquery Validation and JSON binding support
    • Chart, WebGrid, Crypto,WebImage, WebMail Controls
    • Improved Dependency Injection with new IDependencyResolver.It provides powerful hooks with Dependency Injection and Global Action Filters
    • Partial page output caching.
    • TempData, ViewData ,ViewBag
    • Supports not only Master Page but also Layout Page

    MVC 2 – March 2010

    • MVC 2 uses only Web Forms view engine (.aspx) as a default View Engine.
    • (HTML Syntax) Web Forms view engine syntax: <%=Html code %>
    • TempData, ViewData
    • Jquery support is Good
    • Supports only Master Page
    • Client-side Validation and Asynchronous controllers
    • support controllers to process requests asynchronously
    • Supports validations using the RangeAttribute, RequiredAttribute, StringLengthAttribute, and RegexAttribute attributes.

    MVC 1 – March 2009

    MVC CTP – December 2007 

    * Notes

    • View Engine is responsible for rendering of the HTML code from your views to the browser.
    • In ViewData, dictionary of objects are accessible via strings as keys
    • ViewBag was added in the C# 4.0 which uses the dynamic feature that allows to add properties of an object dynamically . We can say that ViewBag = ViewData + dynamic feature around the ViewData dictionary
  • .Net Universe

    .NET Universe Poster

    A visual map of the entire .NET ecosystem — frameworks, tools, languages, runtimes and libraries — all in one poster. The original PDF version is no longer available for direct download but the poster content is captured above.