[ 
https://issues.apache.org/jira/browse/FELIX-1746?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765374#action_12765374
 ] 

Jed Wesley-Smith commented on FELIX-1746:
-----------------------------------------

Karl, your patch reduces the contention somewhat, as it now only synchronizes 
on the map.get() (rather than holding the ServiceRegistry lock for the entire 
read operation) and the map.put() cases using the map's monitor, but it still 
requires the lock to be acquired on read. We have found that the read case is 
called very often, while write is comparatively rare.

My patch removes all synchronisation during read, eliminating most cases of 
lock contention. It was also was extremely careful not to introduce any 
semantic changes to the ServiceRegistry. You also still use the ServiceRegistry 
monitor to co-ordinate updates to the map, which blocks concurrent calls to 
ServiceRegistry.getUsingBundles(ServiceReference), 
ServiceRegistry.getServicesInUse(Bundle) and other parts of the class that 
explicitly synchronize on (this).

Lastly, it seems to me that the edge-case change you made in alt2 (deal with 
IllegalStateException when derefencing) is orthogonal to this change and the 
change would need to be made regardless of this particular problem.

> Reduce contention on ServiceRegistry.getServiceReferences(String, Filter)
> -------------------------------------------------------------------------
>
>                 Key: FELIX-1746
>                 URL: https://issues.apache.org/jira/browse/FELIX-1746
>             Project: Felix
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: felix-2.0.0
>            Reporter: Jed Wesley-Smith
>            Assignee: Karl Pauls
>         Attachments: blocked-threads.gif.jpg, FELIX-1746-alt.patch, 
> FELIX-1746-alt2.patch, FELIX-1746.patch
>
>
> Performance testing has shown that there is significant contention on the 
> ServiceRegistry object's monitor during startup. This is caused by Spring DM 
> making lots of calls to the synchronized method 
> ServiceRegistry.getServiceReferences(String, Filter). This method is 
> synchronized in order to protect the m_serviceRegsMap HashMap, but the method 
> does a lot more work than simply accessing the map.
> Propose changing the ServiceRegistry to use a thread-safe Map implementation 
> that does not require external synchronization, in particular a 
> CopyOnWriteMap. I will add a patch that includes a CopyOnWriteMap 
> implementation.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to