Load Balancing the Dashboard server

Architecture

The Panintelligence Dashboard is made up of 6 different services or components:

  1. MariaDB database to store the PiDashboard configuration

  2. Core Dashboard (served by tomcat)

  3. Excel Reader to use Excel as a data source

  4. Renderer to convert charts into PDF/Word/PPT/PNG.

  5. Pirana that serves as the machine-learning Analytics engine

  6. Scheduler to support PiReports with sending reports at given recurrences

Assuming you want the architecture below:

 

Where each component may or may not share a machine.

Pirana (as pictured above), Scheduler, Renderer and Excel Reader components are stateless so they do not require session synchronisation if you want to load-balance them.

We highly recommend that you load balance Pirana as well, even if you keep it in one machine as it helps it take advantage of multiple cores.

Configuring the Dashboard

You’ll have to tell the dashboard where its database lives, what the session cookie name is and, if you want to use session sync, the tomcat cluster. Currently you’ll always need to edit at least 1 XML configuration file.

Using containers

For containers you can configure them using environment variables but you’ll still need to edit one XML file for now.

Configuring the database location

You can use environment variables to configure where the database lives:

PI_DB_HOST

Database host

PI_DB_PORT

Database port

PI_DB_USERNAME

Database username

PI_DB_PASSWORD

Database password

These can be specified as per the instructions on our Docker Deployments repository.

Configuring the session cookie name

If any of the dashboards is set to a different port than the others, you might have to check that all nodes are setting the same cookie. To do this, make sure the following file is configured as a volume for ease of editing:

<dashboard installation>/Dashboard/tomcat/conf/context.xml

Then edit the following line

<Context sessionCookieName="DASHBOARDSESSIONID8224">

The sessionCookieName can be anything you like as long as it’s the same for all nodes.

Using native hosts

Configuring the database location

You can use the same environment variables as defined in “Using Containers” or you can edit the configuration files yourself like below.

You need to specify the database URL on the tomcat configuration files, i.e. you’ll need to edit the following XML files:

<dashboard installation>/Dashboard/tomcat/conf/Catalina/localhost/panMISDashboardWebServices.xml <dashboard installation>/Dashboard/tomcat/conf/Catalina/localhost/panSecurity.xml <dashboard installation>/Dashboard/tomcat/conf/Catalina/localhost/pi.xml

With an editor, change all entries in those files with the string

to

where database is the IP or domain to your database machine and port is the port where the database is listening to.

Configuring the session cookie name

If any of the dashboards is set to a different port than the others, you might have to check that all nodes are setting the same cookie. To do this, check the following file:

Verify that the following line is the same across all your nodes:

The sessionCookieName can be anything you like as long as it’s the same for all nodes.

Configuring the Dashboard Load Balancer

With nginx

Edit your nginx.conf or your individual site configuration and add an ‘upstream’ section:

And change your server section to proxy requests to the upstream block you’ve configured:

For the complete nginx config, see attached nginx.conf (link at the bottom).

Access your load balancer and you should see the dashboard.

Configuring session sharing

With nginx

Modify your upstream with the ip_hash directive:

Don’t use ip_hash if it’s possible that two clients could share an IP (such as if they’re on a NAT)

This should work on most cases, but if it doesn't suit your scenario see nginx's documentation about session persistence, or see the tomcat config below.