Implemented Redis Server controller

This commit is contained in:
Netkas 2023-06-10 01:46:34 -04:00
parent 40bb5e29d0
commit 0c23fdfac2
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
34 changed files with 226 additions and 3955 deletions

View file

@ -1,30 +0,0 @@
<?php
// Pi function (closure) loop 10 times
for ($i = 0; $i < 50; $i++)
{
$start = microtime(true);
$pi = 0;
$top = 4;
$bot = 1;
$minus = true;
$iterations = 1000000;
for ($i = 0; $i < $iterations; $i++)
{
if ($minus)
{
$pi = $pi - ($top / $bot);
$minus = false;
}
else
{
$pi = $pi + ($top / $bot);
$minus = true;
}
$bot += 2;
}
}

18
tests/redis_server.php Normal file
View file

@ -0,0 +1,18 @@
<?php
require 'ncc';
import('net.nosial.tamerlib');
$redis_server = new \TamerLib\Classes\RedisServer();
$redis_server->start();
$redis_client = new \Redis();
$redis_client->connect('127.0.0.1', $redis_server->getPort());
$redis_client->set('foo', 'bar');
$value = $redis_client->get('foo');
echo $value . PHP_EOL;
$redis_client->close();
$redis_server->stop();

View file

@ -1,71 +0,0 @@
<?php
use TamerLib\Abstracts\ProtocolType;
use TamerLib\Tamer;
require 'ncc';
import('net.nosial.tamerlib', 'latest');
Tamer::init(ProtocolType::Gearman,
['127.0.0.1:4730']
//['127.0.0.1:5672'], 'guest', 'guest'
);
$instances = 10;
Tamer::addWorker('closure', $instances);
Tamer::startWorkers();
$a = microtime(true);
$times = [];
$jobs = 30;
// Pi function (closure) loop 10 times
for ($i = 0; $i < $jobs; $i++)
{
Tamer::queueClosure(function(){
// Full pi calculation implementation
$start = microtime(true);
$pi = 0;
$top = 4;
$bot = 1;
$minus = true;
$iterations = 1000000;
for ($i = 0; $i < $iterations; $i++)
{
if ($minus)
{
$pi = $pi - ($top / $bot);
$minus = false;
}
else
{
$pi = $pi + ($top / $bot);
$minus = true;
}
$bot += 2;
}
return json_encode([$pi, $start]);
},
function($return) use ($a, &$times)
{
$return = json_decode($return, true);
$end_time = microtime(true) - $return[1];
$times[] = $end_time;
echo "Pi is {$return[0]}, completed in " . ($end_time) . " seconds \n";
});
}
echo "Waiting for $jobs jobs to finish on $instances workers \n";
Tamer::run();
$b = microtime(true);
echo PHP_EOL;
echo "Average time: " . (array_sum($times) / count($times)) . " seconds \n";
echo "Took (with tamer)" . ($b - $a) . " seconds \n";
echo "Total time (without tamer): " . (array_sum($times)) . " seconds \n";
echo "Tamer overhead: " . (($b - $a) - array_sum($times)) . " seconds \n";

View file

@ -1,33 +0,0 @@
<?php
use TamerLib\Abstracts\ProtocolType;
use TamerLib\Objects\JobResults;
use TamerLib\Objects\Task;
use TamerLib\Tamer;
require 'ncc';
import('net.nosial.tamerlib', 'latest');
Tamer::init(ProtocolType::Gearman,
['127.0.0.1:4730']
);
Tamer::addWorker(__DIR__ . '/tamer_worker.php', 10);
Tamer::startWorkers();
// Sleep function (task) loop 10 times
for ($i = 0; $i < 10; $i++)
{
Tamer::queue(Task::create('sleep', 5, function(JobResults $data)
{
echo "Slept for {$data->getData()} seconds \n";
}));
}
echo "Waiting for jobs to finish \n";
$a = microtime(true);
Tamer::run();
$b = microtime(true);
echo "Took " . ($b - $a) . " seconds \n";

View file

@ -1,18 +0,0 @@
<?php
use TamerLib\Abstracts\Mode;
use TamerLib\Abstracts\ProtocolType;
use TamerLib\Tamer;
require 'ncc';
import('net.nosial.tamerlib', 'latest');
Tamer::initWorker();
Tamer::addFunction('sleep', function(\TamerLib\Objects\Job $job) {
sleep($job->getData());
return $job->getData();
});
Tamer::work();