Skip to content

Commit

Permalink
Merge pull request #38 from artur-graniszewski/develop
Browse files Browse the repository at this point in the history
Release of 1.6.1
  • Loading branch information
artur-graniszewski committed Apr 11, 2017
2 parents e297929 + 96ee54e commit f09c6ad
Show file tree
Hide file tree
Showing 42 changed files with 466 additions and 801 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Changelog

## Version 1.6.1
- [Improvement] Major performance improvement in IPC adapters (up to 10x performance increase)
- [Improvement] Lots of code improvements based on static code analysis
- [Fix] Standardized behaviour of disconnect() method in all IPC adapters

## Version 1.6.0
- [Feature] Implemented new Async Server Service (Experimental)
- [Feature] Implemented `async()` ZF3 controller plugin that allows to execute multiple anonymous functions/closures asynchronously
Expand Down
82 changes: 1 addition & 81 deletions benchmarks/Ipc/ApcuIpcBenchmark.php
Expand Up @@ -2,89 +2,9 @@

namespace ZeusBench\Ipc;

use Athletic\AthleticEvent;
use Zend\Log\Logger;
use Zend\Log\Writer\Noop;
use Zeus\Kernel\IpcServer\Adapter\ApcAdapter;
use Zeus\Kernel\IpcServer\Adapter\IpcAdapterInterface;
use ZeusTest\Helpers\ZeusFactories;

class ApcuIpcBenchmark extends AthleticEvent
{
use ZeusFactories;

protected $largeMessage;

protected $mediumMessage;

protected $smallMessage;

protected $serviceManager;

/** @var IpcAdapterInterface */
protected $ipcAdapter;

public function __construct()
{
$logger = new Logger();
$logger->addWriter(new Noop());
$this->largeMessage = str_repeat('A', 65536);
$this->mediumMessage = str_repeat('A', 32768);
$this->smallMessage = str_repeat('A', 4096);
$this->serviceManager = $this->getServiceManager();
$this->ipcAdapter = $this->serviceManager->build(IpcAdapterInterface::class, ['logger_adapter' => $logger, 'ipc_adapter' => ApcAdapter::class, 'service_name' => 'zeus-test-' . md5(microtime(true))]);

$adapter = $this->ipcAdapter;
if (!$adapter->isSupported()) {
throw new \RuntimeException('The PHP configuration or OS system does not support ' . get_class($adapter));
}
$adapter->connect();
}

public function __destruct()
{
$this->ipcAdapter->disconnect();
}

/**
* @iterations 10000
*/
public function testSmallMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->smallMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->smallMessage) {
throw new \Exception('Small message is corrupted');
}
}

/**
* @iterations 10000
*/
public function testMediumMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->mediumMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->mediumMessage) {
throw new \Exception('Medium message is corrupted');
}
}

/**
* @iterations 10000
*/
public function testLargeMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->largeMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->largeMessage) {
throw new \Exception('Large message is corrupted');
}
}
protected $ipcAdapterName = ApcAdapter::class;
}
92 changes: 92 additions & 0 deletions benchmarks/Ipc/AthleticEvent.php
@@ -0,0 +1,92 @@
<?php

namespace ZeusBench\Ipc;

use Athletic\AthleticEvent as Event;
use Zend\Log\Logger;
use Zend\Log\Writer\Noop;
use Zeus\Kernel\IpcServer\Adapter\ApcAdapter;
use Zeus\Kernel\IpcServer\Adapter\IpcAdapterInterface;
use ZeusTest\Helpers\ZeusFactories;

class AthleticEvent extends Event
{
use ZeusFactories;

protected $largeMessage;

protected $mediumMessage;

protected $smallMessage;

protected $serviceManager;

/** @var IpcAdapterInterface */
protected $ipcAdapter;

protected $ipcAdapterName = ApcAdapter::class;

public function __construct()
{
$logger = new Logger();
$logger->addWriter(new Noop());
$this->largeMessage = str_repeat('A', 65536) . "\n";
$this->mediumMessage = str_repeat('A', 32768) . "\n";
$this->smallMessage = str_repeat('A', 4096) . "\n";
$this->serviceManager = $this->getServiceManager();
$this->ipcAdapter = $this->serviceManager->build(IpcAdapterInterface::class, ['logger_adapter' => $logger, 'ipc_adapter' => $this->ipcAdapterName, 'service_name' => 'zeus-test-' . md5(microtime(true))]);

$adapter = $this->ipcAdapter;
if (!$adapter->isSupported()) {
throw new \RuntimeException('The PHP configuration or OS system does not support ' . get_class($adapter));
}
$adapter->connect();
}

public function __destruct()
{
$this->ipcAdapter->disconnect();
}

/**
* @iterations 1000
*/
public function testSmallMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->smallMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->smallMessage) {
throw new \Exception('Small message is corrupted');
}
}

/**
* @iterations 1000
*/
public function testMediumMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->mediumMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->mediumMessage) {
throw new \Exception('Medium message is corrupted');
}
}

/**
* @iterations 1000
*/
public function testLargeMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->largeMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->largeMessage) {
throw new \Exception('Large message is corrupted');
}
}
}
80 changes: 2 additions & 78 deletions benchmarks/Ipc/FifoIpcBenchmark.php
Expand Up @@ -2,89 +2,13 @@

namespace ZeusBench\Ipc;

use Athletic\AthleticEvent;
use Zend\Log\Logger;
use Zend\Log\Writer\Noop;
use Zeus\Kernel\IpcServer\Adapter\FifoAdapter;
use Zeus\Kernel\IpcServer\Adapter\IpcAdapterInterface;
use ZeusTest\Helpers\ZeusFactories;

class FifoIpcBenchmark extends AthleticEvent
{
use ZeusFactories;
protected $ipcAdapterName = FifoAdapter::class;

protected $largeMessage;

protected $mediumMessage;

protected $smallMessage;

protected $serviceManager;

/** @var IpcAdapterInterface */
protected $ipcAdapter;

public function __construct()
{
$logger = new Logger();
$logger->addWriter(new Noop());
$this->largeMessage = str_repeat('A', 65536);
$this->mediumMessage = str_repeat('A', 32768);
$this->smallMessage = str_repeat('A', 4096);
$this->serviceManager = $this->getServiceManager();
$this->ipcAdapter = $this->serviceManager->build(IpcAdapterInterface::class, ['logger_adapter' => $logger, 'ipc_adapter' => FifoAdapter::class, 'service_name' => 'zeus-test-' . md5(microtime(true))]);

$adapter = $this->ipcAdapter;
if (!$adapter->isSupported()) {
throw new \RuntimeException('The PHP configuration or OS system does not support ' . get_class($adapter));
}
$adapter->connect();
}

public function __destruct()
{
$this->ipcAdapter->disconnect();
}

/**
* @iterations 10000
*/
public function testSmallMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->smallMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->smallMessage) {
throw new \Exception('Small message is corrupted');
}
}

/**
* @iterations 10000
*/
public function testMediumMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->mediumMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->mediumMessage) {
throw new \Exception('Medium message is corrupted: ' . $message);
}
}

/**
* iterations 1000
*/
private function testLargeMessage()
public function testLargeMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->largeMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->largeMessage) {
throw new \Exception('Large message is corrupted');
}
}
}
78 changes: 3 additions & 75 deletions benchmarks/Ipc/MsgIpcBenchmark.php
Expand Up @@ -2,89 +2,17 @@

namespace ZeusBench\Ipc;

use Athletic\AthleticEvent;
use Zend\Log\Logger;
use Zend\Log\Writer\Noop;
use Zeus\Kernel\IpcServer\Adapter\IpcAdapterInterface;
use Zeus\Kernel\IpcServer\Adapter\MsgAdapter;
use ZeusTest\Helpers\ZeusFactories;

class MsgIpcBenchmark extends AthleticEvent
{
use ZeusFactories;
protected $ipcAdapterName = MsgAdapter::class;

protected $largeMessage;

protected $mediumMessage;

protected $smallMessage;

protected $serviceManager;

/** @var IpcAdapterInterface */
protected $ipcAdapter;

public function __construct()
{
$logger = new Logger();
$logger->addWriter(new Noop());
$this->largeMessage = str_repeat('A', 65536);
$this->mediumMessage = str_repeat('A', 32768);
$this->smallMessage = str_repeat('A', 4096);
$this->serviceManager = $this->getServiceManager();
$this->ipcAdapter = $this->serviceManager->build(IpcAdapterInterface::class, ['logger_adapter' => $logger, 'ipc_adapter' => MsgAdapter::class, 'service_name' => 'zeus-test-' . md5(microtime(true))]);

$adapter = $this->ipcAdapter;
if (!$adapter->isSupported()) {
throw new \RuntimeException('The PHP configuration or OS system does not support ' . get_class($adapter));
}
$adapter->connect();
}

public function __destruct()
{
$this->ipcAdapter->disconnect();
}

/**
* @iterations 10000
*/
public function testSmallMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->smallMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->smallMessage) {
throw new \Exception('Small message is corrupted');
}
}

/**
* iterations 100
*/
private function testMediumMessage()
public function testMediumMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->mediumMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->mediumMessage) {
throw new \Exception('Medium message is corrupted');
}
}

/**
* iterations 100
*/
private function testLargeMessage()
public function testLargeMessage()
{
$this->ipcAdapter->useChannelNumber(0);
$this->ipcAdapter->send($this->largeMessage);
$this->ipcAdapter->useChannelNumber(1);
$message = $this->ipcAdapter->receive();
if ($message !== $this->largeMessage) {
throw new \Exception('Large message is corrupted');
}
}
}

0 comments on commit f09c6ad

Please sign in to comment.