Skip to content

Commit

Permalink
fix: limit workers to max 60 on MSWin32 for Parallel::ForkManager
Browse files Browse the repository at this point in the history
  • Loading branch information
g-bougard committed Jan 15, 2024
1 parent fb71334 commit 2ce3017
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Revision history for GLPI agent

1.8 not yet released

core:
* Parallel::ForkManager must not use more than 60 workers on MSWin32 due to a
perl limitation on this operating system

inventory:
* Fix network default route discovery on linux
* Fix virtualmachine inventory on computer providing vmware-cmd command
Expand Down
2 changes: 1 addition & 1 deletion lib/GLPI/Agent/HTTP/Server/ToolBox/Remotes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ sub _submit_start {
my $logger = $self->{logger};
my $starttime = gettimeofday();

# Configure agent to use required workes and only process expired remotes
# Configure agent to use required workers and only process expired remotes
$agent->{config}->{'remote-workers'} = $workers || 1;
$agent->{config}->{'remote-scheduling'} = 1;

Expand Down
6 changes: 6 additions & 0 deletions lib/GLPI/Agent/Task/Deploy/P2P.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ sub new {
p2pnet => {}
};

# On windows, max_workers should not be bigger than 60 due to a perl limitation
if ($OSNAME eq 'MSWin32' && $self->{max_workers} > 60) {
$self->{logger}->info("Limiting workers from $self->{max_workers} to 60 on MSWin32");
$self->{max_workers} = 60;
}

bless $self, $class;

return $self;
Expand Down
6 changes: 6 additions & 0 deletions lib/GLPI/Agent/Task/NetDiscovery.pm
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ sub run {
my ($max_threads) = sort { $b <=> $a } map { int($_->max_threads()) }
@{$self->{jobs}};

# On windows, max_threads should not be upper than 60 due to a perl limitation
if ($OSNAME eq 'MSWin32' && $max_threads > 60) {
$self->{logger}->info("Limiting threads from $max_threads to 60 on MSWin32");
$max_threads = 60;
}

# Prepare fork manager
my $tempdir = $self->{target}->getStorage()->getDirectory();
mkpath($tempdir);
Expand Down
6 changes: 6 additions & 0 deletions lib/GLPI/Agent/Task/NetInventory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ sub run {
my ($max_threads) = sort { $b <=> $a } map { int($_->max_threads()) }
@{$self->{jobs}};

# On windows, max_threads should not be upper than 60 due to a perl limitation
if ($OSNAME eq 'MSWin32' && $max_threads > 60) {
$self->{logger}->info("Limiting threads from $max_threads to 60 on MSWin32");
$max_threads = 60;
}

# count devices and check skip_start_stop
my $devices_count = 0;
my $skip_start_stop = 0;
Expand Down
7 changes: 7 additions & 0 deletions lib/GLPI/Agent/Task/RemoteInventory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;

use parent 'GLPI::Agent::Task::Inventory';

use English qw(-no_match_vars);
use Parallel::ForkManager;

use GLPI::Agent::Tools;
Expand Down Expand Up @@ -49,6 +50,12 @@ sub run {

my $worker_count = $remotes->count() > 1 ? $self->{config}->{'remote-workers'} : 0;

# On windows, worker_count should not be upper than 60 due to a perl limitation
if ($OSNAME eq 'MSWin32' && $worker_count > 60) {
$self->{logger}->info("Limiting workers count from $worker_count to 60 on MSWin32");
$worker_count = 60;
}

my $start = time;

my $manager = Parallel::ForkManager->new($worker_count);
Expand Down

0 comments on commit 2ce3017

Please sign in to comment.