9 $analysisStatsAdaptor = $db_adaptor->get_AnalysisStatsAdaptor;
10 $analysisStatsAdaptor = $analysisStats->adaptor;
14 Module to encapsulate all db access
for persistent
class AnalysisStats.
15 There should be just one per application and database connection.
19 See the NOTICE file distributed with
this work
for additional information
20 regarding copyright ownership.
22 Licensed under the Apache License, Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
23 You may obtain a copy of the License at
27 Unless required by applicable law or agreed to in writing, software distributed under the License
28 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 See the License
for the specific language governing permissions and limitations under the License.
33 Please subscribe to the Hive mailing list: http:
37 The rest of the documentation details each of the
object methods.
38 Internal methods are usually preceded with a _
43 package Bio::EnsEMBL::Hive::DBSQL::AnalysisStatsAdaptor;
48 use base (
'Bio::EnsEMBL::Hive::DBSQL::ObjectAdaptor');
51 sub default_table_name {
52 return 'analysis_stats';
56 sub default_input_column_mapping {
59 'when_updated' => $self->dbc->_interval_seconds_sql(
'when_updated') .
' seconds_since_when_updated',
64 sub do_not_update_columns {
65 return [
'when_updated'];
70 return 'Bio::EnsEMBL::Hive::AnalysisStats';
74 sub objectify { # turn the hashref into an
object
75 my ($self, $hashref) = @_;
77 my $object = $self->SUPER::objectify( $hashref );
79 $object->seconds_since_last_fetch(0);
92 sub update_statistics {
93 my ($self, $stats) = @_;
95 my $sql =
"UPDATE analysis_stats SET status='".$stats->status.
"' ";
97 $sql .=
",avg_msec_per_job=" . $stats->avg_msec_per_job();
98 $sql .=
",avg_input_msec_per_job=" . $stats->avg_input_msec_per_job();
99 $sql .=
",avg_run_msec_per_job=" . $stats->avg_run_msec_per_job();
100 $sql .=
",avg_output_msec_per_job=" . $stats->avg_output_msec_per_job();
101 $sql .=
",is_excluded=" . $stats->is_excluded();
103 unless( $stats->hive_pipeline->hive_use_triggers() ) {
104 $sql .=
",total_job_count=" . $stats->total_job_count();
105 $sql .=
",semaphored_job_count=" . $stats->semaphored_job_count();
106 $sql .=
",ready_job_count=" . $stats->ready_job_count();
107 $sql .=
",done_job_count=" . $stats->done_job_count();
108 $sql .=
",failed_job_count=" . $stats->failed_job_count();
110 $stats->num_running_workers( $self->db->get_RoleAdaptor->count_active_roles( $stats->analysis_id() ) );
111 $sql .=
",num_running_workers=" . $stats->num_running_workers();
114 $sql .=
",when_updated=CURRENT_TIMESTAMP";
115 $sql .=
",sync_lock='0'";
116 $sql .=
" WHERE analysis_id='".$stats->analysis_id.
"' ";
118 my $sth = $self->prepare($sql);
121 $stats->seconds_since_when_updated(0); #not exact but good enough :)
126 my ($self, $analysis_id, $status) = @_;
128 my $sql =
"UPDATE analysis_stats SET status='$status' WHERE analysis_id='$analysis_id' ";
130 my $sth = $self->prepare($sql);
136 =head2 interval_update_work_done
138 Arg [1] :
int $analysis_id
139 Arg [2] :
int $jobs_done_in_interval
140 Arg [3] :
int $interval_msec
141 Arg [4] :
int $fetching_msec
142 Arg [5] :
int $running_msec
143 Arg [6] :
int $writing_msec
144 Arg [7] : real $weight_factor [optional]
145 Example : $statsDBA->interval_update_work_done($analysis_id, $jobs_done, $interval_msec, $fetching_msec, $running_msec, $writing_msec);
146 Description : does a database update to recalculate the avg_msec_per_job and done_job_count
147 does an interval equation by multiplying out the previous done_job_count with the
148 previous avg_msec_per_job and then expanding by
new interval values to give a better average.
153 sub interval_update_work_done {
154 my ($self, $analysis_id, $job_count, $interval_msec, $fetching_msec, $running_msec, $writing_msec, $weight_factor) = @_;
156 $weight_factor ||= 3; # makes it more sensitive to the dynamics of the farm
160 UPDATE analysis_stats SET
161 avg_msec_per_job = ROUND(((done_job_count*avg_msec_per_job)/$weight_factor + $interval_msec) / (done_job_count/$weight_factor + $job_count)),
162 avg_input_msec_per_job = ROUND(((done_job_count*avg_input_msec_per_job)/$weight_factor + $fetching_msec) / (done_job_count/$weight_factor + $job_count)),
163 avg_run_msec_per_job = ROUND(((done_job_count*avg_run_msec_per_job)/$weight_factor + $running_msec) / (done_job_count/$weight_factor + $job_count)),
164 avg_output_msec_per_job = ROUND(((done_job_count*avg_output_msec_per_job)/$weight_factor + $writing_msec) / (done_job_count/$weight_factor + $job_count))
165 WHERE analysis_id= $analysis_id
168 UPDATE analysis_stats SET
169 avg_msec_per_job = ROUND(((done_job_count*avg_msec_per_job)/$weight_factor + $interval_msec) / (done_job_count/$weight_factor + $job_count)),
170 avg_input_msec_per_job = ROUND(((done_job_count*avg_input_msec_per_job)/$weight_factor + $fetching_msec) / (done_job_count/$weight_factor + $job_count)),
171 avg_run_msec_per_job = ROUND(((done_job_count*avg_run_msec_per_job)/$weight_factor + $running_msec) / (done_job_count/$weight_factor + $job_count)),
172 avg_output_msec_per_job = ROUND(((done_job_count*avg_output_msec_per_job)/$weight_factor + $writing_msec) / (done_job_count/$weight_factor + $job_count)),
173 done_job_count = done_job_count + $job_count
174 WHERE analysis_id= $analysis_id
177 $self->dbc->do( $sql );
181 sub increment_a_counter {
182 my ($self, $counter, $increment, $analysis_id) = @_;
184 unless( $self->db->hive_pipeline->hive_use_triggers() ) {
185 if($increment) { # can either be positive or negative
186 ## ToDo: does it make sense to update the timestamp as well, to signal to the sync-allowed workers that they should wait?
187 # $self->dbc->do( "UPDATE analysis_stats SET $counter = $counter + ($increment), when_updated=CURRENT_TIMESTAMP WHERE sync_lock=0 AND analysis_id='$analysis_id'" );
188 $self->dbc->do(
"UPDATE analysis_stats SET $counter = $counter + ($increment) WHERE sync_lock=0 AND analysis_id='$analysis_id'" );