[ https://issues.apache.org/jira/browse/CXF-6823?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15184812#comment-15184812 ]
Brendon edited comment on CXF-6823 at 3/8/16 12:07 PM: ------------------------------------------------------- Edited to add more detail. >From what I can determine, the 4 ProviderInfo objects above are added to the >injectedProviders list whenever we create a new JAXRSClient (by calling >org.apache.cxf.jaxrs.client.JAXRSClientFactory#create(java.lang.String, >java.lang.Class<T>, java.util.List<?>, >java.util.List<org.apache.cxf.feature.Feature>, java.lang.String)). We have a LOT of jaxrs references so it's probably amplified by the number of clients we're creating. The main flow from what I can see is: 1. JAXRSClientFactory#create(...) calls (through a bunch of other calls) ProviderFactory#setCommonProviders 2. setCommonProviders passes (messageReaders, messageWriters, contextResolvers, paramConverters, readerInterceptors, and writerInterceptors) to ProviderFactory#injectContextProxies 3. injectContextProxies adds each provider to injectedProviders (supporting duplicates). The params in step 2 are not changed, hence they get duplicated. was (Author: codenative): >From what I can determine, the 4 ProviderInfo objects above are added to the >injectedProviders list whenever we create a new JAXRSClient (by calling >org.apache.cxf.jaxrs.client.JAXRSClientFactory#create(java.lang.String, >java.lang.Class<T>, java.util.List<?>, >java.util.List<org.apache.cxf.feature.Feature>, java.lang.String)). We have a LOT of jaxrs references so it's probably amplified by the number of clients we're creating. The main touch points are that JAXRSClientFactory#create(...) calls org.apache.cxf.jaxrs.provider.ProviderFactory#initFactory which adds the providers to the factory which then calls org.apache.cxf.jaxrs.provider.ProviderFactory#injectContextProxies to add each provider to injectedProviders (supporting duplicates). > Duplicate injectedProviders in ProviderFactory impacting throughput by ~30% > --------------------------------------------------------------------------- > > Key: CXF-6823 > URL: https://issues.apache.org/jira/browse/CXF-6823 > Project: CXF > Issue Type: Bug > Components: JAX-RS > Affects Versions: 3.1.5 > Reporter: Brendon > Labels: performance > > We are using CXF to process JAX-RS requests and have noticed a large number > of threads blocking in a synchronised block. > ClientProviderFactory and ServerProviderFactory extend ProviderFactory which > contains a member variable > org.apache.cxf.jaxrs.provider.ProviderFactory#injectedProviders (a > LinkedList). > Due to injectProviders being a list, it supports (and contains) duplicates. > In our application, we currently have the following: > org.apache.cxf.jaxrs.client.ClientProviderFactory: 26 elements > org.apache.cxf.jaxrs.provider.ServerProviderFactory: 8504 elements > But there are only 4 unique ProviderInfo objects in these lists, namely: > org.apache.cxf.jaxrs.provider.FormEncodingProvider > org.apache.cxf.jaxrs.provider.MultipartProvider > org.apache.cxf.jaxrs.provider.SourceProvider > org.apache.cxf.jaxrs.provider.JAXBElementProvider > The issue is that injectProviders is iterated on each response to clear > thread local proxies > (org.apache.cxf.jaxrs.provider.ProviderFactory#clearThreadLocalProxies). > Clearing of the thread local proxies relies on a synchronized block to > retrieve the thread local proxies from the bus > (org.apache.cxf.jaxrs.model.AbstractResourceInfo#getProxyMap). > This means that at scale, the code blocks waiting for entry into this code. I > have seen a huge number of threads waiting for entry into this block. > As a test, I have changed injectedProviders to a Set to remove the duplicates > and have seen an increase in throughput (RPS) of about ~30% in our > application. -- This message was sent by Atlassian JIRA (v6.3.4#6332)