I'm a bit new to the entire umbraco thing, but have been using it for a few months now and have some questions about
load balancing that I hope someone can give me pointers on.
I have the site (v7.11.1) setup in Azure and was looking to add another copy of the site, but to a different location e.g. East US.
From the bits of info I have found, it seems Umbraco can do this out of the box. I have done a quick test setup and it does seem to work.
The only thing that doesn't work is some custom code that runs when items are published. The site has some custom caching and when items are published it expires the content out of the cache.
This works just fine on the 'main' site where the edits are being done, but the code doesn't fire on the 'secondary' site so the cache is not cleared. Is there anyway to have the code run on the 'secondary' site when it content is changed?
I tried to find info in the docs, but my experience so far has been that the docs aren't always up to date :(
Also for load balancing what is the best setup to have? is it better to have 2 public servers for the frontend and 1 private server to do edits on?
We have noticed the site restart when there is a lot of editing/publishing going on, so was wondering if the split of frontend servers and one for editing might help with keeping the public facing part of the site up?
For updating your cache on your load balanced server you need to use different events. You need to hook in to the PageCacheRefresher.CacheUpdated event.
This is an event that will execute on all servers after a publish
Thanks for the reply, had a quick play with it in a single server setup and looks like the cache busting / removal code should have always been in that method.
Another question now, any ideas under what circumstances the MessageType is RefreshById?
I couldn't trigger this condition in the code
if (e.MessageType == MessageType.RefreshById || e.MessageType == MessageType.RemoveById)
I tried publishing a single item and publishing a subtree and both times the MessageType was RefreshByInstance.
Ok, I've had a little more time to test it out and the RefreshById and RemoveById conditions do get triggered on the 'secondary' server.
So the RefreshByInstance and RemoveByInstance happens on the server the publish event came from and the RefreshById and RemoveById happen on other servers picking up the change.
This is the code I finally ended up with, in case it helps anyone else:
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
PageCacheRefresher.CacheUpdated += PageCacheRefresher_CacheUpdated;
}
private void PageCacheRefresher_CacheUpdated(PageCacheRefresher sender, Umbraco.Core.Cache.CacheRefresherEventArgs e)
{
string key = null;
var cache = new CacheService();
if (e.MessageType == MessageType.RefreshByInstance || e.MessageType == MessageType.RemoveByInstance)
{
var content = (Umbraco.Core.Models.Content)e.MessageObject;
key = CacheService.GetCacheKeyForModel(content);
}
else if (e.MessageType == MessageType.RefreshById || e.MessageType == MessageType.RemoveById)
{
int id = (int)e.MessageObject;
var content = ApplicationContext.Current.Services.ContentService.GetById(id);
key = CacheService.GetCacheKeyForModel(content);
}
if (!string.IsNullOrEmpty(key))
cache.Delete(key, true);
}
just ignore the CacheService lines. Also in this situation there is no UmbracoContext so have used the Content service to get the model (as I needed that to create my key)
Load balancing and the Published event
Hi,
I'm a bit new to the entire umbraco thing, but have been using it for a few months now and have some questions about load balancing that I hope someone can give me pointers on.
I have the site (v7.11.1) setup in Azure and was looking to add another copy of the site, but to a different location e.g. East US. From the bits of info I have found, it seems Umbraco can do this out of the box. I have done a quick test setup and it does seem to work.
The only thing that doesn't work is some custom code that runs when items are published. The site has some custom caching and when items are published it expires the content out of the cache.
This works just fine on the 'main' site where the edits are being done, but the code doesn't fire on the 'secondary' site so the cache is not cleared. Is there anyway to have the code run on the 'secondary' site when it content is changed? I tried to find info in the docs, but my experience so far has been that the docs aren't always up to date :(
Also for load balancing what is the best setup to have? is it better to have 2 public servers for the frontend and 1 private server to do edits on?
We have noticed the site restart when there is a lot of editing/publishing going on, so was wondering if the split of frontend servers and one for editing might help with keeping the public facing part of the site up?
Many Thanks
Hi Dave,
Dave here :-)
For updating your cache on your load balanced server you need to use different events. You need to hook in to the PageCacheRefresher.CacheUpdated event.
This is an event that will execute on all servers after a publish
You can find an example in this post :
https://our.umbraco.com/forum/using-umbraco-and-getting-started/79614-memory-cache-refresh
Dave
Hi Dave :)
Thanks for the reply, had a quick play with it in a single server setup and looks like the cache busting / removal code should have always been in that method.
Another question now, any ideas under what circumstances the MessageType is RefreshById?
I couldn't trigger this condition in the code
I tried publishing a single item and publishing a subtree and both times the MessageType was RefreshByInstance.
Ok, I've had a little more time to test it out and the RefreshById and RemoveById conditions do get triggered on the 'secondary' server.
So the RefreshByInstance and RemoveByInstance happens on the server the publish event came from and the RefreshById and RemoveById happen on other servers picking up the change.
This is the code I finally ended up with, in case it helps anyone else:
just ignore the CacheService lines. Also in this situation there is no UmbracoContext so have used the Content service to get the model (as I needed that to create my key)
Nice clarification !
Dave
is working on a reply...