Kooboo CMS load balance

From Kooboo document
Jump to: navigation, search

In order to achieve load balance from deploying the Kooboo CMS in the servers cluster, additional providers' sharing data and files among servers are required. In Kooboo CMS, data to be shared are:

  • Pages The pages can be updated on one of the servers in the cluster by using inline editing.
  • HMTL blocks The HMTL blocks can be updated.
  • Labels, inline editing or translation at runtime.
  • Media files The Media files need be shared to enable every server to manage the media library.
  • Attachments for text content Attachments for text content are the same as media files.
  • Text content Text content are using the shared database engines (e.g. SQLServer, MySQL, MongoDB).

Other kinds of data like Sites, Layouts, Views etc that are considered to be updated frequently in the development progress, will not be updated frequently at runtime. To simplify the sharing solution, those data are designed not to be shared at runtime. Changing those data will be taken by Kooboo CMS as application upgrading and the changes need to be manually updated on each server.

Pages,HTML blocks and Labels are structured data and will be saved into the relation-database. Therefore, we have ahad the SQLServer provider implemented in Kooboo CMS.

There is a file server specially used to host the Media files and Media attachment. So the media files can be jointly managed by all severs using the file server API.

Setup file server

  • Download the FileServer_Web.zip(FileServer.zip) from [[1]]
  • Extract the FileServer_Web.zip to a folder.
  • Setup a IIS web site to host the FileServer.
  • Edit the file serve web.config to customize the settings.
 
 <appSettings>
    <add key="AccountName" value="devstoreaccount1"/>
    <add key="AccountKey" value="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="/>
    <add key="BaseUri" value=""/>
  </appSettings>
 
 - AccountName: The account name that gives you access to request the RESTful API that provided by file server.
 - AccountKey: The password for the account.
 - BaseUri: BaseUri is used to customize the file url that used in Kooboo CMS.

Setup the FileServer Provider in Kooboo CMS

  • Download Content_Providers.zip, unzip the folder "FileServerProvider".
  • Copy "Kooboo.CMS.Content.FileServer.Interfaces.dll", "Kooboo.CMS.Content.Persistence.FileServerProvider.dll" and "FileServerProviderSettings.config" and paste them into the BIN folder.
  • Edit the "FileServerProviderSettings.config" and setup the connection string.
 
<FileServerProviderSettings xmlns="http://schemas.datacontract.org/2004/07/Kooboo.CMS.Content.Persistence.FileServerProvider" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <AccountKey>Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==</AccountKey>
  <AccountName>devstoreaccount1</AccountName>
  <Endpoint>http://localhost:8626/</Endpoint>
</FileServerProviderSettings>
 

Setup the site data SQLServer provider in Kooboo CMS

SQLServer provider is used to store the Pages/Html blocks/Labels in SQLServer. How to setup the SQLServer provider in Kooboo CMS:

  • Copy "EntityFramework.dll","Kooboo.CMS.Sites.Providers.SqlServer.dll" and "SiteOnSQLServerSettings.config" and paste them into the BIN folder.
  • create a new database or use an existing database to run the following T-SQL to create the tables:
 
/****** Object:  Table [dbo].[Pages]    Script Date: 02/22/2012 10:28:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Pages]') AND TYPE IN (N'U'))
BEGIN
CREATE TABLE [dbo].[Pages](
	[SiteName] [nvarchar](128) NOT NULL,
	[FullName] [nvarchar](128) NOT NULL,
	[ParentPage] [nvarchar](128) NULL,
	[IsDefault] [bit] NOT NULL,
	[ObjectXml] [nvarchar](MAX) NULL,
 CONSTRAINT [PK_Pages] PRIMARY KEY CLUSTERED 
(
	[SiteName] ASC,
	[FullName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[PageDrafts]    Script Date: 02/22/2012 10:28:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PageDrafts]') AND TYPE IN (N'U'))
BEGIN
CREATE TABLE [dbo].[PageDrafts](
	[SiteName] [nvarchar](128) NOT NULL,
	[FullName] [nvarchar](128) NOT NULL,
	[ParentPage] [nvarchar](128) NULL,
	[IsDefault] [bit] NOT NULL,
	[ObjectXml] [nvarchar](MAX) NULL,
 CONSTRAINT [PK_PageDrafts] PRIMARY KEY CLUSTERED 
(
	[SiteName] ASC,
	[FullName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Labels]    Script Date: 02/22/2012 10:28:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Labels]') AND TYPE IN (N'U'))
BEGIN
CREATE TABLE [dbo].[Labels](
	[SiteName] [nvarchar](128) NOT NULL,
	[Name] [nvarchar](128) NOT NULL,
	[Category] [nvarchar](128) NOT NULL,
	[VALUE] [nvarchar](MAX) NULL,
 CONSTRAINT [PK_Labels] PRIMARY KEY CLUSTERED 
(
	[SiteName] ASC,
	[Name] ASC,
	[Category] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[LabelCategories]    Script Date: 02/22/2012 10:28:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LabelCategories]') AND TYPE IN (N'U'))
BEGIN
CREATE TABLE [dbo].[LabelCategories](
	[SiteName] [nvarchar](128) NOT NULL,
	[CategoryName] [nvarchar](128) NOT NULL,
 CONSTRAINT [PK_LabelCategories] PRIMARY KEY CLUSTERED 
(
	[SiteName] ASC,
	[CategoryName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[HtmlBlocks]    Script Date: 02/22/2012 10:28:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HtmlBlocks]') AND TYPE IN (N'U'))
BEGIN
CREATE TABLE [dbo].[HtmlBlocks](
	[SiteName] [nvarchar](128) NOT NULL,
	[Name] [nvarchar](128) NOT NULL,
	[Body] [nvarchar](MAX) NULL,
 CONSTRAINT [PK_HtmlBlocks] PRIMARY KEY CLUSTERED 
(
	[SiteName] ASC,
	[Name] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
 
/****** Object:  Table [dbo].[SiteUsers]    Script Date: 05/15/2012 14:04:33 ******/
SET ANSI_NULLS ON
GO
 
SET QUOTED_IDENTIFIER ON
GO
 
CREATE TABLE [dbo].[SiteUsers](
	[SiteName] [nvarchar](128) NOT NULL,
	[UserName] [nvarchar](128) NOT NULL,	
	[ObjectXml] [nvarchar](MAX) NULL,
 CONSTRAINT [PK_SiteUsers] PRIMARY KEY CLUSTERED 
(
	[SiteName] ASC,
	[UserName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
 
GO
 
  • Edit the "SiteOnSQLServerSettings.config" setup the connection string.
 
<SiteOnSQLServerSettings xmlns="http://schemas.datacontract.org/2004/07/Kooboo.CMS.Sites.Providers.SqlServer" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <ConnectionString>Server=.\SQLExpress;Database=Kooboo_CMS; Trusted_Connection=Yes;</ConnectionString>
</SiteOnSQLServerSettings>
 

Sync the memory cache between different servers


Every server in the cluster will have its owner memory cache. But sometimes the page will changed in the other server, but it do not catch the update action, so it do not expire the cache in the memory cache. The Kooboo CMS have a memory cache sync solution is when one server expire a cache, it will notice the other servers remove the cache value using the same key.

Setup the memory cache synchronization


  • Make sure the "Kooboo.CMS.Caching.NotifyRemote.dll" exists in the BIN folder.
  • Uncomment these lines in the "Web.confg"
 
  <cache.notify>
    <servers>
      <add name="localhost" url="http://127.0.0.1/sites/cache/clear" delay="0"/>
    </servers>
  </cache.notify>
 
  - name: The server name.
  - url: The cache service clear API.
  - delay: The time it takes to request the API after a cache expired.