📜 ⬆️ ⬇️

Need for speed: Optimization of the trading terminal performance



Earlier in our blog, we talked about why traders in the stock market use trading terminals , and presented the history of developing their own SmartX terminal.

In today's stock market , speed is very important - in order to get ahead of competitors and make a deal at the best price, traders develop their own trading systems, put their trading robots servers for collocation into stock and brokerage data centers, use direct access technologies .
')
For those of them who perform operations manually using the terminal, its speed and reliability of operation are also very important. That is why the developers of commercial software are constantly engaged in optimizing its performance. Today we will tell how to increase the speed of the terminal SmartX .

Why speed up the terminal


The need to speed up the operation of the SmartX terminal has matured for two reasons - often traders launch trading software on portable devices (laptops, tablets under Windows), not on the most powerful “office computers” or just old machines.

At the same time, the market activity only increases from year to year, and in terms of, for example, strong movements or the so-called “panic-sale” on important economic news days, the amount of market data (market data) sent by the server to the terminal can be short terms increase tenfold. If the program is running on a weak device, it may just hang at the crucial moment, which can result in the loss of money by the user.

In addition, there is a whole class of active traders on the market (for example, scalpers, arbitrageurs, and high frequency traders) who, even on a typical trading day, carry out a large number of orders and transactions. Such merchants rarely use GUI terminals for direct trading, but they often use this kind of software to control their positions, however a large amount of data generated by them can even “not be digested” by a powerful computer.

In no case should the trading terminal become a “narrow” place in the “trader-exchange” chain, therefore, work on its improvement and optimization of productivity should be carried out constantly.

How is the terminal


Before diving into the description of the terminal optimization process, you should understand which components include such software. ( In order not to delay those who are interested in the optimization process itself, we removed these details under the spoiler ).

How things are arranged
The SmartX trading terminal consists of protocol and terminal parts.

The first of them is responsible for “communicating” with the servers of the brokerage trading system ( Matrix - we had separate material about it) - it “merges” all incoming data streams into one message flow. Accordingly, the protocol part is multi-threaded. It is written in C ++.

The terminal part with the specified period polls the resulting message queue and does the necessary calculations to display information to the user. This software is single-threaded and written in C #. (Our blog also published an interesting interview with SmartX developers about why C # and C ++ are so popular in the stock market .)

Basic optimization concepts


Now let's take a closer look at the performance optimization techniques used.

The first one is deferred rendering . A significant part of the “activity” of the trading terminal falls on the drawing of various tables and graphs. Constant updating of all graphs and tables requires significant resources, but if you redraw them only if new data is received, and also start drawing only after the main thread is freed from processing the message queue, this can significantly improve performance.

In addition, a filtering mechanism was implemented for loaded data streams (both in the terminal and in the protocol parts of the terminal). Such flows include quotes, snapshots of stock "glasses", etc.

This was done to ensure that when the load increases, for example, when market activity increases after the release of economic news, the terminal “discarded” data that had already become historical at the time, and showed the user only the latest information.

Prior to the introduction of such a technology at peak times, the terminal could begin to lag and display “historical” data, and the GUI at such moments could hang at all, unable to cope with the processing of large data arrays.

The next stage of optimization was the reduction of memory traffic . A bottleneck in this mechanism, as you know, is the GarbageCollection, so the terminal developers implemented their own memory management for those objects and collections that are often created or updated. With its help, it was possible to reduce the number of garbage collections during the terminal operation, and therefore - to improve its performance

As a result, the GUI does not freeze during the garbage collection, it also allows the terminal to work an unlimited amount of time without rebooting - the amount of memory used does not grow.

Is it better: the test


To test how much better the trading terminal began to work, a stress test was launched on the test circuit of the brokerage trading system, consisting in starting the load data flow generator - 1000 ticks, 1000 glasses and 1000 quotes changes (“quotas”) per second.



Part of the test: opening in the terminal a large number of glasses on the instrument (more than 40)

On the Celeron G460 1.8GHz 2Gb computer, the following terminal versions were compared:


The following test results were obtained:




As you can see, the performance of the terminal has increased significantly, and the CPU load has significantly decreased. The optimization is relevant for all users of the terminal, but it will be especially appreciated by traders who run the terminal on low-power computers, as well as those who use a large number of financial instruments, glasses, charts and indicators in the program.

That's all for today, thank you for your attention! Don't forget to subscribe to our blog .

Source: https://habr.com/ru/post/257919/


All Articles