[SERVER-621] Fully construct ring handler before registering with the web server Created: 2015/05/12 Updated: 2016/01/19 Resolved: 2015/07/23 Status: Project: Component/s: Affects Version/s: Fix Version/s: Closed Puppet Server None None Type: Reporter: Resolution: Labels: Remaining Estimate: Time Spent: Original Estimate: Improvement Jeremy Barlow Cannot Reproduce None Not Specified Template: Epic Link: Scrum Team: QA Contact: QA Status: customfield_10700 true Server- TBD tickets Puppet Server Erik Dasher Reviewed SERVER 2.x, SERVER 1.x Priority: Assignee: Votes: Normal Unassigned 0 Not Specified Not Specified Description In Puppet Server code, I noticed that we do this in master_service.clj... (add-ring-handler this (compojure/context path [] (core/build-ring-handler handlerequest)) {:route-id :master-routes}) ... where build-ring-handler returns "compojure/routes" wrapped with middleware as desired. I haven't really looked into what the compojure macros expand into but it seems like it might be more efficient to do this... (let [handler (compojure/context path [] (core/build-ring-handler handle-request)) {:route-id :master-routes})] (add-ring-handler this handler) ...so that the logic in build-ring-handler is executed only once - not for every web request that is handled. Note that the same approach is currently being used for the certificate-authority-service route registration. Maybe there was a reason we did it this way to begin with - or maybe the overhead involved in re-executing build-ring-handler beyond the first call isn't significant (given compilation to byte code on the first pass, etc.). Throwing this ticket to consider making the suggested change above as an optimization at some point if it makes sense. Comments Comment by Kevin Corcoran [ 2015/07/23 ] Jeremy Barlow - Is this ticket still relevant now that we've switched to comidi? Comment by Jeremy Barlow [ 2015/07/23 ] Kevin Corcoran I don't think this is relevant anymore. For the master-service, we ended up switching to the approach of constructing the handler and just passing a reference to the handler var in the call to add-ring-handler anyway. I think we did that around the time we were doing some refactoring related to the legacy-routes-service. Justin May might recall more details there. For the certificate-authority-service, though, we're still using the approach of defining the handler in line as part of the call to add-ring-handler. From https://github.com/puppetlabs/puppet-server/blob/puppet-server2.1.1/src/clj/puppetlabs/services/ca/certificate_authority_service.clj#L20-L25: (add-ring-handler this (-> (core/web-routes settings) (#(comidi/context path %)) comidi/routes->handler (core/wrap-middleware puppet-version)))) I instrumented behind each of the threaded calls made to create the handler result and confirmed that they are each only made once - and not once per request handled like we were getting with our compojure / ring-handler creation earlier. So I'm good with just closing this issue out. Comment by Kevin Corcoran [ 2015/07/23 ] cool, thanks man. Generated at Tue Feb 09 07:30:10 PST 2016 using JIRA 6.4.12#64027sha1:e3691cc1283c0f3cef6d65d3ea82d47743692b57.