Galaktikasoft

Xafari Server Performance

Xafari Server is a separate service that handles the tasks in the Message Queue, and stores the results in XAF application database. This post discusses its performance. Using the server significantly accelerated querying compared to querying in the application, even if the server and the application are deployed on a single workstation. Acceleration is achieved through the use of multithreading and a pool of database connections. Additional features are a cancellation request, adding (deleting) message handler. The server does not support asynchronous work automatically. To implement an asynchronous message handler, the developer must define the beginning of the substantive work in a separate thread. See, for example, this is the implementation of the IMessageHandler.StartHandler method in XafariMQSample.

public void StartHandler()
{
    _cancellationToken = _source.Token;

    LockReportMessage();

    var handlerTask = Task.Factory.StartNew(ProcessMessage, _cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
    Task.Factory.ContinueWhenAll(new[] { handlerTask }, tasks => FinishProcessing(), _cancellationToken);
}

Creating a task to handle the message:

var handlerTask = Task.Factory.StartNew(ProcessMessage, _cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);

The main logic of the handler is encoded in the ProcessMessage delegate.

The table below shows the results of running various message handlers. We used XafariMQSample application and one Xafari Server for testing. Workstation: Intel Core i3-3220 processor and 8 Gb RAM.

Step Message handler specific The average intensity of message processing, message / s Average message processing time, s
1 Handler does nothing 2223 0.00047
2 Handler runs in a separate thread, changes the message status and supports the cancel of execution 370 0.0027
3 The handler as in step 2, added function to save result in DB 77 0.013
4 The handler as in step 2, added function to perform an operation lasting 10 seconds 56 0.0179
5

The handler as in step 2, added 2 functions:

  • to perform an operation lasting 10 seconds
  • to save the result in DB
36 0.0278

Server performance was more than 2000 messages in 1 second, excluding message processing. Needless to say, after the addition of various operations handlers, the performance will drop somewhat. If the message processing in the thread is longer than 50 ms., then for the creation of thread it is recommended to use TaskCreationOptions.LongRunning option.