Skip to content

Commit

Permalink
- client: clean up network suspension logic.
Browse files Browse the repository at this point in the history
    There are now separate flags for
    "file_xfers_suspended": don't do file transfers
    "network_suspended": don't do any network comm
        (scheduler RPCs, RSS fetch, master fetch, etc.)
    The policy:
    if preferences/settings say no network
    (quota exceeded, no-network mode, user active, time, excl. app)
    then:
        file_xfers_suspended = true
        if (no recent network-related RPC) network_suspended = true
- user web: code cleanup for project prefs

svn path=/trunk/boinc/; revision=21299
  • Loading branch information
davidpanderson committed Apr 26, 2010
1 parent 37f08f4 commit 26c0814
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 317 deletions.
21 changes: 21 additions & 0 deletions checkin_notes
Original file line number Diff line number Diff line change
Expand Up @@ -3171,3 +3171,24 @@ David 25 Apr 2010
html/inc/
prefs.inc
prefs_util.inc

David 26 Apr 2010
- client: clean up network suspension logic.
There are now separate flags for
"file_xfers_suspended": don't do file transfers
"network_suspended": don't do any network comm
(scheduler RPCs, RSS fetch, master fetch, etc.)
The policy:
if preferences/settings say no network
(quota exceeded, no-network mode, user active, time, excl. app)
then:
file_xfers_suspended = true
if (no recent network-related RPC) network_suspended = true
- user web: code cleanup for project prefs

client/
client_state.cpp,h
cs_prefs.pp
html/inc/
prefs.inc
prefs_util.inc
37 changes: 24 additions & 13 deletions client/client_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,22 +651,33 @@ bool CLIENT_STATE::poll_slow_events() {
cpu_benchmarks_poll();
}

network_suspend_reason = check_suspend_network();

// if a recent GUI RPC needs network access, allow it
//
if (gui_rpcs.recent_rpc_needs_network(300)) {
network_suspend_reason = 0;
}
int old_network_suspend_reason = network_suspend_reason;
bool old_network_suspended = network_suspended;
check_suspend_network();
if (network_suspend_reason) {
if (!network_suspended) {
suspend_network(network_suspend_reason);
network_suspended = true;
if (!old_network_suspend_reason) {
char buf[256];
if (network_suspended) {
sprintf(buf,
"Suspending network activity - %s",
suspend_reason_string(network_suspend_reason)
);
} else {
sprintf(buf,
"Suspending file transfers - %s",
suspend_reason_string(network_suspend_reason)
);
}
msg_printf(NULL, MSG_INFO, buf);
pers_file_xfers->suspend();
}
} else {
if (network_suspended) {
resume_network();
network_suspended = false;
if (old_network_suspend_reason) {
if (old_network_suspended) {
msg_printf(NULL, MSG_INFO, "Resuming network activity");
} else {
msg_printf(NULL, MSG_INFO, "Resuming file transfers");
}
}
}

Expand Down
19 changes: 13 additions & 6 deletions client/client_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ class CLIENT_STATE {
int pers_giveup;

bool tasks_suspended;
// Don't use CPU. See check_suspend_activities for logic
bool network_suspended;
// Don't use network. See check_suspend_network for logic
// Don't run apps.
int suspend_reason;

bool network_suspended;
// Don't use network.
bool file_xfers_suspended;
// Don't do file xfers (but allow other network activity).
int network_suspend_reason;

bool executing_as_daemon;
Expand Down Expand Up @@ -379,15 +382,14 @@ class CLIENT_STATE {
int allowed_project_disk_usage(double&);
int suspend_tasks(int reason);
int resume_tasks(int reason=0);
int suspend_network(int reason);
int resume_network();
void read_global_prefs();
int save_global_prefs(char* prefs, char* url, char* sched);
double available_ram();
double max_available_ram();
const char* suspend_reason_string(int reason);
private:
int check_suspend_processing();
int check_suspend_network();
void check_suspend_network();
void install_global_prefs();
PROJECT* global_prefs_source_project();
void show_global_prefs_source(bool);
Expand Down Expand Up @@ -536,6 +538,11 @@ extern void print_suspend_tasks_message(int);

#define CONNECT_ERROR_PERIOD 600.0

#define ALLOW_NETWORK_IF_RECENT_RPC_PERIOD 300
// if there has been a GUI RPC within this period
// that requires network access (e.g. attach to project)
// allow it even if setting is "no access"

#define DAILY_XFER_HISTORY_PERIOD 60

#define MAX_STD (86400)
Expand Down
1 change: 1 addition & 0 deletions client/cs_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ bool CLIENT_STATE::start_new_file_xfer(PERS_FILE_XFER& pfx) {
int ntotal=0, nproj=0;

if (network_suspended) return false;
if (file_xfers_suspended) return false;


// limit the number of file transfers per project
Expand Down
104 changes: 60 additions & 44 deletions client/cs_prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,26 +177,30 @@ int CLIENT_STATE::check_suspend_processing() {
return 0;
}

static string reason_string(int reason) {
const char* CLIENT_STATE::suspend_reason_string(int reason) {
switch (reason) {
case SUSPEND_REASON_BATTERIES: return " - on batteries";
case SUSPEND_REASON_USER_ACTIVE: return " - user is active";
case SUSPEND_REASON_USER_REQ: return " - user request";
case SUSPEND_REASON_TIME_OF_DAY: return " - time of day";
case SUSPEND_REASON_BENCHMARKS: return " - running CPU benchmarks";
case SUSPEND_REASON_DISK_SIZE: return " - out of disk space - change global prefs";
case SUSPEND_REASON_NO_RECENT_INPUT: return " - no recent user activity";
case SUSPEND_REASON_INITIAL_DELAY: return " - initial delay";
case SUSPEND_REASON_EXCLUSIVE_APP_RUNNING: return " - an exclusive app is running";
case SUSPEND_REASON_CPU_USAGE: return " - CPU usage is too high";
case SUSPEND_REASON_NETWORK_QUOTA_EXCEEDED: return " - network bandwidth limit exceeded";
case SUSPEND_REASON_BATTERIES: return "on batteries";
case SUSPEND_REASON_USER_ACTIVE: return "user is active";
case SUSPEND_REASON_USER_REQ: return "user request";
case SUSPEND_REASON_TIME_OF_DAY: return "time of day";
case SUSPEND_REASON_BENCHMARKS: return "running CPU benchmarks";
case SUSPEND_REASON_DISK_SIZE: return "out of disk space - change global prefs";
case SUSPEND_REASON_NO_RECENT_INPUT: return "no recent user activity";
case SUSPEND_REASON_INITIAL_DELAY: return "initial delay";
case SUSPEND_REASON_EXCLUSIVE_APP_RUNNING: return "an exclusive app is running";
case SUSPEND_REASON_CPU_USAGE: return "CPU usage is too high";
case SUSPEND_REASON_NETWORK_QUOTA_EXCEEDED: return "network bandwidth limit exceeded";
}
return "";
return "unknown reason";
}

void print_suspend_tasks_message(int reason) {
string s_reason = "Suspending computation" + reason_string(reason);
msg_printf(NULL, MSG_INFO, s_reason.c_str());
char buf[256];
sprintf(buf,
"Suspending computation - %s",
gstate.suspend_reason_string(reason)
);
msg_printf(NULL, MSG_INFO, buf);
}

int CLIENT_STATE::suspend_tasks(int reason) {
Expand Down Expand Up @@ -225,48 +229,60 @@ int CLIENT_STATE::resume_tasks(int reason) {
return 0;
}

int CLIENT_STATE::check_suspend_network() {
// Check whether to set network_suspended and file_xfers_suspended.
//
void CLIENT_STATE::check_suspend_network() {
network_suspended = false;
file_xfers_suspended = false;
network_suspend_reason = 0;

// no network traffic if we're allowing unsigned apps
//
if (unsigned_apps_ok) return SUSPEND_REASON_USER_REQ;

switch(network_mode.get_current()) {
case RUN_MODE_ALWAYS: return 0;
case RUN_MODE_NEVER:
return SUSPEND_REASON_USER_REQ;
}
if (!global_prefs.run_if_user_active && user_active) {
return SUSPEND_REASON_USER_ACTIVE;
}
if (global_prefs.net_times.suspended()) {
return SUSPEND_REASON_TIME_OF_DAY;
}
if (exclusive_app_running) {
return SUSPEND_REASON_EXCLUSIVE_APP_RUNNING;
if (unsigned_apps_ok) {
network_suspended = true;
file_xfers_suspended = true;
network_suspend_reason = SUSPEND_REASON_USER_REQ;
}

// was there a recent GUI RPC that needs network?
//
bool recent_rpc = gui_rpcs.recent_rpc_needs_network(
ALLOW_NETWORK_IF_RECENT_RPC_PERIOD
);

if (global_prefs.daily_xfer_limit_mb) {
double up, down;
daily_xfer_history.totals(
global_prefs.daily_xfer_period_days, up, down
);
if (up+down > global_prefs.daily_xfer_limit_mb*MEGA) {
return SUSPEND_REASON_NETWORK_QUOTA_EXCEEDED;
file_xfers_suspended = true;
if (!recent_rpc) network_suspended = true;
network_suspend_reason = SUSPEND_REASON_NETWORK_QUOTA_EXCEEDED;
}
}
return 0;
}

int CLIENT_STATE::suspend_network(int reason) {
string s_reason;
s_reason = "Suspending network activity" + reason_string(reason);
msg_printf(NULL, MSG_INFO, s_reason.c_str());
pers_file_xfers->suspend();
return 0;
}

int CLIENT_STATE::resume_network() {
msg_printf(NULL, MSG_INFO, "Resuming network activity");
return 0;
if (network_mode.get_current() == RUN_MODE_NEVER) {
file_xfers_suspended = true;
if (!recent_rpc) network_suspended = true;
network_suspend_reason = SUSPEND_REASON_USER_REQ;
}
if (!global_prefs.run_if_user_active && user_active) {
file_xfers_suspended = true;
if (!recent_rpc) network_suspended = true;
network_suspend_reason = SUSPEND_REASON_USER_ACTIVE;
}
if (global_prefs.net_times.suspended()) {
file_xfers_suspended = true;
if (!recent_rpc) network_suspended = true;
network_suspend_reason = SUSPEND_REASON_TIME_OF_DAY;
}
if (exclusive_app_running) {
file_xfers_suspended = true;
if (!recent_rpc) network_suspended = true;
network_suspend_reason = SUSPEND_REASON_EXCLUSIVE_APP_RUNNING;
}
}

// call this only after parsing global prefs
Expand Down
Loading

0 comments on commit 26c0814

Please sign in to comment.