The code is virtually identical to the trades-by-second query in the previous post. What was unexplained previously is the presence of the mysterious Segmenter function. The Segmenter deserves a blog post of its own but, in principle, it allows the GroupBy to scale to a large number of groups. In this case, there are 1,881,910,846 groups that are further processed by the OrderBy clause and reduced to 200,000 tuples. The reduction is needed to be able to visualize the result but is GrokIt has no trouble dealing with results of this size.
In this case, I am showing below the actual performance graphs GrokIt is displaying instead on average performance numbers. The execution on fgrokit produces the performance graphs:
A number of interesting things can be noticed during the execution:
- The execution is chaotic from the CPU and number of tuples point of view. This really is a harsh query that requires a large amount of memory allocation and traffic. This results in large fluctuations throughout the execution.
- GrokIt cannot keep up with the IO (i.e. the disk is too fast) in this query. There are a large number of chunk drops, as can be seen from the "Chunks Dropped" graph. Chunks are the unit of storage and processing in GrokIt and contain 2 million tuples.
- GrokIt does not read data at full speed (4 GB/s on fgrokit). This is due to the large interference between the chaotic memory access of the query processing and the IO.
- Despite the obvious struggling, fgrokit finishes the query in 233s. In this time, 56.8 billion tuples were grouped into 1.8 billion groups and then the top 200,000 best tuples extracted.
- There is probably room for improvement for GrokIt since the execution looks wasteful (too many chunk drops).
| Date | Millisecond | cnt |
|---|---|---|
| 2009-Nov-23 | 35,998,000 | 14,740 |
| 2010-Jan-26 | 35,998,950 | 14,715 |
| 2010-May-07 | 44,417,850 | 12,377 |
| 2009-Dec-01 | 36,000,750 | 12,066 |
| 2010-May-05 | 34,319,350 | 11,698 |
| 2010-Feb-08 | 56,486,475 | 11,682 |
| 2010-Jan-29 | 56,661,350 | 11,656 |
| 2009-Nov-04 | 53,561,975 | 10,735 |
| 2010-Jan-29 | 53,907,275 | 10,591 |
| 2010-May-07 | 45,911,500 | 9,226 |
The top entry has 14,740 trades for the 25ms interval. If sustained for a full second, this would correspond to 589,600 trades/second, almost 6 times larger than the largest per second rate we have seen in the previous blog post. By consulting again the per second results, for November 23, 2009 at second 35,998 (this is the second in which the top millisecond falls into), the total number of trades is 38,512 and the rank among the top seconds is 539. This means that half the trades in this second happened in a 25ms interval -- this reaffirms the idea of flash trading possible only with algorithmic trading. Looking at the second highest 25ms, the total trades in the corresponding second are 19,195 ranked 9573 among the top seconds. In this situation, 75% of all trading in the second happens in this 25ms interval.



