Our Creative Corners

Lazy Loading Angular Modules
Lazy loading is a technique in Angular that allows you to load JavaScript components asynchronously when a specific route is activated. This can add some initial performance during the initial load, especially if you have many components with complex routing. There are some good post about lazy loading in angular, but I wanted to simplify it further.

Sonu Baghel

Mar 1st 12:44pm

Webpack setup

Setting up the Webpack side of things is fairly trivial, but essentially we need just a few key pieces.

Choosing a router loader
You may wish to use the angular-router-loader or ng-router-loader to accomplish your lazy loading mission - I’m going to roll with the former, angular-router-loader as it’s pretty simple to get working and both cover the base set of features we’d need for lazy loading.

Here’s how I’ve added it to my Webpack config: lazy_loading_angular_modules

Lazy @ngModules
we have three feature modules that are identical, apart from renaming of the module and components to suit.
Feature modules
Feature modules, aka child modules, are the modules that we can lazy load using the router. Here are the three child module names:
  • HomeModule
  • AboutModule And the parent, app module:
  • AppModule
lazy loading structure of our app directory would be like this
lazy_loading_angular_modules The AppModule has the responsibility at this point to somehow “import” those other modules. There are a few ways we can do this, asynchronously and synchronously.
Async module lazy loading
We look to the router to power our lazy loading, and all we need for it is the magical loadChildren property on our routing definitions. Here’s the HomeModule: lazy_loading_angular_modules Note how we’re using an empty path : lazy_loading_angular_modules This module can then be used together with loadChildren and path in a parent module, letting AppModule dictate the URL. This creates a flexible module structure where your feature modules are “unaware” of their absolute path, they become relative paths based on the AppModule paths. This means that inside app.module, we can do this: lazy_loading_angular_modules The full picture of the AppModule routing definitions: lazy_loading_angular_modules This means at any moment in time, we can “move” an entire module under a new route path and everything will work as intended to, which is great! Notice in the recording below how *-chunk.js files are being loaded in as we navigate to these particular routes.

Load Balancer Configuration in Web Servers

Madan Mohan Jadon

Mar 5 12:44pm

Internet is one of the greatest invention of 21st century.
More than 54% of world’s population usage internet.
Sites receiving unprecedented workload.
google.com (113,533,299 hits/day), youtube.com (104,337,118 hits/day), facebook.com(88,347,439 hits/day), are top searched sites according to Amazon's traffic rating.
Above all are having multiple data centers and Web Servers to fulfill all requests.
What is Load Balance?
1. Load Balancing refers to efficiently distributing incoming network traffic across a group of backend servers.
2. Load balancing is a key component of highly-available infrastructures.
3. commonly used to improve the performance and reliability of web sites, applications, databases and other services by distributing the workload across multiple servers.
Why Load Balance is required for Web Servers?
Modern high-traffic websites must serve hundreds of thousands concurrent requests from users or clients and return the correct text, images, video, or application data, all in a fast and reliable manner. To cost-effectively scale to meet these high volumes, modern computing best practice generally requires adding more servers.
In this manner, a load balancer performs the following functions:
  • Distributes client requests or network load efficiently across multiple servers.
  • Ensures high availability and reliability by sending requests only to servers that are online.
  • Provides the flexibility to add or subtract servers as demand dictates.
How Load Balance works for Web Servers?
  • In a basic load balancing setup, clients send their requests to the IP address of a virtual server.
  • The virtual server distributes them to the load-balanced application servers according to a preset pattern, called the load balancing algorithm.
How Load Balance works for Web Servers?
  • In the example illustrated above, the user accesses the load balancer, which forwards the user's request to a backend server, which then responds directly to the user's request.
  • In this scenario, the single point of failure is now the load balancer itself.
  • This can be mitigated by introducing a second load balancer, but before we discuss that, let's explore how load balancers work.
How does the load balancer choose the backend server?
Load balancers choose which server to forward a request to based on a combination of two factors :
  • Health Checks
  • Load Balancing Algorithms
Health Checks :
  • Load balancers should only forward traffic to "healthy" backend servers.
  • It regularly attempt to connect to backend servers using the protocol and port defined by the forwarding rules to ensure that servers are listening.
  • it automatically remove unhealthy servers from the pool, and traffic will not be forwarded to it.
Load Balancing Algorithms:
  • Round Robin- servers will be selected sequentially.
  • Least Connections - Load balancer will select the server with the least connections.
  • Source - This method ensures that a particular user will consistently connect to the same server.
Load Balance in IIS Servers
  • Set-Up Application Request Routing Module.
  • Set-Up a Web farm of Web Servers.
Application Request Routing Module :
  • It is a proxy-based routing module that forwards HTTP requests to application servers based on HTTP headers, server variables, and load balance algorithms.
  • ARR Version 2 works with IIS 7 and Above.
Installation Steps & Package Info :
ARR Module Package contains following
  • Microsoft URL Rewrite Module for IIS.
  • Microsoft Web Farm Management Version 1 for IIS.
  • Microsoft Application Request Routing Version 1 for IIS.
  • Microsoft External Cache Version 1 for IIS.
  • Step 1 - Download Microsoft Application Request Routing Version 2 .
  • Step 2 - Install Microsoft Application Request Routing Version 2.
  • Step 3 - Change application pool process model for Application Request Routing.
  • Step 4 - Change application pool recycling settings for Application Request Routing.
URL Rewrite Module : it comes with ARR Module package.
  • It is used to create powerful customized rules to map request URLs to friendly URLs. We can use the URL Rewrite module to perform URL manipulation tasks.
  • Perform redirects, send custom responses, or stop HTTP requests based on the logic expressed in the rewrite rules.
  • Control access to Web site content based on URL segments or request metadata.
  • A rewrite rule defines the logic of what to compare or match the request URL with, and what to do if the comparison is successful.
Rewrite rules consists of the following parts:
  • Pattern
  • Conditions
  • Action 
Rules Evaluation
  • If URL does not match, the URL Rewrite Module immediately stops processing that rule, and goes on to the next rule.
  • If a pattern matches and there are no conditions for the rule, the URL Rewrite Module performs the action specified for this rule
  • If a pattern matches and there are conditions for the rule, the URL Rewrite Module evaluates the conditions. If the evaluation is successful, the specified rule action is performed.
Set-Up a web farm of web servers : there are multiple steps to develop a web farms.
  • IIS Web Farm Infrastructure :
    There are many ways to design the infrastructure of a web farm. in Local Content Infrastructure , each web server needs to store content locally. in Shared Network Content Infrastructure , content configures all web servers point to a central location.
  • IIS Web Farm Configuration :
    determine what is needed to configure shared content and shared configuration. Shared configuration is an IIS feature that helps support homogeneous web farms where all web servers share the same configuration. You enable shared configuration in two steps by using the IIS Manager.
    • Export the configuration files to a shared folder on the back-end file server.
    • Point IIS to the UNC path for that shared folder.
    Set up a shared folder on file server and create user or user group who can access that content.
  • Plan a Load Balancer : ARR is used for load balancing.
  • A key feature of ARR is called host name affinity. Host name affinity creates an affinity (close connection) between requests and a given server (or set of servers).
  • This ensures that a given site is consuming resources only on a defined number of servers.
  • Prepare a list of IP addresses for all servers in your farm.
  • Other features can be enabled as per requirements.
No results found