CAMEL-19815: use a ConcurrentHashMap instead of a blanket synchronize#11279
CAMEL-19815: use a ConcurrentHashMap instead of a blanket synchronize#11279orpiske wants to merge 2 commits intoapache:mainfrom
Conversation
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Maintainers, please note that first-time contributors require manual approval for the GitHub Actions to run. 🤖 Use the command If necessary Apache Camel Committers may access logs and test results in the job summaries! |
| ref = new QueueReference(queue, size, multipleConsumers); | ||
| QueueReference ref = new QueueReference(queue, size, multipleConsumers); | ||
| ref.addReference(endpoint); | ||
| getQueues().put(key, ref); |
There was a problem hiding this comment.
Maybe we should consider creating the queue and the queue reference in a computeIfAbsent to prevent concurrent creation for the same key
| if (ref.getSize() != null) { | ||
| setSize(ref.getSize()); | ||
| synchronized (this) { | ||
| if (queue == null) { |
There was a problem hiding this comment.
Warning, queue is not volatile so this is not thread-safe
|
Maybe I misunderstood your results, but I don't see a real significant improvement, could you please clarify a bit your results? |
|
Marking it as a draft as I want to go through @essobedo's comments next week. |
|
Another question, Is there a real-life use case where we heavily create queues? otherwise, I don't really get the real need of improving it. Do you have profiler reports indicating that this part of the code as an hot spot? |
The key ones are the top two on each table. They are measured in terms of number of operations per millisecond. Even though the number seems small, when spread over the course of a few minutes/hours, this results in quite a lot more exchanges going through the core. |
|
You mean that we need to compare |
| } | ||
| return ref; | ||
| } | ||
|
|
There was a problem hiding this comment.
Can the 'synchronized' keyword in the 'registerQueue' method also be eliminated? I believe you can utilize 'computeIfAbsent,' as suggested by @essobedo in the comment above.
Exactly. This tries to bring the code closer to what we had in 4.0, as I had to revert one of the performance improvements we had there. BTW, answering your other question: "Is there a real-life use case where we heavily create queues". The answer is yes, we do. Basically, that patch for 4.0 was breaking a scenario for an user that was heavily creating queues. |
|
Interesting, by chance, do you have the html version of the reports to allow me to zoom in? |
|
Obs.: please, do feel free to review. I'll go through your review comments next week. For now just answering the non-review questions as my brain is basically a jelly after this week. |
Here's one: http://angusyoung.org/arquivos/tmp/profile-camel-19815-with-perf-v6-4.1.0-SNAPSHOT-2023-09-01-043702.html Obs.: just keep in mind that this is just one of the many scenarios I run (and NOT generated from the same JMH results I pasted - it's just the only one I have readily available). If you want a different one (i.e.: uncontended SEDA or etc), drop me a note next week and I can send it to you (or point to how you can generate your own). |
If so if you check well the second case is better with Camel 4.0 and the first one is slightly better with Camel 4.1 but you have a higher Error I'm wondering if an improvement of less than 1 % is insignificant enough to be considered a real improvement as the results may vary a lot from one test to another. BTW, I've just realized that you set forks to 1, maybe you should retry with 3 to get more reliable results? |
Normally that would be the case (i.e.: if we were comparing the results from the same test class). However, these tests are already running on forked executions: the iterations for different versions run separately (as in, the automation runs the tests for one version and then for another - not on the same JVM, I mean). |
Thx for sharing do you have the same kind of report for 4.0 (the baseline)? |
Not right now, as I am off from work, but on Monday I'll take a look at the review comments you raised (along w/ the ones from @rhuan080), adjust the code and regenerate all the data. I'll post the update report so you guys can look at it. |
This should help offset the performance impacts of removing the cached QueueReference on d66469d
…/unboxing WIP: removing auto-boxing/unboxing
d4c0bc6 to
26b436f
Compare
|
Let's put this one on pause for now. I tried with the suggestions, but the performance wasn't better: 4.1.0-SNAPSHOT Updated I'll get back to this one with a clearer head in a couple of weeks, after I dispatch other higher priority items. Edit: tracking this on CAMEL-19830. |


This should help offset the performance impacts of removing the cached QueueReference on d66469d
4.1 (this patch)
4.1 (without the patch)
4.0 (baseline)