Tuesday, 3 June 2008

VBA GSIterator

VB Space API v1.2 is released.

A nice addition to the release is the native support for GSIterator, which enabled reading large sets of data in a manageable manner. The ReadWrite example file includes a usage scenario.


Friday, 30 May 2008

Realtime Aggregations

Quartet Financial provide a very appealing product called ActivePivot.

ActivePivot offloads pivot calculations and aggregations from the client process to a backend server. It exposes XMLA interface (among others), which means that if you are an Excel user, you simply define a pivot table and point the data source to the ActivePivot server. From that point onwards, Excel interacts with ActivePivot natively.

The result is a very thin Excel spreadsheet which only displays the aggregated result, and all the number crunching and aggregations take place at the server side. When the user interacts with the pivot table, Excel queries ActivePivot and display the next level. Very nice!

ActivePivot provides hooks for the correlation and aggregation execution, so custom logic can easily be applied.

ActivePivot stores the aggregated cube in memory, which allows it to update the cube and respond to market events, and by that provide intra-day aggregations.

The real time bit is where GigaSpaces fits in

Market data feeds are written into a space using one of GigaSpaces' APIs (JMS, Remoting, JavaSpaces, etc'), and ActivePivot connect to the space and register for space events. When a tick is updated in the space, the space sends a notification to ActivePivot which in turn re-aggregates the relevant cube branch. This means that the aggregated cube is always updated and reflects the latest market state. In addition ActivePivot queries the space for the raw data when Excel sends a drill-down request, which allows ActivePivot a very quick response time.

ActivePivot can be applied at different areas and provide real time P&L, real time Risk, etc'


Friday, 23 May 2008

Deployment Predictability

My colleague Uri raised an interesting point in his post. I completely agree with Uri, and would like to give an example.

I have been involved in a project for a mobile operator in the UK during the second half of last year. We built a scale-out SOA activation platform for a new mobile device launch using GigaSpaces. The GigaSpaces platform replaced an existing system.

The original system was built using JBoss as a backend server. Predictions were for a huge increase in activation-requests the system had to handle due to the new device launch. While the system worked fine using the JBoss as a platform, there was no way these guys could predict how many instances of JBoss they would need to run in order to cope with anticipated load. They started to do some benchmarking and performance testing to figure out where the system's limits were, but they soon found out, that the process was leading them nowhere. This is mainly because the JBoss's were inconsistent and they hit the scalability ceiling using a few (very few…) nodes. When adding more instances, the overhead of synchronising the JBoss cluster grow exponentially as suggested by
Ahmdal's Law, so the gain in TP that each instance added varied depending on the cluster size and other nodes' load, which kills predictability all together.

JBoss is just an example in this case. It's not a JBoss specific flaw, but rather a tier based approached which imposes a limited architecture.

They then came to us to resolves the predictability challenge.

We did an exercise to figure out how the deployment would look like using GigaSpaces, and came up with a linear formula of the HW and number of instances needed to support the given load. More than that, they knew that if the business predictions had been pessimistic, supporting extra load would mean simply deploying more spaces... On top of that, their back office systems did not support HA, and would explode if load increased suddenly, so GigaSpaces also provided HA and throttling for the backend servers. During one overnight test the database failed for about 4 hours, and the system was fully functional and completed users' requests, while completed requests waited for the database to be brought up again to complete the archiving process. The customer was truly impressed!

Needless to say that the launch went flawless, and there were no issues what so ever with the GigaSpaces based system.

So, yes – Uri makes a good point. GigaSpaces' customers can predict and properly plan ahead the deployment needed to support their business.


Monday, 19 May 2008

Let's play...

I have been involved in a nice gaming project in the last couple of weeks.

In the first meeting, giving an overview, the prospect presented their challenge:

"We store game data in memory as we need very fast response time, and we are reaching our limits in terms of supporting our business. We are launching games which support many thousands of users and we are not able to store a game's data in a single server.

We tried using a database and running our aggregations against it. The response time we got was not acceptable. We want to store game's data across multiple JVM, but how will which JVM stores which pieces of the data?"

Well, aggregations and data partitioning go very well together if you have the right technology in hand.
Nati Shalom wrote a good post on this subject.

The interesting thing is that GigaSpaces supports aggregation since way before the Map/Reduce term was even thought of… When using
JavaSpaces' readMultiple API against a clustered space, the read request is broadcasted to all the cluster members, who execute the request (locally) in parallel, the client side receives back an array of responses which it then needs to aggregate (Reduce). With OpenSpaces, we have Springified this and it is also supported through Spring Remoting with a pluggable reducer at the client side.

A couple of hours after the dev was kicked off, we were able to demo how a single game can span multiple JVMs, aggregate the game's data in a simple fashion, and display the aggregated result. The system, which was limited to x10,000 concurrent users, can now scale to x100,000 and x1,000,000 linearly using GigaSpaces.



Wednesday, 7 May 2008

GigaSpaces VB API Beta Release

GigaSpaces VB API version 1.0 is now available under OpenSpaces.org.

Up and above some enhancements and stability fixes, the main addition in this release is native notification support for VBA applications.

The distribution includes a comprehensive example of notifications, which includes also (as a side effect) interoperability with Java. It is a simulation of FXSpot Pricing System in which prices are updated by an external system (the Java feeder in our case), and at the other end there is a spreadsheet which is listening to the FXSpot updates.

Here are the basics of the example:


@SpaceClass(persist = false, fifo = false, replicate = false)
public class FXSpot {
    private String fxName;
 private double modified;
 private float value;    

 @SpaceId(autoGenerate = false)
 public String getFxName() {
  return fxName;
 public void setFxName(String _fxName) {
  fxName = _fxName;
 @SpaceProperty(nullValue = "0")
 public double getModified() {
  return modified;
 public void setModified(double _modified) {
  modified = _modified;
 @SpaceProperty(nullValue = "0")
 public float getValue() {
  return value;
 public void setValue(float _value) {
  value = _value;

The counterpart PONO (I have omitted the COM methods):

namespace com.mycompany.trading.fx
    [ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
    public class FXSpot
        private string _fxName;
        private double _modified;
        private float _value;
   public FXSpot()
            _fxName     = null;
            _modified   = 0;
            _value      = 0;

        [SpaceID(AutoGenerate = false)]
        [SpaceProperty(AliasName = "fxName", NullValue = "")]
        public string FXName
            get { return _fxName; }
            set { _fxName = value; }

        [SpaceProperty(AliasName = "modified", NullValue = 0)]
        public double Modified
            get { return _modified; }
            set { _modified = value; }

        [SpaceProperty(AliasName = "value", NullValue = 0)]
        public float Value
            get { return _value; }
            set { _value = value; }

Java feeder – After looking up the space, and initializing Random helpers and currency names, it looks like:

    FXSpot spot = new FXSpot();

    double modified = (double)System.currentTimeMillis(); 

    // convert to Excel date
    modified = (modified + 7200000) / 86400000 + 25569;


    System.out.println("Writing spot = " + spot); 

    spaceProxy.write(spot, null, Lease.FOREVER);


Up until now, nothing new really… Now begins the interesting bit!

After omitting the initialization parts of the VBA code, what we have is the following:

Registration function:

Function RegisterNotifications(ByVal sRng As String)
    If GigaSpace Is Nothing Then
        Call Init
    End If
    Dim rng As range
    rng = range(sRng)
    Dim Template As FXObjects.FXSpot
    Template = New FXObjects.FXSpot
    Template.fxName = rng.Value
    Dim modifiers As Integer
    modifiers = NotificationModifiers.Update 

    Call GigaSpace.RegisterNotification(Template, "Notify", modifiers, sRng)
End Function

It is very easy to explain the code. If you have ever read the docs or used GigaSpaces’ notifications API, you should feel pretty comfortable here. Same rules apply… If you haven’t, a quick browse here will help understanding the API and terminology better.

You simply invoke GigaSpace.RegisterNotification method with a template to match, the name of your notify function, notify modifiers (take, write, update, all), and last argument which is not part of GigaSpaces notify API is called vbHint. It can hold any object the user wishes to receive back when the notify function is triggered for this specific registration (i.e. template match and operation match). In this example I have iterated through a list of currencies, and I pass the cell address of the specific currency to the registration so that when my Notify method is invoked, I can lookup the relevant cell easily.

My Notify function:

Function Notify(ByVal eventType As Long, ByVal pono As Object, ByVal vbHint As Object)
    Dim sRng As String
    sRng = vbHint
    Dim rng As range
    rng = range(sRng)
    Dim spot As FXObjects.FXSpot
    spot = pono
    rng.Offset(0, 1).Value = spot.Value
    rng.Offset(0, 2).Value = spot.Modified
End Function

Note the Notify signature. When registering to notifications, the notify function must have this signature in terms of the types it takes as arguments. The eventType represents the space operation which triggered the notification, and the pono is the object which matched the registration’s template and triggered the notify.

In this example, I take the values from the notification object, and update the relevant Excel cells (I use the vbHint for that).

The example includes a button to UnRegisterNotifications.

Public Sub UnReg()
    If Not (GigaSpace Is Nothing) Then
        Call GigaSpace.UnRegisterNotifications
    End If
End Sub

The UnRegisterNotifications method removes all registrations for the invoking Excel from the space.

One more thing to note is the termination of the Excel process. As notifications require some daemon threads to run at the background, the Excel needs to invoke GigaSpace.Terminate function which cleans up these threads and frees some resources. Failing to invoke the method could result a hanging Excel process. As a best practice, you should catch the Excel workbook close event and call the terminate method.

Example (at the workbook level):

Private Sub Workbook_BeforeClose(ByVal Cancel As Boolean)
    Call TerminateGigaSpace
End Sub

Which invokes the Terminate method:

Public Function TerminateGigaSpace()
    If Not (GigaSpace Is Nothing) Then
        Call GigaSpace.Terminate
    End If
End Function

The example with inline comments and documentation is packed in the setup. After downloading and completing the installation process, the example Excel can be run from --> Programs --> VB Space API --> Examples --> FXSpot Notify. The example is located under \Examples\FXPrices. Follow the readMe.txt to run and change the example.



Saturday, 26 April 2008

Dealing With Excel Arrays

One of the nice things in Excel is the ability to treat scalar, any size vector, and any size matrix in the same way (from the developer's perspective). This is very powerful, and saves a lot of development time.

It gets interesting when you add COM and C# into the picture… I am working on a demo which includes Excel and C# (more on the demo in a different post), and one of the things we needed to do is pass arrays from the spreadsheet to our C# logic. We are using COM for the interaction. This is where the problem starts. When you fill up an array in Excel and pass it over COM, it is received at the other side as an object, not as an array, and you can not access the array's elements.

The solution for that is to use reflection and to interrogate the object using simple array methods. It took us some time to find how this should be done properly (thanks to PK), and this is it:

First of all, let's assume we have a range of doubles in your spreadsheet. I named the range "double_range":

Next, I have a utility function which populates a VBA array with the values:

My VBA code which passes the array, looks like:

My C# object does not use an attribute setter, but rather have a setter method which invokes a translator utility function:

Translator function is the most important piece of this puzzle:

I have uploaded the code snippets into a text file here.

The VBSpaceAPI will include such helpers in its next release and Will support arrays natively.


Saturday, 12 April 2008

VB Space API Alfa Release

An Alfa release of the Space VB API is now available at OpenSpaces.org.

There are a number of changes in this build. Main ones are a new installer, a fix for default value in read and take APIs, and a more comprehensive example and documentation pages.

You can read more about it in the project pages, but one thing I want to specifically mention in my experience with the installer program.

It has been very long since the last time I had to compile an installer program. Actually, it was around 1998, where I created a setup for a university project. It was based on InstallShield, which made the entire process long and painful! This time it was very different. I used a utility called Inno Setup
, a very lightweight and simple installer. It took me no more than 10 minutes to create the first run of the setup, and another half an hour or so to customise it with my own specific stuff (making sure GigaSpaces is installed, invoking the example at the end of the setup, etc'), which was also straight forward to do thanks to the detailed help files provided.

Now, surely InstallShield could do everything I needed and much more, but it would have been much harder and a longer process... Kudos to Jordan Russell for the well designed and implemented installer utility!



Tuesday, 8 April 2008

Google's Cloud Is Now Public

Well almost...

Google has announced AppEngine, which is, in essence, a platform for developing web applications using Google's platform, and deploying them into Google's cloud.

Google like Google, released AppEngine in a very controlled way, granting access to the first 10,000 users who registered to the Beta program. Too bad I wasn't quick enough… I am sure that the user-experience and the set of features provided will make developing and deploying web apps into Google an easy and nice experience.

As for the release being a Beta, that's also a nice trick by Google. It really doesn’t mean that AppEngine is not mature yet, it's just a way to lower our expectation a bit I guess. Take GMail for instance, it's still at Beta stage!

A very detailed description of the offering from Brady Forrest, which also discusses some differences between AppEngine and Amazon's AWS


Monday, 7 April 2008

VB Space API 0.1 Is Released

I have released the first version of the VB API as a Pre-Alfa under OpenSpace.org. The main purpose of this early release is to gather feedback from prospective users, and build-up a proper roadmap. The backlog is filling up with stuff such as install program, batch operations, notification, and additional space functionality, and I'd appreciate your input and rating as to those or other items.

The release includes a nice little Excel file as an example, where you can interact with the space to write and read Person objects. The Excel file includes comments which explain how the example should be used, whereas the code, being very simple and self-explanatory, does not require extra elaboration in my opinion. Follow the
installation and example instructions and give it a try. Comments are welcomed!

Technical background and limitations – The VB API uses GigaSpaces C# API over COM. This means that I have a C# class which wraps GigaSpaces' C# API, and is exposed as a COM class. From this point onwards, the VB application communicates with my C# layer using COM.

There is a number of VB / COM limitations which I had to work around. I am still looking for ways to overcome these issues. One of the things you will note is that the Read API takes two arguments: a template, and a default value (there is an overloaded Read which also takes a blocking timeout as a parameter):

This is because VB over COM does not allow you (or I haven’t yet found the proper way) to return a null value from the C# layer and set it to the Response object, nor did I find a way to cast COM's return value. So when there is no result back for the template match in the space, I could not simply return null. I am looking at generics support for VB / COM, in which case the problem is solved as I can do something like: return default(T);

Another limitation I found is the inability to specify a VB class as serializable, which means that you need to declare your business classes using C#. It's a fairly quick and straight forward task, though I am still googling for a proper solution which will allow users to stay in the VB environment from start to end. If that proves to be impossible I can think of means such as generators to ease this process.

In next posts I will demonstrate how to create a full example from scratch.


Friday, 4 April 2008

GigaSpaces VB API

GigaSpaces provides scaling solutions for Excel, a.k.a. "Excel That Scales"

A lot have been said and written about it, and there is plenty of collaterals, examples, and webcasts. That's all good and fine, but what I would like to suggest in this post is a simplified way to access the space from within an Excel spreadsheet and / or any other VB application.

I am targeting Excel or VB developers who require simple means to interact with the space, and prefer not to exhaust their C# skill-set.

As an example, say you want to write a Person object into the space. Using the C# as an access layer to the space, you will need to implement your Person C# class, and space accessibility methods. See the following example for more details (replace HelloMsg with Person…)

What if you could work with the space API from within your Excel code without having to develop an access function (WritePerson() in our case) in C#? I.e. What if you had a reference to VB Space proxy? Think of your code looking something like the following (using the Person example):

Sub WriteToSpace()
Dim aPerson As Person
Set aPerson = New Person

aPerson.FirstName = ActiveCell.Offset(1, 0).Value
aPerson.LastName = ActiveCell.Offset(2, 0).Value
aPerson.Age = ActiveCell.Offset(3, 0).Value

Call GigaSpace.Write(aPerson)
End Sub

And to read a Person object, you'd have to do something like the following (note that I filter the person according to the current user's selection as first name, and then just print the last name and age):

Sub ReadFromSpace()
Dim Template As Person
Set Template = New Person

Template.FirstName = ActiveCell.Value

Dim Response As Person

Set Response = GigaSpace.Read(Template)

ActiveCell.Offset(1, 0).Value = Response.LastName
ActiveCell.Offset(2, 0).Value = Response.Age
End Sub

In this example all you need to do is define your Person object (as a space class using C#), and include it in your COM libraries. The rest is your good old VB code working with the space API…

If you like this approach, stay tuned. I am working on the first version of the API, which will be released fairly soon.