]> git.ipfire.org Git - pbs.git/commitdiff
builders: Simplify the queue estimation
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 16:41:09 +0000 (16:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 16:41:09 +0000 (16:41 +0000)
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 <michael.tremer@ipfire.org>
src/buildservice/builders.py
src/buildservice/jobs.py

index dd0ec8c39080646bca7a0a5aebc05fdeab3e80a6..79494b6c253ba679286c77f49ca45c3c49982635 100644 (file)
@@ -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
index 50f8ed41c06d309ba0f3eb1bd0b86b814682dce8..815bff3a06ff30548f9f90adc5c4019e354e922f 100644 (file)
@@ -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