Allocate multiple items up to no. of idle workers 80/251280/1
authorHyokeun Jeon <hyokeun.jeon@samsung.com>
Tue, 12 Jan 2021 07:02:49 +0000 (16:02 +0900)
committerHyokeun Jeon <hyokeun.jeon@samsung.com>
Tue, 12 Jan 2021 07:02:52 +0000 (16:02 +0900)
- Before: Wasting redundant time to calculate deps if we assign single package in every run.
- After: Assign multiple packages if there exists enough idle workers.
- Time improvement: 10 minutes savings for 1895 packages.

Change-Id: Ia060cef3b3a7301aa5f1dc6ba5e391ea3942f572

depanneur

index 2be73b0..16e4d31 100755 (executable)
--- a/depanneur
+++ b/depanneur
@@ -1315,23 +1315,28 @@ sub createrepo
 
 #---------------------------------------------------------------------
 # check state of every thread in thread pool
-# and return a idle one to use
+# and mark it as idle if it has been finished
 #---------------------------------------------------------------------
-sub find_idle {
-    my $idle = -1;
-    foreach my $w (sort keys %workers) {
+sub set_idle_of_all_finished_thread {
+    foreach my $w (sort { $a <=> $b } keys %workers) {
         my $tid = $workers{$w}->{tid};
-        my $state = $workers{$w}->{state};
         # check the thread id, set it state idle
         # if it has been finished
         if (! defined(threads->object($tid))) {
             set_idle($w);
-            $idle = $w;
-            last;
         }
     }
+}
+
+#---------------------------------------------------------------------
+# check state of every thread in thread pool
+# and return a idle one to use
+#---------------------------------------------------------------------
+sub find_idle {
+    my $idle = -1;
+    set_idle_of_all_finished_thread();
     # find a idle one to return pool id
-    foreach my $w (sort keys %workers) {
+    foreach my $w (sort { $a <=> $b } keys %workers) {
         if ( $workers{$w}->{state} eq 'idle' ) {
             $idle = $w;
             last;
@@ -1341,6 +1346,21 @@ sub find_idle {
 }
 
 #---------------------------------------------------------------------
+# check state of every thread in thread pool
+# and return the number of idle workers
+#---------------------------------------------------------------------
+sub no_of_idle_thread {
+    set_idle_of_all_finished_thread();
+    my @idle_workers  = ();
+    foreach my $w (sort { $a <=> $b } keys %workers) {
+        if ( $workers{$w}->{state} eq 'idle' ) {
+            push (@idle_workers, $w);
+        }
+    }
+    return scalar @idle_workers;
+}
+
+#---------------------------------------------------------------------
 # set state of its thread in pool busy
 #---------------------------------------------------------------------
 sub set_busy {
@@ -2937,6 +2957,9 @@ while (! $TERM) {
     my @order = ();
     my @order_clean = ();
 
+    set_idle_of_all_finished_thread();
+    my $no_of_idles = no_of_idle_thread();
+
     {
         # update glocal vars %repo and %pkgdeps etc.
         # so lock it
@@ -2981,16 +3004,18 @@ while (! $TERM) {
                 }
                 if ($add == 1 ) {
                     push(@order, $name);
-                               last;
+                    if ($no_of_idles <= scalar @order) {
+                        last;
+                    }
                 }
             } else {
-                               push(@order_clean, $name);
-               }
+                push(@order_clean, $name);
+            }
+        }
+        #remove unuseful package name from  build_order
+        foreach my $u_name (@order_clean) {
+            @build_order = grep { $_ ne $u_name} @build_order;
         }
-               #remove unuseful package name from  build_order
-               foreach my $u_name (@order_clean) {
-                       @build_order = grep { $_ ne $u_name} @build_order;
-               }
 
         # No candidate packges and all thread works are idle, and pkgdeps
         # is updated, in this case, set packages in %tmp_expansion_errors