Describe the bug
The XmlUtils.updateMapWithLimit method attempts to cap the number of entries in a map.
However, it is not thread safe, and if multiple threads attempt to insert a new key at the same time, it is possible to get more entries in the map than desired.
This gives non-deterministic results when running multi-threaded apps (eg. qprofiler2)
To Reproduce
run qprofiler2 with multiple consumer threads a number of times
compare outputs - you will most likely see additional map entries in some instances
Expected behavior
It would be great to be able to run qprofiler2 multiple times with multiple threads and get the same result every time
Additional context
Is there any reason that the map is being kept to a certain size? If it is just the top 100 entries that are required, would it not be a better approach to capture all the entries, and then sort and report on just the top 100? That way you would get the same results every time.
Describe the bug The
XmlUtils.updateMapWithLimit
method attempts to cap the number of entries in a map. However, it is not thread safe, and if multiple threads attempt to insert a new key at the same time, it is possible to get more entries in the map than desired.This gives non-deterministic results when running multi-threaded apps (eg.
qprofiler2
)To Reproduce
qprofiler2
with multiple consumer threads a number of timesExpected behavior It would be great to be able to run
qprofiler2
multiple times with multiple threads and get the same result every timeAdditional context Is there any reason that the map is being kept to a certain size? If it is just the top 100 entries that are required, would it not be a better approach to capture all the entries, and then sort and report on just the top 100? That way you would get the same results every time.