Showing posts with label Velocity. Show all posts
Showing posts with label Velocity. Show all posts

Tuesday, 20 April 2010

Building A PageStatePersister With AppFabric

One of my favourite demos to do at user group sessions is to show off how you can use the SessionPageStatePersister to store page state information (Viewstate and Controlstate) on the server in Session state instead of round-tripping it to the client. But yesterday it occurred to me that you could do the same thing quite easily with AppFabric caching*.

ASP.NET has shipped with two page state persistence mechanisms since ASP.NET 2.0 was released - HiddenFieldPageStatePersister, which is the one used by default and produces those <input id="__VIEWSTATE" type="hidden" value="AnEnormousBase64EncodedTree" /> tags that we all hate so much, and SessionPageStatePersister, which instead stores the state on the web server in Session state and cuts out the roundtripping. To use the SessionPageStatePersister you need to write an Adapter class and a .browser file:

using System.Web.UI;
using System.Web.UI.Adapters;

namespace Adapter
{
    public class Adapter: System.Web.UI.Adapters.PageAdapter
    {
        public override PageStatePersister GetStatePersister()
        {
            return new SessionPageStatePersister(this.Page);
        }
    }

<browser refID="default">
    <controladapters>
        <adapter controltype="System.Web.UI.Page">
            adapterType="Adapter.Adapter" />
    </controladapters>
</browser>

SessionPageStatePersister is built into the .NET Framework, so our adapter can just new it up and return it in the GetStatePersister function. If we want to build a PageStatePersister with AppFabric, however, we've got a bit more work to do. We need a class that inherits from PageStatePersister so we can implement the Save and Load methods.

using System.Web.UI;
using System.Web.UI.WebControls;

namespace AppFabricPageStatePersister
{

    public class Persister : System.Web.UI.PageStatePersister
    {
        public Persister(Page page) : base(page)
        {
        }


        private const string HiddenFieldId = "StateIdHiddenField";


        public override void Load()
        {
            // Read page's incoming state Id from hidden field
            string stateIdString = Page.Request.Form[HiddenFieldId];


            Pair cachedState = (Pair) CacheHelper.Get(stateIdString);


            ViewState = cachedState.First;
            ControlState = cachedState.Second;
        }


        public override void Save()
        {
            Pair statePair;


            // Build a Pair from the Page's View- and ControlState
            statePair = new Pair(ViewState, ControlState);


            // Generate a new ID to use as the key for storing in the cache
            Guid stateId = Guid.NewGuid();


            // Put the Pair in the cache
            CacheHelper.Put(stateId.ToString(), statePair);


            // Write the key out into the page in a hidden field so we can get it back later
            Page.ClientScript.RegisterHiddenField(HiddenFieldId, stateId.ToString());
        }
    }
}

CacheHelper is an abstraction over AppFabric so my Persister class isn't cluttered with calls to the AppFabric objects:

using System.Web.Configuration
using Microsoft.ApplicationServer.Caching;

namespace AppFabricPageStatePersister
{
    class CacheHelper
    {
         public static object Get(string Key)
         {
            DataCacheFactory factory;
            DataCache cache;
            string cacheName;
            factory = new DataCacheFactory();
            cacheName = WebConfigurationManager.AppSettings["StatePersistenceCacheName"].ToString();
            cache = factory.GetCache(cacheName);
            return cache.Get(Key);
       }

       public static void Put(string Key, object Value)
       {
            DataCacheFactory factory;
            DataCache cache;
            string cacheName;

            factory = new DataCacheFactory();
            cacheName = WebConfigurationManager.AppSettings["StatePersistenceCacheName"].ToString();
            cache = factory.GetCache(cacheName);

            cache.Put(Key, Value);
        }
    }
}

The adapter is straightforward - like the SessionPageStatePersister adapter, all it needs to do is return a new instance of AppFabricPageStatePersister, and the .browser file just needs to point at AppFabricPageStatePersister.Adapter.

namespace AppFabricPageStatePersister

{
    public class Adapter : System.Web.UI.Adapters.PageAdapter
    {
        public override System.Web.UI.PageStatePersister GetStatePersister()
        {
            return new Persister(this.Page);
        }
    }
}

<browser refID="default">

    <controlAdapters>
        <adapter controlType="System.Web.UI.Page"
adapterType="AppFabricPageStatePersister.Adapter" />
    </controlAdapters>
</browser>
Simples.

Download this demo code: C# VB

* Yes, I know you could put your Session state in AppFabric and continue to use the SessionPageStatePersister but I'm assuming you can't/don't want to use Session state.

Wednesday, 3 March 2010

What's New in AppFabric Caching Beta 2

Typical - just as I get an AppFabric Beta 1 caching cluster up and running for Edge UG this month, they release Beta 2!

This is, by all accounts, now a feature complete release for v1.0 with the RTM expected in Q3 this year. There is, however, no Go Live licence here, unlike Visual Studio. Let's take a look at AppFabric B2 and see what's changed (from a caching perspective)...

What's New in Installation
First of all, this release is aligned with the Release Candidate of .NET 4.0 and VS2010, so the dependency on the .NET Framework is moved up from the beta to the .NET 4.0 Release Candidate. Note that if you're removing the .NET 4.0 Beta in order to install AppFabric, you need to do this in Control Panel|Programs and Features, and uninstall the .NET 4.0 Framework Extended first, then the the .NET 4.0 Client Profile.

The installer seems to have had quite a bit of time spent on it for this release.
The set of features to install is largely the same as we saw in Beta 1, with the addition of an administration piece for the Dublin workflow component.

Post-installation, the AppFabric caching service has been renamed and no longer refers to the Velocity codename; it also now is not marked as a CTP (unlike the caching service in Appfabric Beta 1 which still showed as CTP4).

Installation and configuration have been decoupled into two separate wizards, which should make it possible to reconfigure a cluster without having to un- and re-install.The configuration wizard can be started at the end of installation, or separately from the Start menu.


What's New in Configuration
As before when configuring the caching piece you have to decide whether to store configuration information in SQL Server or using XML and a network share. There's still no guidance on when you should use one or the other, although included in this release is a comprehensive help file.

Selecting the SQL Server provider and clicking the Configure button opens this sub-dialog where you can build up the connection string to the configuration database. It's now explicit that if you enter the name of a database that doesn't exist and select the 'Create...' checkbox then the configurator will go and create the database for you. If you're adding a server to an existing cluster, then the 'Register...' checkbox is the one to select; if you unselect both checkboxes you lose the ability to enter any connection string information. However there seems to be a slight bug in that whether you create a new database from scratch or register a server to an existing database, when you return to the main configuration screen you can still choose whether you are creating a new cluster or joining an existing cluster.
As before, the configurator allows you set the size of the cluster to optimise the clusters' performance. The help file states that 'once you set the cluster size during configuration, you cannot change it later', however it's unclear how this fits in with the ability to re-run the configurator from the Start menu.

As I run my Velocity VM cluster with Windows Firewall disabled, I'm pleased to see that the Cache Node configuration page now detects when the firewall is disabled and accordingly disables the firewall exceptions checkboxes. This is a change to Beta 1 where the Velocity installer log would register a warning if the firewall was disabled.

What's New in Powershell
In a change from previous installs, there doesn't seem to be a Velocity Administration Powershell console installed by default; to access the Velocity Powershell commands you need to run up Powershell and then run 'import-module DistributedCacheAdministration'. Or you can add it to your Powershell profile - run 'get-help profiles' for details on doing this.
Looking at the list of Powershell commands available it seems that, unforgivably, there's still no commandlets for managing regions.The Install-Data and Install-Bits cmdlets that were in Beta 1 have disappeared.

A new feature is that it seems you can now use Powershell on any server with the Velocity cmdlets installed to manage any Velocity cluster, by using the 'Use-CacheCluster' cmdlet with a connection string to a configuration store (though the documentation talks about a connection string which implies this only works with the SQL Server provider). This cmdlet sets the context of subsequent commands e.g. Start-CacheCluster, Restart-CacheCluster. This enables you to manage multiple clusters from a server that isn't in any cluster. If you're running Use-CacheCluster on a server that is inside a cluster and has Cache Administration (from the installer) set up, you don't need to use any parameters, the current cluster is implied.

What's New in Client Configuration
The assemblies that you need to add to a project to use Velocity have been renamed, to Microsoft.ApplicationServer.Caching.Core.dll and Microsoft.ApplicationServer.Caching.Client.dll (in Windows\System32\AppFabric). The namespace has changed again, to Microsoft.ApplicationServer.Caching. And the requirement to also reference the Fabric assemblies has been removed, so there's only two references to add which makes the whole thing seem much cleaner.
The MSDN article on setting up the client environment states that there is a problem with referencing these DLLs as Visual Studio is unable to browse to Windows\System32\AppFabric, and that you need to hand-edit the project file to include these references. This seems to be incorrect, as I've just done it - I suspect that this may be due to the fact I'm running Visual Studio under an account which is an administrator on the server and thus has access to everything.
A couple of the old annoyances when writing client code are still there:
  • DataCacheFactory.GetCache is still not a static method, you still need to new up a DataCacheFactory.
  • Some of the code around using DataCacheServerEndpoints seems to have been refactored a little bit, but it still runs on an array, not a List(Of DataCacheServerEndPoint). But you can, of course, still get round this by using a List(Of DataCacheServerEndpoint) and then calling .ToArray on it.
That's all I've discovered that's new (for now), but I'll post more updates as I discover things!

Saturday, 20 February 2010

A Developer's Guide To Velocity on tour!

Following on from Liam's recent tour dates blog,I thought I should do something similar...

First of all I need to offer belated thanks to NxtGen Manchester for having me up to speak in January. I had a good time even though something went wonky in my VMs while I was running my demos that morning which meant I couldn't run the demos in the evening. I hope everyone still got an appreciation of the capabilities of Velocity.

I'm running this session again at Edge UG at Microsoft in London on 17th March - visit http://edgeug.net to sign up. I may be running it at DDD Scotland if I've been voted in. Subject to agreement on dates it'll be at NxtGen Southampton in June. I've also been talking to NxtGen Cambridge and NEBytes about doing it for them over the summer.
UPDATE: Well I didn't get voted in for DDD Scotland, but there'll be another opportunity to vote for me at DDD Southwest.And I now have a confirmed date for NxtGen Southampton - 24th June.

Thursday, 28 January 2010

Extensible Output Caching with Velocity

This morning Scott Gu posted an article on his blog about the extensibility points now built into output caching in ASP.NET 4.0. Steve Robbins said to me that it looked easy to wire up Velocity, and I was pleased to see that when ASP.NET 4.0 ships there will be a set of samples showing how to use Velocity as an output cache provider, however since Scott said that writing an output cache provider is just a case of inheriting from System.Web.Caching.OutputCacheProvider and overriding four methods, I decided to have a look at it at lunchtime.

And it does seem remarkably simple - here's my code:
Imports Microsoft.Data.Caching
Public Class VelocityOutputCacheProvider
    Inherits System.Web.Caching.OutputCacheProvider
Private Const cacheName As String = "VelocityOutputCache"
Private mCache As DataCache
Public Sub New()
    Dim factory As DataCacheFactory

    Try
        factory = New DataCacheFactory

        mCache = factory.GetCache(cacheName)
    Catch ex As Exception
        Throw
    Finally
        factory = Nothing
    End Try
End Sub

Public Overrides Function Add(ByVal key As String, ByVal entry As Object, ByVal utcExpiry As Date) As Object
    Try
        mCache.Add(key, entry, (utcExpiry - DateTime.UtcNow))
    Catch ex As Exception
        Throw
    Finally
    End Try
End Function

Public Overrides Sub Remove(ByVal key As String)
    Try
        Call mCache.Remove(key)
    Catch ex As Exception
        Throw
    Finally
    End Try
End Sub
Public Overrides Function [Get](ByVal key As String) As Object
Dim cachedObject As Object
    Try
        cachedObject = mCache.Get(key)
        Return cachedObject
    Catch ex As Exception
       Throw
    Finally
    End Try
End Function
Public Overrides Sub [Set](ByVal key As String, ByVal entry As Object, ByVal utcExpiry As Date)
    Try
        Call mCache.Put(key, entry, (utcExpiry - DateTime.UtcNow))
    Catch ex As Exception
        Throw
    Finally
    End Try
    End Sub
End Class

The only thing I'm a little fuzzy on is what object the Add method should return. It's slightly awkward that the Velocity Cache.Add method takes a TimeSpan parameter where the OutputCacheProvider passes in a point in time, so I've calculated a TimeSpan by subtracting the current time from the passed-in Date.
 
Something that's slightly unclear is how this would behave in a server farm. It depends whether each server maintains it's own set of cached pages, or the cached pages are common and available to all servers. If the latter then this would be a truly awesome boost to scalability since for any given web page only the first server that picked up a request for a given URL would need to compile it - other servers in the farm would then be able to pick up the cached copy and return it to the client.

Update: When the Add method is called, you don't need to return anything, just put the object into the cache and ASP.NET takes care of the rest. You get a warning that the function doesn't return anything but this can be ignored.

Wednesday, 6 January 2010

Installing AppFabric Caching Beta 1, Part 4

I'm pleased to report that I've (at last) had a measure of success with the AppFabric installer :-)

I mentioned in my last entry that I'd posted on the MSDN AppFabric Caching forum about the problems I'd been having with the installer. I also made two of my installation logs available. I'm indebted to Rahul Kaura from Microsoft, who pointed out that these were AppFabric general installation logs and steered me towards the cache-specific installation logs. These logs are found in the same place as the AppFabric logs i.e. your %TEMP% folder, are called DistributedCacheAppServerConfig(DateTime).log and I've found them invaluable in diagnosing and fixing installation problems.

So what were the problems I was having? From reading the log they seem to be largely around permissions to the Registry:
2010-01-06 11:52:52, Info DCACHE Adding access for NT AUTHORITY\NETWORK SERVICE on registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft Distributed Cache\Version



2010-01-06 11:53:16, Error DCACHE System.InvalidOperationException: This access control list is not in canonical form and therefore cannot be modified.
at System.Security.AccessControl.CommonAcl.ThrowIfNotCanonical()
at System.Security.AccessControl.CommonAcl.AddQualifiedAce(SecurityIdentifier sid, AceQualifier qualifier, Int32 accessMask, AceFlags flags, ObjectAceFlags objectFlags, Guid objectType, Guid inheritedObjectType)
at System.Security.AccessControl.DiscretionaryAcl.AddAccess(AccessControlType accessType, SecurityIdentifier sid, Int32 accessMask, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
at System.Security.AccessControl.CommonObjectSecurity.ModifyAccess(AccessControlModification modification, AccessRule rule, Boolean& modified)
at System.Security.AccessControl.CommonObjectSecurity.AddAccessRule(AccessRule rule)
at Microsoft.Data.Caching.InstallConfig.Program.SetResetLocalPermissions(Boolean grant)
at Microsoft.Data.Caching.InstallConfig.Program.PostConfigServiceInstallSteps()
at Microsoft.Data.Caching.InstallConfig.Program.Install()
at Microsoft.Data.Caching.InstallConfig.Program.Main(String[] args)


2010-01-06 11:53:16, Error DCACHE Unexpected Error: This access control list is not in canonical form and therefore cannot be modified.


2010-01-06 11:53:16, Info DCACHE Configuration failed, Rolling back...

which is sort of annoying as I've been running the installer under an account that is a Domain Administrator, and the Domain Admins group is part of the Administrators group on each of my cache servers. The solution was to add the account I'm using to install AppFabric to the ACL for HKEY_LOCAL_MACHINE with full permission.

The installer still reports that it fails to configure AppFabric, but this is because the log includes a Warning that the Windows Firewall is disabled, which I'm reasonably sure I can ignore.

So, I now have an AppFabric caching cluster with three servers. Onward to actually using it!

Friday, 18 December 2009

Installing AppFabric Caching Beta 1, Part 3

In Part 1 of this (unintentional) series, I talked about how the AppFabric installer works only with Integrated Security and so I needed a domain before I could install it, and in Part 2 I talked about how I then built said domain. At this point I tried once again to install AppFabric on CACHESERVER1, with all it's Integrated Security goodness. And failed. When the installer got to the configuration screen, I entered SQLSERVER in the connection string dialog, then clicked on the dropdownlist to get the list of databases on SQLSERVER. I then got a Timeout error in trying to retrieve the list of databases. No matter what I tried, I couldn't get this to work. I created a UDL file on CACHESERVER1, running Integrated Security, pointing at SQLSERVER, and confirmed that I could not only see SQLSERVER and retrieve a list of databases, but successfully connect to a database. I raised this as a question on StackOverflow and on the MSDN AppFabric Caching forum (where it looks like I'm not the only one having trouble with installations). And whilst it looks like at least some of the AppFabric team have been answering questions on the MSDN forum, I've had no answer at all to my posts.

Since then, my development laptop has been rebuilt with Windows 7, which has necessitated rebuilding my server environment from scratch with Virtual PC for Windows 7 (though there was a flirtation with VirtualBox, which I may yet go back to, although at the moment I find the process for setting up differencing disks a little too involved for my taste). With a rebuilt set of servers, I turned back to the AppFabric install, however there was one subtle difference in the server builds this time around. In trying to use the UDL files to verify that the server could contact the database ahead of the install, I encountered a problem that the SQL Server Native Client provider was not installed, so to fix this I installed the Client Connectivity bits from the SQL Server 2008 disc. When I then tried the AppFabric installer, this resolved the issue of not being able to any databases on the server. Result!

Well, not really. Although this let me proceed with the installation, the installation failed with error code 2. And no explanation for what this error means or how to fix it. And once again, the MSDN Forum has (so far) been no help. I've tried a few other things since then, including using the XML Provider for storing the configuration information instead of SQL Server. This I actually watched as it created a ClusterConfig.xml file on the network share I'd set up (thus proving that the account had enough rights on the folder), and then  removed the file again. The installation failed with error code 2. Tonight I tried something else - when you select the SQL Server provider and go to enter the connection string, you can enter your own connection string, or leave it selected at Default. I tried it with Default, thinking that this would create, perhaps, a SQLExpress database that I could then transfer to my SQL Server. At the very least it would give me a working AppFabric installation that I could play with. No. Leaving the Default radio button checked does, from what I can see, nothing. There is no 'Default' connection string, in fact the installer doesn't even allow you to continue if you select this, making it the stupidest UI possible.

All of which leaves me totally stalled on working with AppFabric since I have yet to find a working configuration. It's all very tiresome.

Tuesday, 24 November 2009

Installing AppFabric Caching Beta 1, Part 2

Last week I blogged about how far I'd got with installing the AppFabric Beta 1 caching engine, in which I got stalled because the caching configuration only supports Integrated Security with SQL Server. In this part I'll cover how I've got round this problem by building a domain on my virtual servers. IT Pros may wish to skip ahead to Part 3 (or point out in the comments my no doubt numerous mistakes in how I've gone about this).I've used two reference sources in going about this: this Microsoft article, and Dave McMahons Network Admin for Developers sessions (part 1 part 2) from DDD7.

My setup is as follows:

All servers are running Windows Server 2008 on Virtual PC 2007, and all on fixed IP addresses from 192.168.10.1 upwards. Liam's already blogged about my initial troubles in getting these servers to talk to each other - they currently all have each other's names and IP addresses in their hosts file.

So, building the domain. Step 1 is installing the Active Directory Domain Services role on to SQLSERVER. This allowed me to create my velocity.local domain with SQLSERVER as the domain controller. I then created a pair of users, VelocityAdmin and VelocityUser - my plan is to use VelocityAdmin to install AppFabric onto the CACHESERVERs and then change it to use VelocityUser in normal usage, but we'll get to that in Part 3. I've also created SQL Server logons for those accounts with permissions on my VelocityConfig database.
With the domain and domain controller all set up and running Active Directory and DNS I can now add the other servers to the domain, and this is where I hit a problem. Every time I tried to add CACHESERVER1 to the domain, I got an error:

I tried a number of different things to get round this but eventually I figured it out - when I configured the network settings originally (in a non-domain world), I didn't setup a DNS server. Once I entered the IP address for SQLSERVER, I could join servers to the domain.

So at the end of all that I now have a network of servers all running under a domain. The next piece of the puzzle is to go back and try installing AppFabric Beta again, which will be Part 3 of this short series.

Friday, 20 November 2009

Installing AppFabric Caching Beta 1, Part 1

So Velocity now has a 'proper' name - AppFabric Caching, and it's finally in beta.

AppFabric Beta 1 can be downloaded from http://www.microsoft.com/downloads/details.aspx?FamilyID=0BD0B14F-D112-4F11-94BF-90B489622EDD&displaylang=en but it has a big list of dependencies and Microsoft didn't link to the download page for each dependency :-(

So, things you will need to install before installing AppFabric Beta 1 on Windows Server 2008:
IIS Web Deployment Tool (http://go.microsoft.com/?linkid=9684516)

Go get it all and install it - it's OK, I'll wait...

Got all that? Good, let's continue...

Fire up the AppFabric installer. Once you get past the licensing, you get to this screen:


This is where you select what to install. By default the Worker and Distributed Cache Service components are selected. The Worker component is for the Workflow and Windows Communications Frameworks parts of AppFabric. Assuming you're just interested in the caching side, unselect Worker and select the others.


Then we're into the caching configuration screen. If you installed one of the Velocity CTPs this will look fairly familiar.
Note that the default is Join Cluster, not New Cluster, and that there's now a fourth port required (though it might have looked a bit better if the four ports had been arranged in ascending order).
 You can still choose whether to store the caching configuration in XML files on a network share or in a SQL Server database, but there are some changes here, especially in the way you enter a SQL Server connection string.


Whereas previously you could enter by hand a connection string, you now enter the name of the server and, once the list of databases has been retrieved from the server, the name of the database that holds the configuration information. The installer then creates the connection string for you. Or you can click the Default radio button and go with the default connection string. However as this puts nothing into the connection string box, you can't see what the default is. More annoyingly, if you do click the Default option, you then can't get back into this dialog to change your mind without cancelling out of the installer and starting the install again.


Note that the connection string is using Integrated Security. And you can't change it. And you can't set the account that AppFabric runs under.
I liked the old installer where you entered your own connection string. It had a couple of quirks about what it considered to be a valid connection string, but that was OK because I'd learnt what they were. Now I feel like I've lost an element of control - I'd rather decide myself that I want Integrated Security, thank you.

And this is as far as I've got on my Velocity demo setup. Every time I finish the install, it installs the caching engine but fails to configure it. I suspect this is because although I have a network of virtual servers set up, I now need to add a domain and accounts so that the Integrated Security works.

To be continued...

Friday, 7 August 2009

@philpursglove is in Demo Hell

Last Tuesday I took my new session on Velocity to the NxtGen User Group at Oxford, having responded to Barry's plea for a speaker. And I had a bit of a 'mare. In fact, a lot of a 'mare.

I knew I was in trouble when I fired up my laptop and the Velocity Powershell console showed an error immediately. So I tried to fix it by uninstalling and reinstalling only to discover that if you have no network connection Velocity will not install. At all. It makes no difference whether you're using a network share on the local machine to store the cluster config, or trying to store it in a SQL database on the local machine - no network, no cache.

So I'd like to thank everyone for listening and offering suggestions as to how I might have got things working faster. I've put my slides up at http://philippursglove.com/velocity , but I'm doing a bit more work on the demos, I'll put them up later this week.

Thursday, 16 April 2009

Manually Uninstalling Velocity CTP2

Now that Velocity CTP3 is out I was looking forward to installing it however going through Add/Remove Programs it prompted me to locate the original installation MSI. Which I haven't got any more :-(

However I contacted the Velocity team and they sent me instructions for manually removing CTP2.

"Note: To un-install Velocity CTP bits use 'Add-Remove Program', however for scenarios where a user is unable to un-install e.g.
'Add-Remove Program' entry is missing, following workaround of using manual steps for un-installation can be used, but they need to be done at users discretion.

Below steps assume removal of Velocity Service and product from a single machine, to un-install multi node Velocity cluster below steps need to be performed on each machine (node)

1. Under 'Administration Tools' -> 'Services' ensure that Velocity service DistributedCacheService with Display Name "Microsoft project code named "Velocity" is stopped

2. Go to Command Prompt and use SC.EXE command to delete velocity service i.e.

SC.EXE delete DistributedCacheService

3. To ensure removal of entries from 'Add-Remove Program' for existing 'Velocity Installer', Download and install 'Windows Installer Cleanup Tool' as per following KB
http://support.microsoft.com/kb/290301 , Or directly from
http://download.microsoft.com/download/e/9/d/e9d80355-7ab4-45b8-80e8-983a48d5e1bd/msicuu2.exe

Launch the above installed Tool and from the list choose 'Microsoft project code name "Velocity" CTP2' and select Remove

4. Next delete files under installed folder, typically under \Program Files\Microsoft Distributed Cache\V1.0

5. Remove 'Firewall Exception' for DistributedCacheService

6. If Cluster Config Store chosen during installation was 'XML'
or 'SQL Server Compact' then remove the files from the Network Share Folder (which was provided during installation)

Else if 'SQLClient Provider' was used as the Cluster Config Store then -

Drop the database (provided as 'Initial Catalog' ) which was mentioned in the connection string during installation.

or, To avoid Dropping the database in case you want to keep it, you can also just drop the table 'dbo.config' present in the above mentioned database."

I haven't tried these instructions out yet as I don't want to fry my laptop ahead of WebDD this weekend but I will try them next week and report back.

UPDATE: I ran through these instructions last week, for me they worked perfectly. The only thing I struggled with was the fact that IT have locked down the UI for firewall exceptions so I couldn't remove the ones I had set up. However I was able to remove them by hacking the Registry.

I now have Velocity CTP3 installed - details coming soon!

Sunday, 23 November 2008

DDD7 - ASP.NET Scalability

I'd like to thank the organisers and attendees for giving me the opportunity to present 'This One Goes Up To 11, or How To Write Scalable ASP.NET' yesterday at DDD7 at Microsoft in Reading. It was my first time presenting at DDD, and I really enjoyed it. My session seemed to go quite well, there were a couple of demos I need to go through again to figure out why they didn't work, but overall I felt it was quite well received. All the sessions were videoed for Channel 9 , which is both quite exciting and means I'll get to see the sessions I couldn't get into :-)

A session I did get into was Phil and Dave's ASP.NET 4.0 runthrough. A lot of things are still under wraps, but one of the most useful things they demoed was the ability to set a control's ID and not have it munged with the control's container name when the html hits the browser. Which is nice. I feel validated in being unsure about MVC now I've heard that Phil's not keen on. It'll be interesting to see the new provider-based caching model when it arrives, especially as this will fit really well with Velocity. I'm not, however, at all sure about the new WPF-based Studio.

Edit: My slides and code samples are now available at www.philippursglove.com/ScalableASPNET.

Monday, 3 November 2008

Velocity CTP2

CTP2 of Velocity was announced at PDC last week - the announcement on the Velocity blog is here, you can download the bits here.

First thoughts are that they've done a lot of work since CTP1.

I installed this CTP tonight and ran up a super-quick demo, and it worked perfectly first time. And by perfectly I mean once I'd fixed my code. And by first time, I mean once I'd updated my web.config. This is good as it means all the problems were on my end, not theirs! (Same old story)

I'm going to have a bit more of a play today/tomorrow and will post some more details then. I've also got the PDC videos to watch.

Tuesday, 5 August 2008

Non-Relational Databases

I read this piece on The Register yesterday about the new database from the original makers of MySQL. I was particularly intrigued by the statements 'won't support Windows ... and neither will it be SQL relational compliant'. All I could hear was Sir Humphrey congratulating them on a 'courageous decision'.
But I got to thinking about it last night and it occurred to me that Velocity does more or less the same things i.e. allows you to perform CRUD operations on data in a non-relational store, is suited to cloud computing etc.
Except Velocity works on Windows, and Drizzle doesn't. Which really is a courageous decision - love it or hate it, it's the most widely used OS. As a Microsoft developer, if I can't use something on Windows I'm not going to use it at all, so it's difficult to see Drizzle taking off. Maybe Microsoft should make a publicly-available Velocity store available in the cloud and position it as a competitor to Drizzle. Now that would be a Live/Mesh/Whatever service I'd like to use.

Wednesday, 23 July 2008

Velocity Samples

This week's UK MSDN Flash included a piece about Velocity and a link to http://code.msdn.microsoft.com/velocity, which has code samples. Downloading now, will report back later.

Slightly annoyed that I've seen no mention of these on the Velocity team blog!

Friday, 11 July 2008

Velocity: Struggling :-(

I've finally got to writing some code against Velocity (one of our servers at work has decided it's not going to talk to the domain controller any more so nobody can log onto it). And ... it's not working :-(
I'm pretty sure I'm doing the right things, I suspect it's a configuration issue. The exception I'm getting (having modified my code slightly to throw CacheExceptions rather than just Exceptions) is 'Could not connect to cache service'. I'm slightly gratified to see Christian Weyer gets the same problem - if someone like that gets it, what chance do I have! ;-)

For now, I've removed the extra instances so I'm back to a single host. I thought briefly that it was due to not having set up 'Everyone' to have read/write access but that didn't fix it. Worth remembering as a setup action though.

I'm going to review all my .config files to see if I've missed something - if I don't find anything then I guess it's for the Velocity team.

Tuesday, 8 July 2008

Velocity: Regions

I did a bit more digging into Velocity last night. I still haven't written any code yet but I'm getting there!

I was poking around in the Object Browser at the System.Data.Caching namespace and I discovered that the context-sensitive help for each method is probably more helpful than the helpfile.

But more interesting than that, the help for Cache.Add(key As String, value As Object) suggests that if you call this particular overload, the item gets cached in the default region of the cache. Which raises all kinds of questions: if there is a region created by, well, default, which host is it tied to? Does the default region span hosts (in which case regions suddenly become a lot more appealing to me)? Can I use the default region everywhere?

Now I've got multiple instances, I can do a bit more experimentation with regions and see if they start to be a bit more useful, but I suspect my next course of action is to run ClientLibrary through Reflector and have a look at what Cache.Add actually does.

Creating Multiple Velocity Instances on a Single Machine

I now have three instances of Velocity running on my laptop, as per these instructions. I found it a little painful, though probably I wasn't reading the directions closely enough - it took me a while to get all the .config files set up right as I got confused between the cacheHostName (which is the name of the Windows service) and the hostName (which is the machine name). There may have been additional confusion involving the folder names...

Friday, 4 July 2008

Velocity: Digging Deeper

I started looking properly at some Velocity bits and pieces this afternoon, including starting to write a little code against it. And I've already found one or two frustrations, or at least things that don't seem to work quite the way I want them to.

CacheFactory
You use the CacheFactory to create an instance of a Cache. So far, so good - I like the Factory pattern. What I'm not so keen on here is that the CacheFactory's methods all have to be called on an instance e.g. instead of:
Dim cache As Cache
cache = CacheFactory.GetCache("MyCache")
...
you have to write:
Dim factory As CacheFactory
Dim cache As Cache

factory = New CacheFactory
cache = factory.GetCache("MyCache")
[EDIT: It came back to me at the weekend that these are called static methods, or Shared in the one true language of VB]
It's a small annoyance, but I'm a small person sometimes.

Regions
I'm going to come right out and say it: I don't get Regions. I'm completely sold on the concept of a single cross-machine cache - it solves the major issue with the ASP.NET Cache (which runs per-machine). So why then require Regions to live on a single machine? It's like they're saying "here, do this to be fault-tolerant, but to get the most out of it you have to do things that aren't fault tolerant".
It's doubly frustrating when you discover that if you want to add an item to a Velocity cache with an expiry time, you have to add it to a Region. The Cache on its' own just allows you to add an item that's there forever.

CacheDependencies
I really think dependencies are the biggest missing element in the first CTP of Velocity. The SqlCacheDependency in .NET 2.0 was the biggest enabler for caching as it meant you could run multiple web servers and keep their caches in sync with database changes without much effort. You can't do this in CTP1.


I'm interested to see Barry has proposed a session on Velocity for DDD7. That's good 'cos it means I can pick his brain for suggestions to solve some of these things!

Monday, 30 June 2008

Velocity First Look

Normally I avoid CTPs like the plague, but I'm interested enough in this one that I installed the first CTP of the Velocity caching engine over the weekend.

Haven't tried coding against it yet but I had a bit of a play with the command-line admin console and read some of the help.

The most obvious missing element right now is a CacheDependency object (+ subclasses viz. SqlCacheDependency) - I've been trying to think of a way to chain this and the ASP.NET Cache together to retain the ability to have dependencies butI haven't come up with one yet :-(

I'm intrigued by the idea that you can lock and unlock cached objects, though since in the finished version it should run across multiple servers I guess this is a way to avoid race conditions.

Edit: Something else missing I just discovered is that the service out of the box doesn't survive a restart i.e. you have to go into the Admin console and issue a new 'START CLUSTER' command. I've now marked the Windows service as 'Automatic', not 'Manual'.