poor performance in OmmConsumerImpl.unregister(handle)

When large number of handles are registered then calls to OmmConsumerImpl.unregister(handle)
become very slow.
I traced this to WlItemHandler.removeUserRequestFromClosedStream(WlRequest)
which iterates over a LinkedList
using an integer index, calling LinkedList.get(i)
for each index. Since get(i)
is O(N) on a LinkedList (each time it is called it has to walk down the list to get to that index), just this step is O(N2). If it finds a match it then calls LinkedList.remove(i)
which again has to walk down the entire list to find that index and remove it.
Calling this on every handle in a set of 379233 handles took 48 minutes! 99% of the CPU time is in WlItemHandler.removeUserRequestFromClosedStream(WlRequest)
.
If you use an iterator you can just walk the list just once, turning the method into O(N). The performance improvement will be enormous. Basically change this
private int removeUserRequestFromClosedStream(WlRequest wlRequest) {
for (int i = 0; i < _userStreamIdListToRecover.size(); i++) {
int listStreamId = _userStreamIdListToRecover.get(i);
if (listStreamId == wlRequest.requestMsg().streamId()) {
_userStreamIdListToRecover.remove(i);
break;
}
}
...
to
private int removeUserRequestFromClosedStream(WlRequest wlRequest) {
Iterator<Integer> iter = _userStreamIdListToRecover.iterator();
while (iter.hasNext()) {
int listStreamId = iter.next();
if (listStreamId == wlRequest.requestMsg().streamId()) {
iter.remove();
break;
}
}
...
or in this case you could even just do
private int removeUserRequestFromClosedStream(WlRequest wlRequest) {
_userStreamIdListToRecover.remove(wlRequest.requestMsg().streamId());
...
and let Java do the iterate and remove for you.
This method also has an iteration over _statusMsgDispatchList
that needs the same treatment (since it does additional actions inside the loop you either have to use the first iterator form I provided, or you have check the boolean result if you use the second form and do the actions outside the loop).
There are dozens of examples of this same problem in this class, and they really all should be fixed. You might also consider a different Collection type. LinkedHashSet want to preserve order and don't want duplicates (and I assume you never want duplicates of handles) or just HashSet if you don't care about order. Both would give O(1) performance (constant time) for these operations and thus be even faster. ArrayList would be faster if you really need to access by index but would cause the remove to go back to O(N).
Best Answer
-
Thank you so much for sharing this finding.
Please raise it to the development team direclty via GitHub. Therefore, the development team can review the code.
0
Answers
-
flame graph from DataDog APM profiler which shows where all the CPU is used
0 -
I raised https://github.com/Refinitiv/Real-Time-SDK/issues/247
@Jirapongse can you please make sure the devs see it? I feel like I can't go into production with this serious of a performance issue.
0 -
@daniel.lipofsky
Yes. The development team always monitors the issues on GitHub.
Otherwise, if you have Refinitiv Developer Connect (RDC) contacts, you can also rasie this request via Contact Premium Support.
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 690 Datastream
- 1.4K DSS
- 629 Eikon COM
- 5.2K Eikon Data APIs
- 11 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 255 ETA
- 559 WebSocket API
- 39 FX Venues
- 15 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 25 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 280 Open PermID
- 45 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 2K Refinitiv Data Platform
- 720 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 106 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 95 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛