Skip to content

Commit

Permalink
Merge pull request #27 from artur-graniszewski/develop
Browse files Browse the repository at this point in the history
Release of 1.3.4
  • Loading branch information
artur-graniszewski committed Mar 13, 2017
2 parents 3798efd + 458597f commit 07de1f8
Show file tree
Hide file tree
Showing 20 changed files with 453 additions and 238 deletions.
31 changes: 29 additions & 2 deletions README.md
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/artur-graniszewski/ZEUS-for-PHP.svg?branch=master)](https://travis-ci.org/artur-graniszewski/ZEUS-for-PHP) [![Coverage Status](https://coveralls.io/repos/github/artur-graniszewski/ZEUS-for-PHP/badge.svg?branch=master)](https://coveralls.io/github/artur-graniszewski/ZEUS-for-PHP?branch=master)
[![Build Status](https://travis-ci.org/artur-graniszewski/ZEUS-for-PHP.svg?branch=master)](https://travis-ci.org/artur-graniszewski/ZEUS-for-PHP) [![Coverage Status](https://coveralls.io/repos/github/artur-graniszewski/ZEUS-for-PHP/badge.svg?branch=master)](https://coveralls.io/github/artur-graniszewski/ZEUS-for-PHP?branch=master) [![Code Climate](https://codeclimate.com/github/artur-graniszewski/ZEUS-for-PHP/badges/gpa.svg)](https://codeclimate.com/github/artur-graniszewski/ZEUS-for-PHP)

# Introduction

Expand Down Expand Up @@ -144,10 +144,20 @@ Scheduler is responsible for:

- running _Server Services_ in parallel using __preemptive multitasking__
- supporting custom _Multi-Processing Modules_
- managing the number of processes based on a Task-Pool strategy
- managing the number of processes based on a Task-Pool strategy and Scheduler Disciplines
- handling Process lifecycle
- keeping track of and reporting Process state

#### Scheduler Disciplines

In ZEUS, scheduling disciplines are algorithms used for distributing hardware resources (such as CPU time or memory) among Scheduler processes.

The main purpose of scheduling algorithms is to minimize resource starvation by creating or termination of processes to keep number of active processes within the boundaries specified by Scheduler configuration.
Some algorithms may focus on termination of processes that were idle for too long, while other may terminate processes based on their actual memory footprint or a number of requests that they already processed.

> Since version 1.3.4, Schedulers can be configured to use custom `\Zeus\Kernel\ProcessManager\Scheduler\Discipline\DisciplineInterface` implementations.
> **If no such implementation is specified, ZEUS defaults to a built-in _LRU (Least Recently Used) Discipline_.**
#### Multi-Processing Modules

Certain multitasking architectures are incompatible or not efficient enough on different operating systems. To remedy this issue, ZEUS provides a Multi-Processing Module interface between an application and the underlying operating system that is designed to hide these differences by providing a consistent platform on which the application is run.
Expand Down Expand Up @@ -243,11 +253,15 @@ Multiple _Process Schedulers_ can be configured in a regular Zend Framework 3 co
```php
// contents of "zf3-application-directory/config/some-config.config.php" file:

use Zeus\Kernel\ProcessManager\MultiProcessingModule\PosixProcess;
use Zeus\Kernel\ProcessManager\Scheduler\Discipline\LruDiscipline;

return [
'zeus_process_manager' => [
'schedulers' => [
'scheduler_1' => [
'scheduler_name' => 'sample_scheduler',
'scheduler_discipline' => LruDiscipline::class, // choice available since version 1.3.4
'multiprocessing_module' => PosixProcess::class,
'max_processes' => 32,
'max_process_tasks' => 100,
Expand All @@ -266,6 +280,7 @@ The table below describes the configuration parameters:
| Parameter | Required | Description |
|------------------------|:--------:|---------------------------------------------------------------------------------------|
| scheduler_name | yes | Unique name of the scheduler configuration |
| scheduler_discipline | no | Zend Framework service providing Scheduler's process management strategy |
| multiprocessing_module | yes | Specifies a `MultiProcessingModuleInterface` implementation to be used in a Scheduler |
| start_processes | yes | Specifies the number of processes that will initially launch with each Server Service |
| max_processes | yes | Maximum number of running/waiting processes of each Server Service |
Expand All @@ -283,6 +298,8 @@ Multiple _Server Services_ can be configured in a regular Zend Framework 3 confi
```php
// contents of "zf3-application-directory/config/some-config.config.php" file:

use Zeus\ServerService\Shared\Logger\LoggerInterface;

return [
'zeus_process_manager' => [
'services' => [
Expand Down Expand Up @@ -358,6 +375,9 @@ Each service must be listed in the `services` section of `zeus_process_manager`
```php
// contents of "zf3-application-directory/config/some-config.config.php" file:

use Zeus\ServerService\Shared\Logger\LoggerInterface;
use Zeus\Kernel\ProcessManager\MultiProcessingModule\PosixProcess;

return [
'zeus_process_manager' => [
'services' => [
Expand Down Expand Up @@ -441,6 +461,13 @@ The above configuration parameters have been described in the __Process Schedule

# Changelog

## Version 1.3.4
- [Feature] Implemented Scheduler Disciplines functionality
- [Feature] Extracted LRU Discipline from Scheduler core
- [Fix] Scheduler was too aggressive in its calculations of number of spare processes to create
- [Fix] Documentation fixes (added missing namespaces in configuration examples)
- [Tests improvements] Improved code coverage

## Version 1.3.3
- [Tests improvements] Improved code coverage
- [Improvement] Documentation improvements and enhancements
Expand Down
4 changes: 4 additions & 0 deletions config/module.config.php
Expand Up @@ -12,6 +12,8 @@
use Zeus\Kernel\ProcessManager\Factory\ManagerFactory;
use Zeus\Kernel\ProcessManager\Factory\SchedulerFactory;
use Zeus\Kernel\ProcessManager\Factory\ProcessFactory;
use Zeus\Kernel\ProcessManager\Scheduler\Discipline\Factory\LruDisciplineFactory;
use Zeus\Kernel\ProcessManager\Scheduler\Discipline\LruDiscipline;
use Zeus\ServerService\Manager;
use Zeus\Kernel\ProcessManager\Scheduler;
use Zeus\Kernel\ProcessManager\Process;
Expand Down Expand Up @@ -44,6 +46,7 @@
Process::class => ProcessFactory::class,
Manager::class => ManagerFactory::class,
PosixProcess::class => PosixProcessFactory::class,
LruDiscipline::class => LruDisciplineFactory::class,
//Service::class => ServiceFactory::class,
],
'abstract_factories' => [
Expand All @@ -56,6 +59,7 @@
'zeus_web_scheduler_1' => [
'scheduler_name' => 'zeus_web_scheduler',
'multiprocessing_module' => PosixProcess::class,
'scheduler_discipline' => LruDiscipline::class,
'max_processes' => 32,
'max_process_tasks' => 100,
'min_spare_processes' => 3,
Expand Down
5 changes: 4 additions & 1 deletion src/Zeus/Kernel/ProcessManager/Factory/SchedulerFactory.php
Expand Up @@ -9,6 +9,7 @@
use Zend\ServiceManager\Factory\FactoryInterface;
use Zeus\Kernel\ProcessManager\Scheduler;
use Zeus\Kernel\ProcessManager\Process;
use Zeus\Kernel\ProcessManager\Scheduler\Discipline\LruDiscipline;
use Zeus\Kernel\ProcessManager\SchedulerEvent;
use Zeus\ServerService\Shared\Logger\LoggerInterface;

Expand All @@ -35,10 +36,12 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o

$serviceLoggerAdapter = $options['service_logger_adapter'];
$mainLoggerAdapter = $options['main_logger_adapter'];
$schedulerDiscipline =
isset($schedulerConfig['scheduler_discipline']) ? $container->get($schedulerConfig['scheduler_discipline']) : $container->get(LruDiscipline::class);

$processService = $container->build(Process::class, ['logger_adapter' => $serviceLoggerAdapter, 'process_event' => $schedulerEvent]);

$scheduler = new Scheduler($schedulerConfig, $processService, $mainLoggerAdapter, $options['ipc_adapter'], $schedulerEvent);
$scheduler = new Scheduler($schedulerConfig, $processService, $mainLoggerAdapter, $options['ipc_adapter'], $schedulerEvent, $schedulerDiscipline);
$container->build($schedulerConfig['multiprocessing_module'], ['scheduler' => $scheduler, 'scheduler_event' => $schedulerEvent]);

return $scheduler;
Expand Down
Expand Up @@ -24,9 +24,6 @@ final class PosixProcess implements MultiProcessingModuleInterface
/** @var SchedulerEvent */
protected $processEvent;

/** @var bool|null */
private static $isPcntlExtensionLoaded = null;

/** @var PosixProcessBridgeInterface */
protected static $pcntlBridge;

Expand Down Expand Up @@ -108,7 +105,7 @@ public static function isSupported($throwException = false)
*/
public function onProcessTerminate(EventInterface $event)
{
$this->terminateTask($event->getParam('uid'), $event->getParam('soft'));
$this->terminateProcess($event->getParam('uid'), $event->getParam('soft'));
}

/**
Expand Down Expand Up @@ -225,7 +222,7 @@ public function onSchedulerInit()
* @param bool|false $useSoftTermination
* @return $this
*/
protected function terminateTask($pid, $useSoftTermination = false)
protected function terminateProcess($pid, $useSoftTermination = false)
{
$this->getPcntlBridge()->posixKill($pid, $useSoftTermination ? SIGINT : SIGKILL);

Expand All @@ -236,9 +233,9 @@ protected function terminateTask($pid, $useSoftTermination = false)
* @param bool|false $useSoftTermination
* @return $this
*/
public function terminateAllTasks($useSoftTermination = false)
public function terminateAllProcesses($useSoftTermination = false)
{
return $this->terminateTask(0, $useSoftTermination);
return $this->terminateProcess(0, $useSoftTermination);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Zeus/Kernel/ProcessManager/Process.php
Expand Up @@ -18,7 +18,7 @@ final class Process
protected $status;

/** @var string */
protected $id;
protected $processId;

/** @var EventManagerInterface */
protected $events;
Expand All @@ -30,12 +30,12 @@ final class Process
protected $event;

/**
* @param string $uid
* @param string $processId
* @return $this
*/
public function setId($uid)
public function setId($processId)
{
$this->id = $uid;
$this->processId = $processId;

return $this;
}
Expand Down Expand Up @@ -241,7 +241,7 @@ public function mainLoop()
*/
public function getId()
{
return $this->id;
return $this->processId;
}

/**
Expand Down

0 comments on commit 07de1f8

Please sign in to comment.