From 7a289712546bc3ce935fd224d69e9670a5092bd3 Mon Sep 17 00:00:00 2001 From: Jimmy Au Date: Wed, 22 Apr 2015 15:24:15 +0800 Subject: [PATCH 1/3] Make worker count configurable --- DependencyInjection/Configuration.php | 1 + Services/RabbitMqSupervisor.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ca1e22a..8aa5ab9 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -51,6 +51,7 @@ protected function addPaths(ArrayNodeDefinition $node) ->scalarNode('worker_configuration_directory') ->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/worker/')->end() ->scalarNode('worker_output_log_file') ->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/logs/stdout.log')->end() ->scalarNode('worker_error_log_file') ->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/logs/stderr.log')->end() + ->scalarNode('worker_count') ->defaultValue(1)->end() ->end() ->end() ->end() diff --git a/Services/RabbitMqSupervisor.php b/Services/RabbitMqSupervisor.php index 4de36a7..bea158b 100644 --- a/Services/RabbitMqSupervisor.php +++ b/Services/RabbitMqSupervisor.php @@ -263,7 +263,7 @@ private function generateWorkerConfigurations($names, $command) 'kernelRootDir' => $this->kernelRootDir, 'workerOutputLog' => $this->paths['worker_output_log_file'], 'workerErrorLog' => $this->paths['worker_error_log_file'], - 'numprocs' => 1, + 'numprocs' => $this->paths['worker_count'], 'options' => array( 'startsecs' => '2', 'autorestart' => 'true', From faf8a9c47578470c9cd6d0d65c9d5bbee9ca6f0c Mon Sep 17 00:00:00 2001 From: Jimmy Au Date: Wed, 22 Apr 2015 15:33:40 +0800 Subject: [PATCH 2/3] Put worker count to root node --- DependencyInjection/Configuration.php | 2 +- Resources/config/services.yml | 1 + Services/RabbitMqSupervisor.php | 11 +++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 8aa5ab9..86217dd 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -22,6 +22,7 @@ public function getConfigTreeBuilder() $rootNode ->children() + ->scalarNode('worker_count')->defaultValue(1)->end() ->scalarNode('supervisor_instance_identifier')->defaultValue('symfony2')->end() ->end(); $this->addPaths($rootNode); @@ -51,7 +52,6 @@ protected function addPaths(ArrayNodeDefinition $node) ->scalarNode('worker_configuration_directory') ->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/worker/')->end() ->scalarNode('worker_output_log_file') ->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/logs/stdout.log')->end() ->scalarNode('worker_error_log_file') ->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/logs/stderr.log')->end() - ->scalarNode('worker_count') ->defaultValue(1)->end() ->end() ->end() ->end() diff --git a/Resources/config/services.yml b/Resources/config/services.yml index ab3d164..dedf636 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -13,6 +13,7 @@ services: - %phobetor_rabbitmq_supervisor.commands% - %phobetor_rabbitmq_supervisor.consumers% - %phobetor_rabbitmq_supervisor.multiple_consumers% + - %phobetor_rabbitmq_supervisor.worker_count% phobetor_rabbitmq_supervisor.supervisor_service: class: %phobetor_rabbitmq_supervisor.supervisor_service.class% diff --git a/Services/RabbitMqSupervisor.php b/Services/RabbitMqSupervisor.php index bea158b..f714f44 100644 --- a/Services/RabbitMqSupervisor.php +++ b/Services/RabbitMqSupervisor.php @@ -44,6 +44,11 @@ class RabbitMqSupervisor */ private $multipleConsumers; + /** + * @var int + */ + private $workerCount; + /** * Initialize Handler * @@ -54,8 +59,9 @@ class RabbitMqSupervisor * @param array $commands * @param array $consumers * @param array $multipleConsumers + * @param int $workerCount */ - public function __construct(Supervisor $supervisor, EngineInterface $templating, $kernelRootDir, array $paths, array $commands, $consumers, $multipleConsumers) + public function __construct(Supervisor $supervisor, EngineInterface $templating, $kernelRootDir, array $paths, array $commands, $consumers, $multipleConsumers, $workerCount) { $this->supervisor = $supervisor; $this->templating = $templating; @@ -64,6 +70,7 @@ public function __construct(Supervisor $supervisor, EngineInterface $templating, $this->commands = $commands; $this->consumers = $consumers; $this->multipleConsumers = $multipleConsumers; + $this->workerCount = $workerCount; } /** @@ -263,7 +270,7 @@ private function generateWorkerConfigurations($names, $command) 'kernelRootDir' => $this->kernelRootDir, 'workerOutputLog' => $this->paths['worker_output_log_file'], 'workerErrorLog' => $this->paths['worker_error_log_file'], - 'numprocs' => $this->paths['worker_count'], + 'numprocs' => $this->workerCount, 'options' => array( 'startsecs' => '2', 'autorestart' => 'true', From d9a5b075101db639f1f8eb24b6dfa96c0c13b107 Mon Sep 17 00:00:00 2001 From: Jimmy Au Date: Wed, 22 Apr 2015 15:37:54 +0800 Subject: [PATCH 3/3] Set config into container value --- DependencyInjection/RabbitMqSupervisorExtension.php | 1 + 1 file changed, 1 insertion(+) diff --git a/DependencyInjection/RabbitMqSupervisorExtension.php b/DependencyInjection/RabbitMqSupervisorExtension.php index d6ef37d..4012d1b 100644 --- a/DependencyInjection/RabbitMqSupervisorExtension.php +++ b/DependencyInjection/RabbitMqSupervisorExtension.php @@ -24,6 +24,7 @@ public function load(array $configs, ContainerBuilder $container) $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); + $container->setParameter('phobetor_rabbitmq_supervisor.worker_count', $config['worker_count']); $container->setParameter('phobetor_rabbitmq_supervisor.supervisor_instance_identifier', $config['supervisor_instance_identifier']); $container->setParameter('phobetor_rabbitmq_supervisor.paths', $config['paths']); $container->setParameter('phobetor_rabbitmq_supervisor.workspace', $config['paths']['workspace_directory']);