From 0a8932b1eda3b4152a542dec94b4338a2f5f9691 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 7 Jul 2023 17:36:55 +0300 Subject: Optimize build-task handler by reducing number of tenant object loads --- mod/mod-build-task.cxx | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'mod/mod-build-task.cxx') diff --git a/mod/mod-build-task.cxx b/mod/mod-build-task.cxx index 27597cf..a2e1f56 100644 --- a/mod/mod-build-task.cxx +++ b/mod/mod-build-task.cxx @@ -273,8 +273,11 @@ handle (request& rq, response& rs) dash_components_to_path (c.machine_pattern), dir_path () /* start */, path_match_flags::match_absent)) + { conf_machines.emplace (build_target_config_id {c.target, c.name}, config_machine {&c, &m}); + break; + } } catch (const invalid_path&) {} } @@ -303,7 +306,7 @@ handle (request& rq, response& rs) auto task = [this] (shared_ptr&& b, shared_ptr&& p, build_package_config&& pc, - shared_ptr&& t, + optional&& interactive, const config_machine& cm) -> task_response_manifest { uint64_t ts ( @@ -403,7 +406,7 @@ handle (request& rq, response& rs) move (pc.arguments), belongs (*cm.config, module_pkg ? "build2" : "host"), cm.config->warning_regexes, - move (t->interactive), + move (interactive), move (b->worker_checksum)); // Collect the build artifacts upload URLs, skipping those which are @@ -1068,8 +1071,6 @@ handle (request& rq, response& rs) position_tried (pos); } - shared_ptr p (build_db_->load (id)); - // Note that a request to interactively build a package in multiple // configurations is most likely a mistake than a deliberate choice. // Thus, for the interactive tenant let's check if the package can @@ -1087,18 +1088,25 @@ handle (request& rq, response& rs) // if (bp.interactive) { + shared_ptr t; + // Note that the tenant can be archived via some other package on // some previous iteration. Skip the package if that's the case. // - // Also note that we need to (re-)load the tenant object rather - // than to refer to bp.archived. + // Also note that if bp.archived is false, then we need to + // (re-)load the tenant object to re-check the archived flag. // - shared_ptr t ( - build_db_->load (id.tenant)); + if (!bp.archived) + { + t = build_db_->load (id.tenant); + bp.archived = t->archived; + } - if (t->archived) + if (bp.archived) continue; + assert (t != nullptr); // Wouldn't be here otherwise. + // Collect the potential build configurations as all combinations // of the tenant's packages build configurations and the // non-excluded (by the packages) build target @@ -1211,6 +1219,8 @@ handle (request& rq, response& rs) } } + shared_ptr p (build_db_->load (id)); + for (build_package_config& pc: p->configs) { pkg_config_name = pc.name; @@ -1276,13 +1286,10 @@ handle (request& rq, response& rs) shared_ptr b (build_db_->find (bid)); optional cl (challenge ()); - shared_ptr t ( - build_db_->load (bid.package.tenant)); - // Move the interactive build login information into the build // object, if the package to be built interactively. // - optional login (t->interactive + optional login (bp.interactive ? move (tqm.interactive_login) : nullopt); @@ -1360,15 +1367,20 @@ handle (request& rq, response& rs) // Archive an interactive tenant. // - if (t->interactive) + if (bp.interactive) { + shared_ptr t ( + build_db_->load (b->id.package.tenant)); + t->archived = true; build_db_->update (t); } // Finally, prepare the task response manifest. // - tsm = task (move (b), move (p), move (pc), move (t), cm); + tsm = task ( + move (b), move (p), move (pc), move (bp.interactive), cm); + break; // Bail out from the package configurations loop. } } @@ -1524,7 +1536,8 @@ handle (request& rq, response& rs) build_db_->update (b); - tsm = task (move (b), move (p), move (*pc), move (t), cm); + tsm = task ( + move (b), move (p), move (*pc), move (t->interactive), cm); } } } -- cgit v1.1