Using the Document Viewer with a load balancer

<< Click to Display Table of Contents >>

Navigation:  Gnostice Document Studio .NET > Going Deeper > Document Viewing > ASP.NET >

Using the Document Viewer with a load balancer

A load balancer is commonly used to ensure high availability and handle high usage traffic to an application. The picture below shows the ASP.NET Document Viewer deployed within a load-balanced infrastructure.

 

XDOC_N~1_img275

 

A load balancer uses an algorithm to determine the routing of incoming requests from the clients. The algorithm is used to choose the specific server which should handle the request. Some of the common routing algorithms are Round Robin, weighted Round Robin, and Random. The load balancer also contains a setting to override the algorithm and use a specific server - this is where the balancer uses some information from the client (such as client IP) to route all requests from a client to a particular server. This setting is named differently by different load-balancers. Some of the names used are sticky-sessions, server affinity, and server-persistence. However using this setting is not optimal since the algorithm is overridden leading to unbalancing of the load on the available servers. Also if for some reason a server goes down then the affinity can no longer be maintained.

 

In order to speed up the document viewing experience the ASP.NET Document Viewer caches processed data on the server. The supported cache storage locations are in-memory, and database. When in-memory caching is used the processed data is cached on the server which receives the first request from a new client starting a viewing session. This in-memory cache can only be accessed by that specific server so subsequent requests from that client should ideally be served by that specific server. If the subsequent requests go to a different server, then that server will have to open the document and reprocess it, which will slow down the viewing experience as well as consume extra memory. Therefore when in-memory caching is used the load balancer setting for sticky-sessions should be turned on. To use the Document Viewer in such a scenario the default settings as mentioned in the Getting Started section will suffice.

 

Given the above disadvantage of using the sticky-sessions setting, we recommend the use of database caching. In which case, processed data is stored on a centralized database that can be accessed by all servers.

 

The Document Viewer uses Entity Framework to access the database. Entity Framework supports Microsoft SQL Server, SQLite, and others. If you already have a supported database engine installed then the Document Viewer can use the same for hosting its database. You can create a new database on your existing database engine and obtain the connection string to it. If you don’t have an existing database engine you can install one of the supported database engines and create a new database on it and obtain the connection string to it. You can then follow the steps given below to use database caching.

 

1.Follow the instructions given in the Getting Started section.

2.For ASP.NET: Open web.config file and make changes to <appSettings> section to look like the following.

 

    <appSettings>
        <!-- Supported options are "memory" and "database" -->
        <add key="DocumentCache" value="database" />
        <!-- DBConnectionStringName is required -->
        <add key="DBConnectionStringName" value="GITSampleDatabase" />
        <!-- Set up optional settings -->
        <add key="DBCleanupRetentionTime" value="0.004" />
        <add key="DBCleanupIntervalTime" value="1"/>
    </appSettings>
    <connectionStrings>
        <!-- Specify the database connection strings -->
        <add name="GITSampleDatabase" connectionString="Data Source=.,Catalog=ViewerDB;Integrated Security=True" providerName="System.Data.SqlClient" />
    </connectionStrings>

 

 

2.For ASP.NET Core: Open appsettings.json file and add the following settings to it.

  

  "GnosticeControlSettings": {

    "DocumentCache""database",

    "DatabaseCleanup": {

      "DBCleanupRetentionTime""10",

      "DBCleanupIntervalTime""7",

      "DBCleanupRetentionSize""1240",

    }

  },

 "ConnectionStrings": {

    "SQLConnection""<Connection string here>"

  }

 

 

3.Install the following NuGet packages

a.For ASP.NET: EntityFramework Version 6.x

a.For ASP.NET Core: Microsoft.EntityFrameworkCore.SqlServer - Choose the version based on the following

i.Version 6.x for .NET 6

ii.Version 5.x for .NET 5 and .NET Core 3.1

 

For additional settings related to database caching you can look at the reference API documentation here.