Commit 69e94449 authored by Leo Gordon's avatar Leo Gordon
Browse files

moved Q:get_hive_current_load --> RA:Q:get_hive_current_load

parent 61421dcf
......@@ -76,5 +76,24 @@ sub fetch_last_by_worker_id {
return $self->fetch_all( "WHERE worker_id=$worker_id ORDER BY when_started DESC LIMIT 1", 1 );
}
sub get_hive_current_load {
my $self = shift;
my $sql = qq{
SELECT sum(1/hive_capacity)
FROM role
JOIN analysis_stats USING(analysis_id)
WHERE when_finished IS NULL
AND hive_capacity IS NOT NULL
AND hive_capacity>0
};
my $sth = $self->prepare($sql);
$sth->execute();
my ($current_load)=$sth->fetchrow_array();
$sth->finish;
return ($current_load || 0);
}
1;
......@@ -260,7 +260,7 @@ sub specialize_new_worker {
$self->safe_synchronize_AnalysisStats($stats);
unless($special_batch or $force) { # do we really need to run this analysis?
if($self->get_hive_current_load() >= 1.1) {
if($self->db->get_RoleAdaptor->get_hive_current_load() >= 1.1) {
$worker->cause_of_death('HIVE_OVERLOAD');
die "Hive is overloaded, can't specialize a worker";
}
......@@ -667,24 +667,6 @@ sub get_num_failed_analyses {
}
sub get_hive_current_load {
my $self = shift;
my $sql = qq{
SELECT sum(1/hive_capacity)
FROM worker w
JOIN analysis_stats USING(analysis_id)
WHERE w.status!='DEAD'
AND hive_capacity IS NOT NULL
AND hive_capacity>0
};
my $sth = $self->prepare($sql);
$sth->execute();
my ($load)=$sth->fetchrow_array();
$sth->finish;
return ($load || 0);
}
sub count_running_workers {
my ($self, $analysis_id) = @_;
......
......@@ -130,7 +130,7 @@ sub schedule_workers {
my $log_buffer = '';
my $submit_capacity_limiter = Bio::EnsEMBL::Hive::Limiter->new( 'Max number of Workers scheduled this time', $submit_capacity );
my $queen_capacity_limiter = Bio::EnsEMBL::Hive::Limiter->new( 'Total reciprocal capacity of the Hive', 1.0 - $queen->get_hive_current_load() );
my $queen_capacity_limiter = Bio::EnsEMBL::Hive::Limiter->new( 'Total reciprocal capacity of the Hive', 1.0 - $queen->db->get_RoleAdaptor->get_hive_current_load() );
foreach my $analysis_stats (@suitable_analyses_stats) {
last if( $submit_capacity_limiter->reached );
......
......@@ -544,7 +544,7 @@ sub run {
if (!$self->cause_of_death) {
my $analysis = $self->current_role->analysis;
my $stats = $analysis->stats; # make sure it is fresh from the DB
if( defined($stats->hive_capacity) && (0 <= $stats->hive_capacity) && ($self->adaptor->get_hive_current_load >= 1.1)
if( defined($stats->hive_capacity) && (0 <= $stats->hive_capacity) && ($self->adaptor->db->get_RoleAdaptor->get_hive_current_load >= 1.1)
or defined($analysis->analysis_capacity) && (0 <= $analysis->analysis_capacity) && ($analysis->analysis_capacity < $stats->num_running_workers)
) {
$self->cause_of_death('HIVE_OVERLOAD');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment