Skip to content

Commit 0439293

Browse files
authored
Merge pull request #6894 from BOINC/dpa_submit60
batch acceleration: make it work for small batches
2 parents 92a3ec3 + 9cd217f commit 0439293

3 files changed

Lines changed: 47 additions & 16 deletions

File tree

html/ops/batch_accel.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
1919

2020
// identify batches that are almost complete, and accelerate their completion
21+
// We first run 'batch_stats.php', which computes needed data:
22+
// LTT hosts, accelerable batches, median TT of batches
2123

2224
require_once('../inc/util.inc');
2325
require_once('../inc/boinc_db.inc');
@@ -26,16 +28,30 @@
2628

2729
ini_set('display_errors', true);
2830

29-
// accelerate batches if at least this frac done
30-
// can be set in project.inc
31+
// the following can be set in project.inc
3132
//
32-
if (!defined('BATCH_ACCEL_MIN_FRAC_DONE')){
33-
define('BATCH_ACCEL_MIN_FRAC_DONE', .85);
33+
// accelerate a batch if at least this frac of jobs are done (success or fail)
34+
// This value is a guess; it may not be optimal.
35+
// If too low, extra instances are created, reducing throughput.
36+
// If too high, batches take longer to finish.
37+
//
38+
if (!defined('BATCH_ACCEL_MIN_FRAC_DONE')) {
39+
define('BATCH_ACCEL_MIN_FRAC_DONE', 0.85);
40+
}
41+
42+
// accelerate a batch if the number of 'not done' jobs
43+
// (i.e. unsent or in progress) is less than this.
44+
// This helps small batches get done quicker
45+
//
46+
if (!defined('BATCH_ACCEL_MAX_NOT_DONE')) {
47+
define('BATCH_ACCEL_MAX_NOT_DONE', 20);
3448
}
3549

3650
$apps = [];
3751

38-
// batch is in-progress and at least 90% done; accelerate its remaining jobs
52+
// batch is in-progress and qualifies for acceleration (see above);
53+
// accelerate its remaining jobs by marking them as high-priority
54+
// and possibly creating a new instance
3955
//
4056
function do_batch($batch, $wus) {
4157
global $apps;
@@ -78,7 +94,7 @@ function do_batch($batch, $wus) {
7894
break;
7995
case RESULT_SERVER_STATE_IN_PROGRESS:
8096
$age = $now - $r->sent_time;
81-
if ($age<$batch->expire_time) {
97+
if ($age < $batch->expire_time) {
8298
echo " have recent in-progress result $r->id\n";
8399
$make_another_result = false;
84100
}
@@ -145,12 +161,16 @@ function main() {
145161
echo "batch $batch->id not in progress\n";
146162
continue;
147163
}
148-
if ($batch->fraction_done < BATCH_ACCEL_MIN_FRAC_DONE) {
149-
echo "batch $batch->id only $batch->fraction_done done\n";
150-
continue;
164+
$n_done = $batch->njobs_success + $batch->nerror_jobs;
165+
$n_not_done = count($wus) - $n_done;
166+
if ($batch->fraction_done > BATCH_ACCEL_MIN_FRAC_DONE
167+
|| $n_not_done < BATCH_ACCEL_MAX_NOT_DONE
168+
) {
169+
echo "doing batch $batch->id\n";
170+
do_batch($batch, $wus);
171+
} else {
172+
echo "not doing batch $batch->id: $batch->fraction_done done\n";
151173
}
152-
echo "doing batch $batch->id\n";
153-
do_batch($batch, $wus);
154174
}
155175
echo sprintf("finished batch_accel: %s\n", time_str(time()));
156176
}

html/ops/batch_stats.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
1919
// process turnaround time stats files
2020

21-
// compute stats for batch acceleration
21+
// compute stats for batch acceleration, and update the DB accordingly
2222
//
2323
// - classify hosts as low turnaround time (LTT)
2424
// host.error_rate = 1

html/user/get_output3.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
// user is allowed to download output files from batch only if
3939
// they own batch or have manage-all permissions
4040
//
41-
function check_auth($batch_id){
41+
function check_auth($batch_id) {
4242
$user = get_logged_in_user();
4343
if (has_manage_access($user, 0)) {
4444
return;
@@ -86,7 +86,7 @@ function get_batch_zip() {
8686
check_auth($batch_id);
8787
$dir = "../../results/$batch_id";
8888
if (!is_dir($dir)) {
89-
die('no batch dir');
89+
error_page('no batch dir');
9090
}
9191
$name = "batch_$batch_id.zip";
9292
$cmd = "cd $dir; rm -f $name; zip -q $name *";
@@ -103,7 +103,17 @@ function get_batch_tar() {
103103
check_auth($batch_id);
104104
$dir = "../../results/$batch_id";
105105
if (!is_dir($dir)) {
106-
die('no batch dir');
106+
error_page('no batch dir');
107+
}
108+
109+
$d = fopen($dir, 'r');
110+
if (!$d) {
111+
error_page('fopen() failed');
112+
}
113+
if (!flock($d, LOCK_EX|LOCK_NB)) {
114+
error_page(
115+
"A download of this batch is already in progress."
116+
);
107117
}
108118

109119
// get the size of the tar file (fast - doesn't read files)
@@ -124,7 +134,7 @@ function get_batch_tar() {
124134
}
125135
}
126136
if ($nbytes<0) {
127-
error_page('tar --totals didn't produce result');
137+
error_page("tar --totals didn't produce result");
128138
}
129139
pclose($f);
130140

@@ -146,6 +156,7 @@ function get_batch_tar() {
146156
flush();
147157
}
148158
pclose($f);
159+
fclose($d);
149160
}
150161

151162
$action = get_str('action');

0 commit comments

Comments
 (0)