From: Michael Tremer Date: Thu, 6 Feb 2025 16:41:09 +0000 (+0000) Subject: builders: Simplify the queue estimation X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=31c6d8eb2a03c3d21610bae91f0b554e2fe3dd6d;p=pbs.git builders: Simplify the queue estimation It is not a very exact science anyways to try to guess how long a job will take, so we are now just counting them which should save a couple of complex database queries when running this. Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builders.py b/src/buildservice/builders.py index dd0ec8c3..79494b6c 100644 --- a/src/buildservice/builders.py +++ b/src/buildservice/builders.py @@ -278,9 +278,6 @@ class Builders(base.Object): """ log.debug("Running autoscaling schedulder") - # XXX max queue length - threshold = datetime.timedelta(minutes=5) - builders = {} # Fetch all builders and their value for sorting @@ -300,7 +297,7 @@ class Builders(base.Object): # Store the length of the queue for each builder queue = { - builder : datetime.timedelta(0) for builder in builders + builder : 0 for builder in builders } # Run through all build jobs and allocate them to a builder. @@ -315,7 +312,7 @@ class Builders(base.Object): continue # Check if this builder is already at capacity - if queue[builder] / builder.max_jobs >= threshold: + if queue[builder] >= builder.max_jobs: log.debug("Builder %s is already full" % builder) continue @@ -325,8 +322,8 @@ class Builders(base.Object): log.debug("Builder %s can build %s" % (builder, job)) - # Add the job to the total build time - queue[builder] += job.estimated_build_time or datetime.timedelta(60) + # Store the job + queue[builder] += 1 break # Find all builders that should be running diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 50f8ed41..815bff3a 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -507,56 +507,6 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin): def size(self): return sum((p.size for p in self.packages)) - @lazy_property - def estimated_build_time(self): - """ - Returns the time we expect this job to run for - """ - res = self.db.get(""" - WITH package_estimated_build_times AS ( - SELECT - packages.name, - jobs.arch, - AVG( - jobs.finished_at - jobs.started_at - ) AS build_time - FROM - jobs - LEFT JOIN - builds ON jobs.build_id = builds.id - LEFT JOIN - packages ON builds.pkg_id = packages.id - WHERE - jobs.deleted_at IS NULL - AND - jobs.started_at IS NOT NULL - AND - jobs.finished_at IS NOT NULL - AND - jobs.failed IS FALSE - AND - builds.test IS FALSE - AND - jobs.finished_at >= (CURRENT_TIMESTAMP - '180 days'::interval) - GROUP BY - packages.name, - jobs.arch - ) - - SELECT - build_time - FROM - package_estimated_build_times - WHERE - name = %s - AND - arch = %s""", - self.pkg.name, self.arch, - ) - - if res: - return res.build_time - # Distro @property