July 27, 2008 21:46 by Naz
I'm part of the small open source team for dashCommerce an .NET shopping cart system so please don't get me wrong this article isn't about dissing the hard work and time developers have put into BlogEngine it is just to highlight some of the the design flaws I've encountered which we should help to improve on in future versions. I will still continue to use blogengine as it's still the best out there but it can be better...
This site is currently distributed across multiple web servers sometimes referred to as “Cloud Hosting”. Many large popular websites work of this kind of architecture to keep up with demand of resources required to process user requests. I’ve read somewhere Facebook currently has around 200 distributed web servers for hosting their site at various parts of the world.
BlogEngine runs of a singleton caching model where it caches posts and comments into an static object and then reads and writes that object to either an XML or Database when required. A common problem with this design is each server does not have direct access to the in memory object. Due to this when a comment is posted on server 1 gets saved to database, server 2 doesn't know that there has been change so you wont see the update until server 2 updates itself. However there are some work-rounds the simplest is just using the standard .NET caching model instead of singleton caching as you can specify an expiration times and also set-up things like cache dependency enabling your servers can get back to sync.
Recently I’ve been having problems as the site has gotten more popular I’ve had comments and even posts disappearing randomly, sometimes re-appearing you might have experienced this yourself either on my site or in your own so after divulging into the code to see what was happening found something I thought was shocking. When you add a comment, or Rating, Approving and Remove Comments this is what BlogEngine DbBlogProvider actually does...
- UPDATE The post
- DELETE All Tags for that post
- INSERT All Tags for that post
- DELETE All Posts Categories
- INSERT All Posts Categories
- DELETE All existing comments for that post
- INSERT All comments back in including the new comment
- DELETE All post notifications
- INSERT All post notifications
Remember all this when all it needed to do is INSERT into Comments table the new Comment!
From what I can see (I could be wrong) it is doing it without an SqlTransaction so if something where to go wrong it wont rollback changes. This can also cause concurrancy issues say if two people are adding comments at the same time i'm not sure if it will lock it. So instead of just getting delayed updates my web servers are actually in constant battle with each other overwriting each others changes when they save content every time someone post's a comment or rates an article.
I hacked a workaround so Add Comment just does what it needs to by adding new Abstract Methods to BlogProvider but this meant I had to write the same methods for XMLProvider but XML's and relational databases are completely different so I just stubbed them out.
I hope the developers take note about this for future versions there might have been a reason for this the only thing I can think of is they tried to reduce the number of methods a BlogProvider requires.