Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCAP dialogs put-get collision in TCAPProviderImpl #107

Closed
Oleg-Afanasiev opened this issue Jun 2, 2016 · 6 comments
Closed

TCAP dialogs put-get collision in TCAPProviderImpl #107

Oleg-Afanasiev opened this issue Jun 2, 2016 · 6 comments
Assignees

Comments

@Oleg-Afanasiev
Copy link

Type: Fix
Description: TCAP fragments of code "... dialogs.get(dialogId) ..." in TCAPProviderImpl need to be inside of synchronized blocks. Because collisions of getting by dialogId can happen before this value will be put. This collisions were detected in high loaded tests with several hundreds of threads on multiprocessor machine.
I managed to fix this problem and attaching both fixed file and old one.

TCAPProviderImpl.java.txt
TCAPProviderImpl-fixed.java.txt

@deruelle
Copy link
Member

deruelle commented Jun 2, 2016

Thanks @Oleg-Afanasiev for the report and contribution !

Can you please sign the contributor license agreement at http://www.telestax.com/open-source/#Contribute and also do a formal pull request as decribed in our Open Source Playbook ?

@vetss
Copy link
Contributor

vetss commented Jun 9, 2016

Hello @Oleg-Afanasiev,

Let's continue discussing in #110.
We need to have the best solution for it.

@vetss vetss added this to the 7.1.0 milestone Jun 9, 2016
@vetss vetss self-assigned this Jun 9, 2016
@jaimecasero
Copy link

have you consider using FastMap.shared API as in concurrentHashMap, trying to leverage putIfAbsent?. The fix involves a system/stack level lock to protect the "getPreviewDialog" where the actual write happens, this may introduce high thread contetnion(consider reducing the scope of the lock for both the sync object and the code block).

@vetss
Copy link
Contributor

vetss commented Dec 21, 2016

Hello @jaimecasero

we used FastMap for much time trying to achieve max productivity (as FastMap declares very high scalabiliy) by usage of locking for writing and reading without locking. But as for now we have confirmations that there are collisions there.
Usage of FastMap.shared() (as for its description) will not fix that collision problem. And "putIfAbsent()" we have not tried, I have no idea how it may help us.
I am thinkg of leverage of ConcurrentHashMap collection and remove our synch() blocks for them.

As for a suggested fix, I do not like such big synch() blocks too.

@jaimecasero
Copy link

jaimecasero commented Dec 21, 2016

ConcurrentHashMap collection==FastMap.shared() -> the key of these concurrent collections is not the implementation (i agree using shared alone will not make any difference), but the additional API exposed. If you dont use the "putIfAbsent" method from a ConcHashMap/shared, instead of regualr "put" there wont be much difference (that true even for CHM).
The magic of putIfAbsent is that the key presence check is done atomically inside the collection impl.

Also there are new features in Java8.computeIfAbsent or Guava.MapMaker collections that may be worth visitins to prevent the systemWide lock, as explained in:
http://stackoverflow.com/questions/3752194/should-you-check-if-the-map-containskey-before-using-concurrentmaps-putifabsent

@vetss
Copy link
Contributor

vetss commented Jan 19, 2017

Hello @jaimecasero @Oleg-Afanasiev

thanks for raising an issue and discussing of it. I have committed updates for the described problem. Please check commits list in #110. I have tried to remove of synchronized() blocks and switched instead of it to ConcurrentHashMap that may help us in collisions.
Updates are committed into master branch.

@Oleg-Afanasiev , can you please check the code at your tests for checking if a problem is fixed or not.

@vetss vetss modified the milestones: Sergey-8.0-sprint1, 8.0.0 Jul 23, 2017
@vetss vetss closed this as completed Aug 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants