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
- 6 AHS
- 39 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 370 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 60 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛