Просмотр исходного кода

acquire: Allow parallelizing methods without hosts

The maximum parallelization soft limit is the number of CPU
cores * 2 on systems defining _SC_NPROCESSORS_ONLN. The hard
limit in all cases is Acquire::QueueHost::Limit.
Julian Andres Klode лет назад: 10
Родитель
Сommit
b89cd2e36f
1 измененных файлов с 22 добавлено и 2 удалено
  1. 22 2
      apt-pkg/acquire.cc

+ 22 - 2
apt-pkg/acquire.cc

@@ -351,8 +351,28 @@ string pkgAcquire::QueueName(string Uri,MethodConfig const *&Config)
    if (Config->SingleInstance == true || QueueMode == QueueAccess)
       return U.Access;
 
-   string AccessSchema = U.Access + ':',
-	FullQueueName = AccessSchema + U.Host;
+   string AccessSchema = U.Access + ':';
+	string FullQueueName;
+
+   if (U.Host.empty())
+   {
+      long randomQueue = random();
+#ifdef _SC_NPROCESSORS_ONLN
+      long cpuCount = sysconf(_SC_NPROCESSORS_ONLN) * 2;
+#else
+      long cpuCount = _config->FindI("Acquire::QueueHost::Limit",10);
+#endif
+      if (cpuCount > 0)
+         randomQueue %= cpuCount;
+
+      strprintf(FullQueueName, "%s%ld", AccessSchema.c_str(), randomQueue);
+      if (Debug) {
+         clog << "Chose random queue " << FullQueueName << " for " << Uri << endl;
+      }
+   } else
+   {
+      FullQueueName = AccessSchema + U.Host;
+   }
    unsigned int Instances = 0, SchemaLength = AccessSchema.length();
 
    Queue *I = Queues;