From 4d47e2f170ae638a0121c4a31cc4a9f54a75848a Mon Sep 17 00:00:00 2001
From: David Anderson <davea@ssl.berkeley.edu>
Date: Sun, 7 Jul 2013 13:13:57 -0700
Subject: [PATCH] client: don't request work from a project w/ > 1000 runnable
 jobs

Because of O(N^2) algorithms, the client becomes CPU-intensive
when there are lots of jobs.
This limit could be somewhat lower.
---
 client/work_fetch.cpp             | 10 ++++++++++
 client/work_fetch.h               |  3 +++
 clientgui/CompletionErrorPage.cpp |  2 +-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/client/work_fetch.cpp b/client/work_fetch.cpp
index a94779ff7c..27455546ea 100644
--- a/client/work_fetch.cpp
+++ b/client/work_fetch.cpp
@@ -664,6 +664,16 @@ void WORK_FETCH::setup() {
         PROJECT* p = rp->project;
         p->sched_priority -= rp->estimated_flops_remaining()/max_queued_flops;
     }
+
+    // don't request work from projects w/ > 1000 runnable jobs
+    //
+    for (unsigned int i=0; i<gstate.projects.size(); i++) {
+        PROJECT* p = gstate.projects[i];
+        if (p->pwf.n_runnable_jobs > 1000 && !p->pwf.cant_fetch_work_reason) {
+            p->pwf.cant_fetch_work_reason = CANT_FETCH_WORK_TOO_MANY_RUNNABLE;
+        }
+    }
+
     std::sort(
         gstate.projects.begin(),
         gstate.projects.end(),
diff --git a/client/work_fetch.h b/client/work_fetch.h
index a3a0ce7b60..4390b9a551 100644
--- a/client/work_fetch.h
+++ b/client/work_fetch.h
@@ -39,6 +39,7 @@
 #define CANT_FETCH_WORK_TOO_MANY_UPLOADS            8
 #define CANT_FETCH_WORK_NOT_HIGHEST_PRIORITY        9
 #define CANT_FETCH_WORK_DONT_NEED                   10
+#define CANT_FETCH_WORK_TOO_MANY_RUNNABLE           11
 
 inline const char* cant_fetch_work_string(int reason) {
     switch (reason) {
@@ -62,6 +63,8 @@ inline const char* cant_fetch_work_string(int reason) {
         return "project is not highest priority";
     case CANT_FETCH_WORK_DONT_NEED:
         return "don't need";
+    case CANT_FETCH_WORK_TOO_MANY_RUNNABLE:
+        return "too many runnable tasks";
     }
     return "";
 }
diff --git a/clientgui/CompletionErrorPage.cpp b/clientgui/CompletionErrorPage.cpp
index 75e4194c0f..a9f4875ea5 100644
--- a/clientgui/CompletionErrorPage.cpp
+++ b/clientgui/CompletionErrorPage.cpp
@@ -218,7 +218,7 @@ void CCompletionErrorPage::OnPageChanged( wxWizardExEvent& event ) {
 
     if (m_pServerMessagesCtrl->GetLabel().IsEmpty()) {
         m_pDirectionsStaticCtrl->SetLabel(
-            _("An error has occurred;\ncheck the Event Log for details.\n\nClick Finish to close.")
+            _("Please try again later.\n\nClick Finish to close.")
         );
     } else {
         m_pDirectionsStaticCtrl->SetLabel(
-- 
GitLab