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.

1
2
3
4
5
6
7
8
9
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:

1
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.

StepMessage handler specificThe average intensity of message processing, message / sAverage message processing time, s
1Handler does nothing22230.00047
2Handler runs in a separate thread, changes the message status and supports the cancel of execution3700.0027
3The handler as in step 2, added function to save result in DB770.013
4The handler as in step 2, added function to perform an operation lasting 10 seconds560.0179
5

The handler as in step 2, added 2 functions:

  • to perform an operation lasting 10 seconds
  • to save the result in DB
360.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.

Write US