How to use storage on CDNs

0
11

A content delivery network (CDN) is a distributed network of servers that can deliver web content to users efficiently. To reduce latency, CDNs store cached content on edge servers in point-of-presence (POP) locations close to end users.

By caching their content at strategically placed physical nodes around the world, Azure Content Delivery Network (CDN) provides developers with a global solution for rapidly delivering high-bandwidth content to users. By leveraging various network optimizations using CDN POPs, Azure CDN can also accelerate dynamic content that cannot be cached. For instance, route optimization to avoid the Border Gateway Protocol (BGP).

The following are some of the advantages of using Azure CDN to deliver web site assets:

  • Improved performance and user experience for end users, particularly when using applications that require multiple round-trips to load content.
  • Large scaling to handle high loads in an instant, such as the start of a product launch event.
  • Distribution of user requests and content delivery directly from edge servers, reducing traffic to the origin server.

How Azure Content Delivery Network works

  1. A user requests a file (also known as an asset) via a URL containing a special domain name, such as <endpoint name>. azureedge.net. This name can be a custom domain or an endpoint hostname. The DNS sends the request to the best-performing POP location, which is usually the POP closest to the user.
  2. If none of the POP’s edge servers have the file in their cache, the POP requests it from the origin server. An Azure Web App, Azure Cloud Service, Azure Storage account, or any publicly accessible web server can serve as the origin server.
  3. The file is returned by the origin server to an edge server in the POP.
  4. A POP edge server caches the file and returns it to the original requestor. The file is cached on the POP edge server until the time-to-live (TTL) specified in its HTTP headers expires. The default TTL is seven days if the origin server did not specify one.
  5. Additional users can then request the same file as Alice by using the same URL and being directed to the same POP.
  6. If the file’s TTL has not expired, the POP edge server returns it directly from the cache. This process results in a more responsive and faster user experience.

Requirements

  • Must create at least one CDN profile (a collection of CDN endpoints).
  • Every CDN endpoint represents a unique configuration of content delivery and access behavior.
  • You can use multiple profiles to organize your CDN endpoints by internet domain, web application, or other criteria.

Limitations

The following resources have default limits in each Azure subscription:

  • The maximum number of CDN profiles that may be created.
  • The maximum number of endpoints that a CDN profile can have.
  • The number of custom domains that can be associated with a given endpoint.

Azure Content Delivery Network products

The Azure Content Delivery Network (CDN) consists of four products:

  • Azure CDN Standard from Microsoft
  • Azure CDN Standard from Akamai
  • Azure CDN Standard from Verizon
  • Azure CDN Premium from Verizon

Cache behavior on Azure Content Delivery Networks

A cached resource is not compared to the version on the origin server every time it is accessed to save time and bandwidth. Instead, as long as a cached resource is deemed fresh, it is assumed to be the most recent version and is delivered directly to the client. When the age of a cached resource is less than the age or period defined by a cache setting, it is considered fresh. When a browser reloads a webpage, for example, it verifies that each cached resource on your hard drive is fresh and then loads it. If the resource is out of date (stale), a new copy is downloaded from the server.

Azure CDNs offer two methods for caching files. These configuration settings, however, are determined by the tier you’ve chosen. Caching rules in Azure CDN Standard for Microsoft are configured at the endpoint level and come in three flavors. Other tiers offer additional configuration options, such as:

  • Caching rules : Can be global (applicable to all content from a specific endpoint) or custom. Custom rules apply to specific file extensions and paths.
  • Query string caching : Can configure how Azure CDN responds to a query string using query string caching. Caching query strings has no effect on files that cannot be cached.

Interact with Azure Content Delivery Networks by using .NET

The Azure CDN Library for.NET can be used to automate the creation and management of CDN profiles and endpoints. Install the Microsoft.Azure.Management.Cdn.Fluent using the.NET Core CLI or the Visual Studio Package Manager console.

Create a CDN client


static void Main(string[] args)
{
    // Create CDN client
    CdnManagementClient cdn = new CdnManagementClient(new TokenCredentials(authResult.AccessToken))
        { SubscriptionId = subscriptionId };
}
 

List CDN profiles and endpoints


private static void ListProfilesAndEndpoints(CdnManagementClient cdn)
{
    // List all the CDN profiles in this resource group
    var profileList = cdn.Profiles.ListByResourceGroup(resourceGroupName);
    foreach (Profile p in profileList)
    {
        Console.WriteLine("CDN profile {0}", p.Name);
        if (p.Name.Equals(profileName, StringComparison.OrdinalIgnoreCase))
        {
            // Hey, that's the name of the CDN profile we want to create!
            profileAlreadyExists = true;
        }

        //List all the CDN endpoints on this CDN profile
        Console.WriteLine("Endpoints:");
        var endpointList = cdn.Endpoints.ListByProfile(p.Name, resourceGroupName);
        foreach (Endpoint e in endpointList)
        {
            Console.WriteLine("-{0} ({1})", e.Name, e.HostName);
            if (e.Name.Equals(endpointName, StringComparison.OrdinalIgnoreCase))
            {
                // The unique endpoint name already exists.
                endpointAlreadyExists = true;
            }
        }
        Console.WriteLine();
    }
}
 

Create CDN profiles and endpoints


private static void CreateCdnProfile(CdnManagementClient cdn)
{
    if (profileAlreadyExists)
    {
        //Check to see if the profile already exists
    }
    else
    {
        //Create the new profile
        ProfileCreateParameters profileParms =
            new ProfileCreateParameters() { Location = resourceLocation, Sku = new Sku(SkuName.StandardVerizon) };
        cdn.Profiles.Create(profileName, profileParms, resourceGroupName);
    }
}
 

We’ll create an endpoint after we finish the profile.


private static void CreateCdnEndpoint(CdnManagementClient cdn)
{
    if (endpointAlreadyExists)
    {
        //Check to see if the endpoint already exists
    }
    else
    {
        //Create the new endpoint
        EndpointCreateParameters endpointParms =
            new EndpointCreateParameters()
            {
                Origins = new List() { new DeepCreatedOrigin("Contoso", "www.contoso.com") },
                IsHttpAllowed = true,
                IsHttpsAllowed = true,
                Location = resourceLocation
            };
        cdn.Endpoints.Create(endpointName, endpointParms, profileName, resourceGroupName);
    }
}
 

Purge an endpoint


private static void PromptPurgeCdnEndpoint(CdnManagementClient cdn)
{
    if (PromptUser(String.Format("Purge CDN endpoint {0}?", endpointName)))
    {
        Console.WriteLine("Purging endpoint. Please wait...");
        cdn.Endpoints.PurgeContent(resourceGroupName, profileName, endpointName, new List() { "/*" });
        Console.WriteLine("Done.");
        Console.WriteLine();
    }
}
 

Comments

comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here