[ 
https://issues.apache.org/jira/browse/CAMEL-27094?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18146099#comment-18146099
 ] 

Ayush Kulshreshtha commented on CAMEL-27094:
--------------------------------------------

I’d like to work on this. Could a committer assign it to me (ayushkul2005)?

Besides gathering the endpoints of all routes on every removal, {{doRemove()}} 
counts each endpoint’s usage by checking every remaining route’s endpoint set, 
so that part is quadratic as well.

Before writing the fix, I’d like to check the approach, because 
{{removeAllRoutes()}} has to keep calling the overridable {{removeRoute(String, 
LoggingLevel)}} ({{{}DefaultCamelContext{}}} takes the model lock first and 
also removes the route definition), and so cannot hold the context lock across 
the loop. My proposal:
 # {{removeAllRoutes()}} gathers the endpoints in use once, as a usage count 
per endpoint plus the endpoints of each route, and makes it available to 
{{removeRoute()}} for the duration of the loop.
 # Each removal uses and updates the counts instead of walking all routes, so 
removing n routes is linear in the total number of endpoints.
 # Adding a route while it is in use discards it, so {{removeRoute()}} falls 
back to gathering as today and never removes an endpoint that a newly added 
route uses.

Would that work, or would you prefer a different shape, for example a separate 
removal path for {{{}removeAllRoutes(){}}}?

> camel-core - removeAllRoutes() is quadratic in the number of routes
> -------------------------------------------------------------------
>
>                 Key: CAMEL-27094
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27094
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Ayush Kulshreshtha
>            Priority: Major
>
> {{AbstractCamelContext.removeAllRoutes()}} calls {{removeRoute()}} once per 
> route, and since CAMEL-26893 each removal of a stopped route still gathers 
> the endpoints of all remaining routes. Stopping or reloading n routes 
> therefore walks O(n²) endpoint sets. The endpoints in use could be gathered 
> once in {{removeAllRoutes()}} and updated as routes are removed. Suggested by 
> Claus Ibsen in the review of 
> [apache/camel#30255|https://github.com/apache/camel/pull/30255].



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to