Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Bugfix/improvement: Orderbook/ticker update processing #364
There have been many updates to websockets, orderbooks and tickers recently that rely on the use of maps. Every time a map is used, go has to look it up - you'll see in the old code, we were looking up items many lines in a row. At the end of our maps are pointers, so we can just make a var referencing the pointer without needing to do a double-lookup.
Coinbase Pro sends out websocket orderbook and ticker updates for every change. When processing this large amount of data, GoCryptoTrader would fall behind leading to an ever larger queue of updates. This was captured by @shazbert as a result of testing #360 (noscope)
This PR addresses that by minimising map lookups, greatly increasing efficiency. Check out the following benchmarks:
Now, even when enabling all coinbasepro currencies, disconnecting shows that there is no longer a queue of updates to be processed.
This PR also Fixes the following data race
Type of change
Please delete options that are not relevant and add an
How Has This Been Tested?
I wrote the above benchmarks, and
…nimising multiple map lookups. Changes buffer to use pointers. Ensures orderbook benchmarks are on equal footing and set correctly. Removes data race by not setting waitgroup adds inside go routine causing wait and add to happen simultaneously. Updates ticker and orderbook service to use a pointer var instead of map lookups when setting data.
@@ Coverage Diff @@ ## engine #364 +/- ## ========================================== + Coverage 42.54% 42.56% +0.01% ========================================== Files 152 152 Lines 34018 34020 +2 ========================================== + Hits 14474 14479 +5 + Misses 18583 18580 -3 Partials 961 961