Search This Blog

2011-04-30

The gateway for an IoC container

Inversion of control and Dependency injection tools became an integral part of any enterprise application because they are great at reducing complex dependencies and increasing flexibility.
My first experience with IoC within enterprise applications was MS Unity that had been used  for decoupling parts of a system and adding extra-flexibility (e.g., to extend system with new implementations). As I discovered it is a great tool that helped me and my team a lot to meet the flexibility requirements of our solution. Nevertheless during research and development I found several issues of using IoC/DI tool in general. They might not be so obvious, but they became a bone in the throat for me.
1. If there is a necessity to implement extra-caching for some services (i.e., specific for our CMS) it would a hard time to create and extensions to do that, and our solution was to create a wrapper layer over Unity's container to intercept its calls and with the passage of time that layer had become pretty big and messy.
2. There is a negative dependency on API of the tool. Thus, Unity's xml container configuration had become our public interface for CMS developers to extend our solution and, as a result, our solution was dependent on reliability of Unity and more - it meant freezing of version Unity. Why? If customer invest in a solution based on our system he would definitely use our (actually, borrowed from Unity) xml structure and it would take time and money to modify it according to the new version of Unity. It did not take long to feel it in the hard way: Unity had been upgraded from version 1.2 to 2.0 so it took us a week to upgrade not released product!
3. IoC tools use reflection (emit is promised) to create and an instance(s) (even though using Singletons) so Resolving is always in the performance hot-sports (8-12% of CPU general usage! for our project). Solving the problem requires extra-monitoring and optimizing of using container. Basically such a problem happened because our team had become to use DI tool as a ServiceLocator instead of injecting dependencies that caused using Container.Resolve<T>() enormous amount of times. If you use 3-d party unmanaged tool is more complex to control resolving.
For my new project we have looked to some various DI tools like: Managed Extensibility Framework (it is actually a little bit different but, at some point, can be used as DI tool), autofac, Spring, Ninject, StructureMap and Windsor. The decision was to use Castle Windsor that, at first, disappointed me but than I realized that all tools basically able to do the same :-). So being inspired by Ritesh Rao's post and Davy Landman's one I realized that sometimes it makes sense to use a generic gateway wrapper for IoC container. It would allow to "mitigate" described issues plus benefits like tool version/vendor independence, more control for 3-d party tool as an "enemy". Of course there is a great tool called Common Service Locator library but, unfortunately, it had been released more than 2 years ago and it does not fit all the functionally we require from the DI tool.
So I have decided to develop some simple gateway that would fit major functionalities I faced for the IoC.
Such a wrapper has several disadvantages:
1. It cuts extra-functionalities of a tool beyond;
2. It takes time to develop and maintain it.
So, IMHO, for small projects it does not make any sense to use any wrappers, it will just increase the complexity. But for enterprise applications that are developed by many people for many years it will give distinct advantages.
Functionalities cuts is a very ambiguous thing. Many tools have extra-functionality like class interceptors, easy-registrations etc. IMHO, these bells and whistles might harm more than give benefits. Of course some of features are important so they should be considered to be used on enterprise approaches (like AOP and PostSharp as a tool).

Ok, let's look to the wrapping.
Basic solution is quite simple: there is container's core that has an instance(s) of the 3-d party tool to intercept all calls and static gateway for quick and convenient access to the IoC container. The first goal is completely isolate 3-d party tool for the our usage.
Okay, before we start on the IoC wrapper, I need some infrastructure work done. First we need is somehow to initialize the container i.e. to fulfill it with contract-implementation associations. One of the most simple solution is create a interface that allows to build the container.
public interface IIoCRegistration
{
  void BuildContainer(IoCContainerCore container);
}

[IoCRegistration]
public class Registrator : IIoCRegistration
{
  public void BuildContainer(IoCContainerCore container)
  {
    container.Register();
  }
}
The class that implements this interface will receive container instance and than it is possible to initialize it using API, either read from XML or anything else. So idea is to let user to implement the interface and mark classes with custom attribute to find registration in an assembly:
[AttributeUsage(AttributeTargets.Class)]
public sealed class IoCRegistrationAttribute : Attribute
{
}
Ok, but we also need to register that assemblies with container setup: to write their names to application config file. So let's create a section:
public sealed class IoCAssemblyRegistration : ConfigurationSection
{
  public const string ConfigurationSectionName = "iocAssemblyConfiguration";

  [ConfigurationProperty("assemblies")]
  public AssembliesElementCollection Assemblies
  {
    get
    {
      return (AssembliesElementCollection)this["assemblies"] ?? new AssembliesElementCollection();
    }
  }

  public static IoCAssemblyRegistration GetConfig()
  {
    return (IoCAssemblyRegistration)ConfigurationManager.GetSection(ConfigurationSectionName) ?? new IoCAssemblyRegistration();
  }
}

public class AssemblyElement : ConfigurationElement
{
  [ConfigurationProperty("assembly", IsRequired = true)]
  public string Assembly
  {
    get
    {
      return this["assembly"] as string;
    }
  }
}

public class AssembliesElementCollection : ConfigurationElementCollection
{
  public AssemblyElement this[int index]
  {
    get
    {
      return BaseGet(index) as AssemblyElement;
    }

    set
    {
      if (BaseGet(index) != null)
      {
        BaseRemoveAt(index);
      }

      BaseAdd(index, value);
    }
  }

  protected override ConfigurationElement CreateNewElement()
  {
    return new AssemblyElement();
  }

  protected override object GetElementKey(ConfigurationElement element)
  {
    return ((AssemblyElement)element).Assembly;
  }
In the .config file it will look like:

  
    
Ok, infrastructural work is done, let's define what basic functionality we would like to have:
1. Nested containers;
2. Registration of type and instance;
3. Resolve, resolve all;
4. Checking if registered;
5. Remove registrations;
6. Setup lifetime management.

Also we need to have a thread save container and, since we suppose that registering (writing to the container) would invoked rarely and resolving (reading) is a common usage, ReaderWriterLockSlim class can be used.

....
private readonly ReaderWriterLockSlim iocLocker;
....
private void InvokeWriteLock(Action action)
{
  this.iocLocker.EnterWriteLock();

  try
  {
    action();
  }
  catch (Exception exception)
  {
    Log.Error(exception.Message, exception, typeof(IoCContainerCore));
    throw new InvalidOperationException(exception.Message, exception);
  }
  finally
  {
    this.iocLocker.ExitWriteLock();
  }
}

private T InvokeReadLock(Func func)
{
  if (!this.iocLocker.IsReadLockHeld && !this.iocLocker.IsWriteLockHeld)
  {
    this.iocLocker.EnterReadLock();
  }

  try
  {
    return func();
  }
  catch (Exception exception)
  {
    Log.Error(exception.Message, exception, typeof(IoCContainerCore));
    throw new InvalidOperationException(exception.Message, exception);
  }
  finally
  {
    if (this.iocLocker.IsReadLockHeld)
    {
      this.iocLocker.ExitReadLock();
    }
  }
}
...

1. Nested containers. So let's allow to have a  hierarchy of containers:
public partial class IoCContainerCore : IDisposable
{
  private readonly ReaderWriterLockSlim childrenLocker;

  private IWindsorContainer container;

  private IoCContainerCore parent;

  private string name;

  private Dictionary childContainers;

  public IoCContainerCore()
  {
    this.container = new WindsorContainer();
    this.childrenLocker = new ReaderWriterLockSlim();
    this.childContainers = new Dictionary();
  }

  public IoCContainerCore Parent
  {
    get
    {
      return this.parent;
    }

    set
    {
      Assert.ArgumentNotNull(value, "value");
      this.parent = value;
      Log.Info(string.Format("Parent container named: '{0}' has been set.", value.Name), typeof(IoCContainerCore));
    }
   }

  public string Name
  {
    get
    {
      return this.name;
    }
    set
    {
      Assert.ArgumentNotNullOrEmpty(value, "value");
      this.name = value;
      Log.Info(string.Format("Container name: '{0}' has been set.", value), typeof(IoCContainerCore));
    }
 }

 public virtual void AddChildContainer(string childContainerKey, IoCContainerCore childContainer)
  {
    Assert.ArgumentNotNullOrEmpty(childContainerKey, "childContainerKey");
    Assert.ArgumentNotNull(childContainer, "childContainer");

    this.childrenLocker.EnterWriteLock();
    try
    {
      Assert.IsFalse(this.childContainers.ContainsKey(childContainerKey), string.Format("Child container named: '{0}' has already been added.", childContainerKey));

      this.childContainers.Add(childContainerKey, childContainer);

      Log.Info(string.Format("Child container named: '{0}' has been added.", childContainerKey), typeof(IoCContainerCore));
    }
    catch (Exception exception)
    {
      Log.Error(exception.Message, exception);
      throw;
    }
    finally
    {
      this.childrenLocker.ExitWriteLock();
    }
  }

  public virtual void RemoveChildContainer(string childContainerKey)
  {
    Assert.ArgumentNotNullOrEmpty(childContainerKey, "childContainerKey");

    this.childrenLocker.EnterWriteLock();
    try
    {
      Assert.IsFalse(this.childContainers.ContainsKey(childContainerKey), string.Format("Child container named: '{0}' has already been added.", childContainerKey));

      this.childContainers.Remove(childContainerKey);

      Log.Info(string.Format("Child container named: '{0}' has been removed.", childContainerKey), typeof(IoCContainerCore));
    }
    catch (Exception exception)
    {
      Log.Error(exception.Message, exception);
      throw;
    }
    finally
    {
      this.childrenLocker.ExitWriteLock();
    }
  }

  public virtual IoCContainerCore GetChildContainer(string childContainerKey)
  {
    Assert.ArgumentNotNullOrEmpty(childContainerKey, "childContainerKey");

    this.childrenLocker.EnterReadLock();
    try
    {
      Assert.IsTrue(this.childContainers.ContainsKey(childContainerKey), string.Format("Child container named: '{0}' does not excist.", childContainerKey));

      return this.childContainers[childContainerKey];
    }
    catch (Exception exception)
    {
      Log.Error(exception.Message, exception);
      throw;
    }
    finally
    {
      this.childrenLocker.ExitReadLock();
    }
  }
}
2. Registration. I have a list of registration functionality that I usually use.
1) Register by type: common use case;
2) Register by key: required when you have set of implementation ;
3) Register object instance: useful when object creation is not under your control;
4) Register with injecting parameters: setup additional parameters to the constructor;
5) Register with lifetime management: by default all registrations are singletons, but usually and especially for web application another management required like: per Request, per Session, per Thread. etc ;
6) Register with setting up dependencies: allow user to setup what exactly dependency should be used;
7) Register using factory method: useful when an object should be created in a special way (e.g. NHibernate data session).
There is a list a basic examples without combination of parameters.

public virtual void Register<TFrom, TTo>() where TTo : TFrom
{
  this.InvokeReadLock(() => this.container.Register(Component.For<TFrom>().ImplementedBy<TTo>()));
}

public virtual void RegisterInstance<TFrom>(TFrom fromInstance)
{
  Assert.ArgumentNotNull(fromInstance, "@from");

  this.InvokeReadLock(() => this.container.Register(Component.For<TFrom>().Instance(fromInstance)));
}

public virtual void Register<TFrom, TTo>(string key) where TTo : TFrom
{
  Assert.ArgumentNotNullOrEmpty(key, "key");

  this.InvokeReadLock(() => this.container.Register(Component.For<TFrom>().ImplementedBy<TTo>().Named(key)));
}

public virtual void Register<TFrom, TTo>(IEnumerable<KeyValuePair<string, string>> dependencies) where TTo : TFrom
{
  Assert.ArgumentNotNullOrEmpty(dependencies, "dependencies");

  this.InvokeReadLock(() =>
  {
    var windsorDepens = dependencies.Select(parameter => ServiceOverride.ForKey(parameter.Key).Eq(parameter.Value));

    return this.container.Register(Component.For<TFrom>().ImplementedBy<TTo>().DependsOn(windsorDepens.ToArray()));
  });
}

public virtual void Register<TFrom, TTo>(Action<IDictionary> setParameters) where TTo : TFrom
{
  Assert.ArgumentNotNull(setParameters, "setParameters");

  this.InvokeReadLock(() => this.container.Register(Component.For<TFrom>().ImplementedBy<TTo>().DynamicParameters((k, d) => setParameters(d))));
}

public virtual void Register<TFrom, TTo>(ILifeTimeDefinition lifeTimeDefinition) where TTo : TFrom
{
  Assert.ArgumentNotNull(lifeTimeDefinition, "lifeTimeDefinition");

  this.InvokeReadLock(() => this.container.Register(LifeTimeRegistration.GetManager(Component.For<TFrom>().ImplementedBy<TTo>(), lifeTimeDefinition)));
}

public virtual void Register<TFrom>(Func<TFrom> factoryMethod)
{
  Assert.ArgumentNotNull(factoryMethod, "factoryMethod");

  this.InvokeReadLock(() => this.container.Register(Component.For<TFrom>().UsingFactoryMethod(() => factoryMethod())));
}
...

So let's move to resolving.
1) Resolving by type
2) Resolving by type and key;
3) Resolve all;
4) Resolve injecting arguments;
5) Try resolve

public virtual T Resolve<T>()
{
  return this.InvokeReadLock(() =>
  {
    this.EnsureContainerIsInitialsied();
    return this.container.Resolve<T>();
  });
}

public virtual T Resolve<T>(string key)
{
  Assert.ArgumentNotNullOrEmpty(key, "key");

  return this.InvokeReadLock(() =>
  {
    this.EnsureContainerIsInitialsied();
    return this.container.Resolve<T>(key);
  });
}

public virtual T Resolve<T>(IDictionary arguments)
{
  Assert.ArgumentNotNull(arguments, "arguments");

  return this.InvokeReadLock(() =>
  {
    this.EnsureContainerIsInitialsied();
    return this.container.Resolve<T>(arguments);
  });
}

public virtual T Resolve<T>(object argumentsAsAnonymousType)
{
  Assert.ArgumentNotNull(argumentsAsAnonymousType, "argumentsAsAnonymousType");

  return this.InvokeReadLock(() =>
  {
    this.EnsureContainerIsInitialsied();
    return this.container.Resolve<T>(argumentsAsAnonymousType);
  });
}

public virtual object Resolve(Type service)
{
  Assert.ArgumentNotNull(service, "service");

  return this.InvokeReadLock(() =>
  {
    this.EnsureContainerIsInitialsied();
    return this.container.Resolve(service);
  });
}

public virtual bool TryResolve<T>(out T @object)
{
  return this.TryInvokeReadLock(
  () =>
  {
    this.EnsureContainerIsInitialsied();
    return this.container.Resolve<T>();
  },
  out @object);
}

public virtual T[] ResolveAll<T>()
{
  return this.InvokeReadLock(() =>
  {
    this.EnsureContainerIsInitialsied();
    return this.container.ResolveAll<T>();
  });
}

private void EnsureContainerIsInitialsied()
{
  if (!this.initialised)
  {
    this.InitializeContainer();
  }
}
...

As you can see an idea is simple but it's painstaking :-)
I'll skip blocks with checking if registered and removing registrations because it is quite trivial task.
And couple of words about lifetime management. In order to isolate DI tool classes I had to create own wrappers based on Lifetime definition and manager:

public interface ILifeTimeDefinition
{
  Type LifetimeManager { get; }
}
public static class LifeTimeRegistration
{
  public static ComponentRegistration<S> GetManager<S, T>(ComponentRegistration<S> componentRegistration,T definition) where T : ILifeTimeDefinition
  {
    return new LifestyleGroup<S>(componentRegistration).Custom(definition.LifetimeManager);
  }
}
public class PerWebRequest : ILifeTimeDefinition
{
  public Type LifetimeManager
  {
    get { return typeof(PerWebRequestLifestyleManager); }
  }
}
public class PerThread : ILifeTimeDefinition
{
  public Type LifetimeManager
  {
    get { return typeof(PerThreadLifestyleManager); }
  }
}
...

And now a static gateway example. It is made just for initialization, storing wrapper and convenience.

public static class IoCContainer
{
  private static readonly IoCContainerCore Container;

  static IoCContainer()
  {
    Container = new IoCContainerCore();
  }

  public static IoCContainerCore ContainerCore
  {
    get { return Container; }
  }

  public static T Resolve()
  {
    return Container.Resolve();
  }

  public static void Register() where TTo : TFrom
  {
    Container.Register();
  }
  ....
  public static void InitializeContainer()
  {
    if (Container.IsInitialised)
    {
      return;
    }

    IEnumerable configAssemblies = GetConfigAssemblies();
    if (configAssemblies.Any())
    {
      Container.InitializeContainer(configAssemblies, null);
    }
    else
    {
      Container.InitializeContainer();
    }
  }
   
  private static IEnumerable GetConfigAssemblies()
  {
    var section = ConfigurationManager.GetSection(IoCAssemblyRegistration.ConfigurationSectionName) as IoCAssemblyRegistration;
    if (section == null)
    {
      // throw new ConfigurationErrorsException("Configuration section was not found");
      yield break;
    }

    foreach (AssemblyElement element in section.Assemblies)
    {
      yield return element.Assembly;
    }
  }

}

Ok, and that works, but is it possible to change the DI tool? Yes, and it took my two and a half hours to replace Windsor with Unity and pass all unit tests.
IoC container usage is quite simple:
[TestFixture]
public class IoCContainerTest
{
  [SetUp]
  public void SetUp()
  {
    IoCContainer.InitializeContainer();
  }

  [TearDown]
  public void ResetContainer()
  {
    IoCContainer.ResetContainer();
  }
  
  [Test]
  public void ResolveTest()
  {
    var service = IoCContainer.Resolve();

    Assert.IsNotNull(service);
    Assert.IsTrue(service is Logger);
  }

  [TestCase("Implementation1")]
  [TestCase("Implementation1Child")]
  public void ResolveInvokeTest(string serviceName)
  {
    var service = IoCContainer.Resolve(serviceName);

    Assert.IsNotNull(service);
    service.Do("some data");
  }
 ...
}
As a summary, I want to underline what that messy stuff gave us. We have isolated 3-d party tool completely so we control IoC container usage now :-), we can do any manipulations to optimize it: caching, container storing, combining several tools if needed, lifetime managers manipulations.
Sources are available here for Windsor and here for Unity.

2011-03-13

PLINQ: is it worth to use?

Last month I had a speaker corner with my colleagues: "Are you still using loops? - We are coming to you!".
We always face the scalability issues in our work and one of the most evident scalability holes is processing great amount of data. One of the solutions could be the concurrent executing on multi-core CPUs. So the main point of the discussion was that we should not use loops any more because they are obsolete :-). Loops like: for, foreach, while, etc are not lead us to the atomic programming and as a result we are not really ready to develop effectively for the concurrent execution.
There were not only .Net developers participating the speaker corner, so they resented what they can use instead? Fortunately C# has LINQ and even more - Parallel LINQ. .NET 4.0 natively provides us with such a chance to use it without a necessity to be a concurrency guru.

Parallel LINQ (PLINQ) is a query execution engine that accepts any LINQ-to-Objects or LINQ-to-XML query and automatically utilizes multiple processors or cores for execution when they are available. PLINQ becomes increasingly crucial to ensuring the scalability of software on future parallel microprocessor architectures. In fact, threads and locks won't even come up unless you really want to dive under the hood to understand how it all works. PLINQ is a key component of Parallel FX, the next generation of concurrency support in the .NET.
Of course, using  concurrent processing one should think about external resource: if you actively work with it within the query, most time the threads are in synchronization state so you're apt to be quite disappointed about the performance.
I am not going to dive deep into the concurrent development theory, I am just want to share some observations weather PLINQ is really able to help with performance improvements or not. Let's write some simple application and profile it. Let's say we have some CollectionProcessor class that calculates a math expression for each element in the collection of numbers and that sums all elements.

public class CollectionProcessor
{
  private static double ItemProccess(int item)
  {
    return Math.Cos(10005000 * item) / item;
  }

  public static double ForEachSerial(IEnumerable<int> collection)
  {
    double sum = 0d;

    foreach (int i in collection)
    {
      sum += ItemProccess(i);
    }

    return sum;
  }

  public static double LinqSerial(IEnumerable<int> collection)
  {
    return collection.Select(ItemProccess).Sum();
  }

  public static double ForEachParallel(IEnumerable<int> collection)
  {
    double sum = 0d;

    foreach (int i in collection.AsParallel())
    {
      sum += ItemProccess(i);
    }

    return sum;
  }

  public static double LinqParallel(IEnumerable<int> collection)
  {
    return collection.AsParallel().Select(ItemProccess).Sum();
  }
}

Here we have four solutions: foreach loop, LINQ, foreach loop using parallel mode and PLINQ.
Let's test the results now and take 100050000 elements for the collection of numbers.

[TestFixture]
public class CollectionProcessorTest
{
  private IEnumerable Collection { get; set; }

  [SetUp]
  public void SetUp()
  {
    Collection = ParallelEnumerable.Range(0, 100050000);
  }

  [Test]
  public void ForEachSerialTest()
  {
    Stopwatch stopwatch = new Stopwatch();

    stopwatch.Start();
    CollectionProcessor.ForEachSerial(this.Collection);
    stopwatch.Stop();

    Console.WriteLine(stopwatch.ElapsedMilliseconds);
  }

  [Test]
  public void LinqSerialTest()
  {
    Stopwatch stopwatch = new Stopwatch();

    stopwatch.Start();
    CollectionProcessor.LinqSerial(this.Collection);
    stopwatch.Stop();

    Console.WriteLine(stopwatch.ElapsedMilliseconds);
  }

  [Test]
  public void ForEachParallelTest()
  {
    Stopwatch stopwatch = new Stopwatch();

    stopwatch.Start();
    CollectionProcessor.ForEachParallel(this.Collection);
    stopwatch.Stop();

    Console.WriteLine(stopwatch.ElapsedMilliseconds);
  }

  [Test]
  public void LinqParallelTest()
  {
    Stopwatch stopwatch = new Stopwatch();

    stopwatch.Start();
    CollectionProcessor.LinqParallel(this.Collection);
    stopwatch.Stop();

    Console.WriteLine(stopwatch.ElapsedMilliseconds);
  }
}

I have Intel Core Quad CPU (4-cores) running on 3,3 GHz. The time of execution results are:
ForEachSerialTest : 16 sec;
LinqSerialTest : 16,3 sec;
ForEachParallelTest : 15,5 sec;
LinqParallelTest :  3,9 sec
Hey! Here we have such a great  time of execution improvements: up to 4 times! Also, it was very nice to see the Core-gadget while PLINQ was running: 

But foreach loop even in concurrent mode had not shown real improvements.
Ok, let's profile the results. 
There are not such a great performance improvements while profiler is working, but still it exists. The expanded tree is: 
Now we can see that MoveNext operation to iterate takes more time than item processing. So I don't see any sense to use .AsParallel() with foreach loop. 
ItemProcess takes the same time for sequential test (approx. 12 sec) but PLINQ requires only 8 sec. But it also creates more threads:
And that is the point! With PLINQ we have 4 threads working in parallel. 
The interesting thing is how PLINQ  works inside. I have tried to look at the systems calls more thoroughly. 
First, let's take a common LINQ query:

This looks simple: it creates expression tree: ItemProcess - WhereSelectEnumerableIterator - Sum.
But the PLINQ tree is a little bit different:-) I even had to flatten the picture.
The call tree is impressive! It uses lots of system commands to start and execute threads. It obviously requires a lot of resources to start the execution. So if you query is not really shared in the parallel tasks you would get serious performance issues with PLINQ.
In the conclusion, PLINQ allows LINQ developers to take advantage of parallel hardware — including achieving better performance and building more intrinsically scalable software — without needing to understand concurrency or data parallelism. But my own experience with PLINQ had shown that one should be very careful with it, test and profile the resulted query to insure it really gives benefits of running in parallel and does not wait for thread synchronization all the time.

P.S.
There are nice samples to start with PLINQ.

2011-02-27

The First Selenium Camp in Europe

I was lucky to visit the first Selenium Camp in Europe last Saturday. It was held in Kiev by XP Injection group.

Even though I am not a QA-or automation testing engineer it was quite useful to visit it. The first reason is we do use (or trying to use) Selenium for functional testing in our project, the second one it is quite nice to feel myself in the shoes of guys how test software all the time. As for my real experience it is quite small, I was just using IDE and RC to create some simple tests and even before I was using WatiN for some functional testing. But Selenium is a real bomb... just imagine, it becomes so popular that people organize big conferences about it!
Let's start from the basics, your Captain speaking:
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language. Selenium provides a test domain specific language (DSL) to write tests in a number of popular programming languages. Test playback is possible in most modern web browsers. Selenium deploys on Windows, Linux, and Macintosh platforms. 
Selenium contains several parts:
1. Core written in pure JavaScript, 
2. IDE as a Firefox extension that allows to record, edit, and debug tests, 
3. Remote Control (RC) that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser, 
4. Grid  allows to run tests on many servers at the same time, cutting down on the time it takes to test multiple browsers or operating systems.
5. Many extensions, integrations etc.

The kick-off meeting I visited was David Burns's "Selenium 2 : The future of Selenium is now!". As a result of a presentation I found that future of the Selenium is quite solid, many good thing like web drivers, fluent and simple API, caching elements collection are provided.
Web driver is a layer between Selenium Core and browser engines, created specially for each supported browser, that means written within the native environment for it, C++/COM for IE, extension mechanisms for FF and Chrome, etc. On the other hand web driver is ready to be used within high level languages like C#. Sometimes it is better to use WebDriver than Selenium and vice-versa. But just look at that:
[TestFixture]
public class GoogleIETest
{
  IWebDriver driver;
      
  [SetUp]
  public void Setup()
  {
    driver = new InternetExplorerDriver();
  }
     
  [TearDown]
  public void Teardown()
  {
    driver.Quit();
  }
      
  [Test]
  public void TestSearchGoogleForTheAutomatedTester()
  {
    //Navigate to the site
    driver.Navigate().GoToUrl("http://www.google.ua");

    //Find the Element and create an object so we can use it
    IWebElement queryBox = driver.FindElement(By.Name("q"));

    //Work with the Element that's on the page
    queryBox.SendKeys("The Automated Tester");
    queryBox.SendKeys(Keys.ArrowDown);
    queryBox.Submit();

    //Check that the Title is what we are expecting
    Assert.True(driver.Title.IndexOf("The Automated Tester") > -1);
  }
}
Yes, It looks just like in WatiN, but it is only a simple example, Selenium provides us with lots of advanced features. What about to be integrated with behavior driver development, run tests in concurrent mode for the different environments, file upload... Selenium is about that. But something is not so brilliant with new Selenium, i.e. Grid 2 future is not so clear. There is no support for Silverlight.
The second and third presentations I visited were about sharing some experience of using Selenium. Kirill Klimov and Mairbek Hadikov had shown us their way of progressing with Selenium from IDE to Grid. Kirill  described us the pros and cons of each Selenium tool form Core to Grid. As for me, I enjoyed RC the most. Mairbek had presented us some valuable advices:
1. Use automation testing
2. Integrate automation tests to Continuous Integration server and run test frequently.
3. Use code review for the test code
4. Use Selenium 2 :-)
5. Use CSS selectors, they are faster and more reliable that x-path
6. Use BDD or write test code that is clear to nontechnical people
7. Isolate test from the environment
8. Try to avoid side effects
9. Make assertions after selectors
10. Think about concurrent testing, different environment ...  thing about Grid
Of course, these advises are simple and common but some of them are regularly forgotten while writing tests.
The following topics I visited were devoted to integration of development process and Selenium.
For example, Aleksey Rezchikov shared his experience of using Selenium within Agile-oriented development. Some moments were quite interesting, i.e. there is a bunch of tools to bind a user story and functional test to make a story test: FitNesse,  Concordion, Cucumber, etc. Also he mentioned quite strong reasons to use PageObject and Feature Flags patterns.
One of the major Camp organizer Nikolay Alimenkov have shown as his way of creating acceptance tests using Selenium + Wiki = Live Requirements. This approach seems to be very cool but I am not sure I will be able to force my Product Owner to write acceptance tests even using wiki :-).
I was not sure that Selenium is able to handle rich Ajax application before the camp, but Sergey Shvets had shown his way of testing such things, and recipe was quite simple: use pauses, jQuery, atomic blocks of testing to manage Ajax requests: post backs. counts etc.

The presentations from Selenium Camp are here.

Remember, if developer is also a tester he is a Product Developer! :-)