Issues (1956)

Branch: master

html/ops/batch_accel.php (1 issue)

Labels
Severity
1
#!/usr/bin/env php
2
<?php
3
// This file is part of BOINC.
4
// https://boinc.berkeley.edu
5
// Copyright (C) 2025 University of California
6
//
7
// BOINC is free software; you can redistribute it and/or modify it
8
// under the terms of the GNU Lesser General Public License
9
// as published by the Free Software Foundation,
10
// either version 3 of the License, or (at your option) any later version.
11
//
12
// BOINC is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
// See the GNU Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public License
18
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
19
20
// identify batches that are almost complete, and accelerate their completion
21
22
require_once('../inc/util.inc');
23
require_once('../inc/boinc_db.inc');
24
require_once('../inc/submit_db.inc');
25
require_once('../inc/submit_util.inc');
26
27
ini_set('display_errors', true);
0 ignored issues
show
true of type true is incompatible with the type string expected by parameter $value of ini_set(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
ini_set('display_errors', /** @scrutinizer ignore-type */ true);
Loading history...
28
29
// accelerate batches if at least this frac done
30
// can be set in project.inc
31
//
32
if (!defined('BATCH_ACCEL_MIN_FRAC_DONE')){
33
    define('BATCH_ACCEL_MIN_FRAC_DONE', .85);
34
}
35
36
$apps = [];
37
38
// batch is in-progress and at least 90% done; accelerate its remaining jobs
39
//
40
function do_batch($batch, $wus) {
41
    global $apps;
42
    $now = time();
43
    $app = $apps[$batch->app_id];
44
    if ($app->n_size_classes) {
45
        // app is accelerable; mark in-progress WUs as high priority
46
        //
47
        foreach ($wus as $wu) {
48
            if ($wu->canonical_resultid) {
49
                continue;
50
            }
51
            if ($wu->error_mask) {
52
                continue;
53
            }
54
            echo "accelerating WU $wu->id\n";
55
            $results = BoincResult::enum_fields(
56
                'id, server_state, sent_time, priority',
57
                "workunitid=$wu->id"
58
            );
59
            $make_another_result = false;
60
            if (count($results) < $wu->max_total_results) {
61
                $make_another_result = true;
62
                foreach ($results as $r) {
63
                    switch ($r->server_state) {
64
                    case RESULT_SERVER_STATE_UNSENT:
65
                        echo "   have unsent result $r->id\n";
66
                        $make_another_result = false;
67
                        if ($r->priority == 0) {
68
                            echo "   boosting its priority\n";
69
                            $r->update('priority=1');
70
                        } else {
71
                            echo "   already high priority\n";
72
                        }
73
                        break;
74
                    case RESULT_SERVER_STATE_IN_PROGRESS:
75
                        $age = $now - $r->sent_time;
76
                        if ($age<$batch->expire_time) {
77
                            echo "   have recent in-progress result\n";
78
                            $make_another_result = false;
79
                        }
80
                        break;
81
                    }
82
                }
83
            }
84
            $query = [];
85
            if ($make_another_result) {
86
                echo "   creating another instance\n";
87
                $query[] = sprintf(
88
                    'target_nresults=%d', $wu->target_nresults+1
89
                );
90
                $query[] = sprintf(
91
                    'transition_time=%f', $now
92
                );
93
            }
94
            if ($wu->priority == 0) {
95
                echo "   setting WU to high prio\n";
96
                $query[] = 'priority=1';
97
            }
98
            if ($query) {
99
                $query = implode(',', $query);
100
                BoincWorkunit::update_aux($query, "id=$wu->id");
101
            }
102
        }
103
    } else {
104
        // not accelerable; reset job priorities
105
        echo "batch is not accelerable; resetting job priorities\n";
106
        BoincWorkunit::update_aux(
107
            'priority=0',
108
            sprintf('batch=%d', $batch->id)
109
        );
110
        BoincResult::update_aux(
111
            'priority=0',
112
            sprintf('batch=%d', $batch->id)
113
        );
114
    }
115
}
116
117
function main() {
118
    global $apps;
119
120
    echo sprintf("starting batch_accel: %s\n", time_str(time()));
121
122
    $as = BoincApp::enum('');
123
    foreach ($as as $a) {
124
        $apps[$a->id] = $a;
125
    }
126
127
    $batches = BoincBatch::enum(
128
        sprintf('state=%d', BATCH_STATE_IN_PROGRESS)
129
    );
130
    foreach ($batches as $batch) {
131
        $wus = BoincWorkunit::enum_fields(
132
            'id, name, rsc_fpops_est, canonical_credit, canonical_resultid, error_mask, max_total_results, target_nresults, priority',
133
            "batch = $batch->id"
134
        );
135
        $batch = get_batch_params($batch, $wus);
136
        if ($batch->state != BATCH_STATE_IN_PROGRESS) {
137
            echo "batch $batch->id not in progress\n";
138
            continue;
139
        }
140
        if ($batch->fraction_done < BATCH_ACCEL_MIN_FRAC_DONE) {
141
            echo "batch $batch->id only $batch->fraction_done done\n";
142
            continue;
143
        }
144
        echo "doing batch $batch->id\n";
145
        do_batch($batch, $wus);
146
    }
147
    echo sprintf("finished batch_accel: %s\n", time_str(time()));
148
}
149
150
system("./batch_stats.php");
151
main();
152
153
?>
154