Xafari Server is a separate service that handles the tasks in the Message Queue, and stores the results in
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.
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:
| 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.