From 60d3e38558240e31dd6836bb17c73eb24d99f325 Mon Sep 17 00:00:00 2001 From: Laky64 Date: Wed, 21 Oct 2020 00:45:58 +0200 Subject: [PATCH] Bug fix, and performance improvments --- .gitignore | 3 +- PHP-README.md | 123 +++++++++++++++++ PYTHON-README.md | 121 ++++++++++++++++ README.md | 307 ++++++++--------------------------------- composer.json | 2 + src/CustomMemcache.php | 15 +- src/JDBI.php | 4 +- src/JDB_CORE.php | 106 +++++++++----- 8 files changed, 386 insertions(+), 295 deletions(-) create mode 100644 PHP-README.md create mode 100644 PYTHON-README.md diff --git a/.gitignore b/.gitignore index a30d309..370e438 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ /composer.phar /test.py /__pycache__ -/src/__pycache__ \ No newline at end of file +/src/__pycache__ +/test_AMPPHP.php diff --git a/PHP-README.md b/PHP-README.md new file mode 100644 index 0000000..15e5dfe --- /dev/null +++ b/PHP-README.md @@ -0,0 +1,123 @@ +# JDBI Client (PHP) +Front-end to take request to JDB Core + +## Requirements: +- **PHP > 7.4** +- **PHP Memcache** +- **JDB Core Running** +- **Memcached Server Running** + +## Introduction +For first initialize the **JDB Sock Connection** to **Memcached Server** +``` php +use laky64\database\JDBI; +include 'vendor/autoload.php'; +$JDBI = new JDBI('ip_memcached_server', 'port_memcached_server'); //Start Connection +... +$JDBI -> close(); //Close connection +``` +#### Show Processlist +Show processlist, return array on success and null on failure +``` php +... +$JDBI->query('SHOW PROCESSLIST;'); +... +``` +#### Make Database +For make database, return true on success and false on failure +``` php +... +$JDBI->query('CREATE DATABASE `database_name` PASSWORD `database_password`;'); +... +``` +#### Drop Database +For drop database, return true on success and false on failure +``` php +... +$JDBI->query('DROP DATABASE `database_name`;'); +... +``` +#### Connect to Database +For connect to database, return true on success and false on failure +``` php +... +$JDBI -> connect('database_name','database_password'); +... +``` +#### Make Table +For make table **(Need connection to database)**, return true on success and false on failure +##### With Auto-Increment primary key +``` php +... +$JDBI->query('CREATE TABLE `table_name` (`column1`, `column2`, `column3`) AS PRIMARY `column1` TYPE `AUTO_INCREMENT`;'); +... +``` +##### With Defined primary key +``` php +... +$JDBI->query('CREATE TABLE `table_name` (`column1`, `column2`, `column3`) AS PRIMARY `column1` TYPE `DEFINED`;'); +... +``` +#### Drop Table +For drop table **(Need connection to database)**, return true on success and false on failure +``` php +... +$JDBI->query('DROP TABLE `table_name`;'); +... +``` +#### Show all Table +Show all tables **(Need connection to database)**, return array on success and null on failure +``` php +... +$JDBI->query('SHOW TABLES;'); +... +``` +#### Dump Table +Dump Row **(Need connection to database)**, return array on success and null on failure +``` php +... +$JDBI->query('SELECT * FROM `table_name`;'); +... +``` +#### Add Column +Add Column **(Need connection to database)**, return true on success and false on failure +``` php +... +$JDBI->query('ALTER TABLE `table_name` ADD COLUMN (`column1`, `column2`);'); +... +``` +#### Drop Column +Add Column **(Need connection to database)**, return true on success and false on failure +``` php +... +$JDBI->query('ALTER TABLE `table_name` DROP COLUMN (`column1`, `column2`);'); +... +``` +#### Insert Row +Insert Row **(Need connection to database)**, return true on success and false on failure +``` php +... +$JDBI->query('INSERT INTO `table_name` (`column1`, `column2`, `column3`) VALUES (`value1`, `value2`, `value3`);'); +... +``` +#### Update Row +Insert Row **(Need connection to database)**, return true on success and false on failure +``` php +... +$JDBI->query('UPDATE `table_name` SET (`column1`, `column2`) VALUES (`value1`, `value2`) WHERE `column` IS `value`;'); +... +``` +#### Delete Row +Delete Row **(Need connection to database)**, return true on success and false on failure +``` php +... +$JDBI->query('DELETE FROM `table_name` WHERE `column` IS `value`;'); +... +``` +#### Dump Row +Dump Row **(Need connection to database)**, return array on success and null on failure +``` php +... +$JDBI->query('SELECT * FROM `table_name` WHERE `column` IS `value`;'); +... +``` \ No newline at end of file diff --git a/PYTHON-README.md b/PYTHON-README.md new file mode 100644 index 0000000..3c6950c --- /dev/null +++ b/PYTHON-README.md @@ -0,0 +1,121 @@ +# JDBI Client (Python) +Front-end to take request to JDB Core + +## Requirements: +- **PHP > 7.4** +- **PHP Memcache** +- **Python > 3.9** +- **JDB Core Running** +- **Memcached Server Running** + +## Introduction +For first initialize the **JDB Sock Connection** to **Memcached Server** +``` python +from vendor.laky64.jdb.src.JDBI import JDBI +JDBI_CLASS = JDBI('ip_memcached_server', 'port_memcached_server') +``` +#### Show Processlist +Show processlist, return array on success and None on failure +``` python +... +JDBI_CLASS.query('SHOW PROCESSLIST;') +... +``` +#### Make Database +For make database, return true on success and false on failure +``` python +... +JDBI_CLASS.query('CREATE DATABASE `database_name` PASSWORD `database_password`;') +... +``` +#### Drop Database +For drop database, return true on success and false on failure +``` python +... +JDBI_CLASS.query('DROP DATABASE `database_name`;') +... +``` +#### Connect to Database +For connect to database, return true on success and false on failure +``` python +... +JDBI_CLASS.connect('database_name','database_password') +... +``` +#### Make Table +For make table **(Need connection to database)**, return true on success and false on failure +##### With Auto-Increment primary key +``` python +... +JDBI_CLASS.query('CREATE TABLE `table_name` (`column1`, `column2`, `column3`) AS PRIMARY `column1` TYPE `AUTO_INCREMENT`;') +... +``` +##### With Defined primary key +``` python +... +JDBI_CLASS.query('CREATE TABLE `table_name` (`column1`, `column2`, `column3`) AS PRIMARY `column1` TYPE `DEFINED`;') +... +``` +#### Drop Table +For drop table **(Need connection to database)**, return true on success and false on failure +``` python +... +JDBI_CLASS.query('DROP TABLE `table_name`;') +... +``` +#### Show all Table +Show all tables **(Need connection to database)**, return array on success and None on failure +``` python +... +JDBI_CLASS.query('SHOW TABLES;') +... +``` +#### Dump Table +Dump Row **(Need connection to database)**, return array on success and None on failure +``` python +... +JDBI_CLASS.query('SELECT * FROM `table_name`;') +... +``` +#### Add Column +Add Column **(Need connection to database)**, return true on success and false on failure +``` python +... +JDBI_CLASS.query('ALTER TABLE `table_name` ADD COLUMN (`column1`, `column2`);') +... +``` +#### Drop Column +Add Column **(Need connection to database)**, return true on success and false on failure +``` python +... +JDBI_CLASS.query('ALTER TABLE `table_name` DROP COLUMN (`column1`, `column2`);') +... +``` +#### Insert Row +Insert Row **(Need connection to database)**, return true on success and false on failure +``` python +... +JDBI_CLASS.query('INSERT INTO `table_name` (`column1`, `column2`, `column3`) VALUES (`value1`, `value2`, `value3`);') +... +``` +#### Update Row +Insert Row **(Need connection to database)**, return true on success and false on failure +``` python +... +$JDBI->query('UPDATE `table_name` SET (`column1`, `column2`) VALUES (`value1`, `value2`) WHERE `column` IS `value`;'); +... +``` +#### Delete Row +Delete Row **(Need connection to database)**, return true on success and false on failure +``` python +... +JDBI_CLASS.query('DELETE FROM `table_name` WHERE `column` IS `value`;') +... +``` +#### Dump Row +Dump Row **(Need connection to database)**, return array on success and None on failure +``` python +... +JDBI_CLASS.query('SELECT * FROM `table_name` WHERE `column` IS `value`;') +... +``` \ No newline at end of file diff --git a/README.md b/README.md index 57d6982..799ed67 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,57 @@ -# JDB(v. 3.1-beta) -A very fast database based on json text plain with encryptation +# JDB(v. 3.3-stable) +JDB is very fast parallel database based on json text plain with encryptation `JDB 2.3-stable it's still available but deprecated` -### Now Available in Async Multi-Thread and Windows Environment! +_Library maked by [Laky64](https://t.me/Laky64)_ -First create the database folder, then create in the database folder with the name of the table to which you want to attribute, in which you want to insert the fields +## JDB Bechmark +| | PHP | Python | Mode | Thread Mode | +| --- | --- | --- | --- | --- | +| **One Thread** | 15ms | 37ms | Sequential | Single Thread | +| **Two Thread** | 47ms | 85ms | Async | Multi Thread | +| **Four Thread** | 79ms | 149ms | Async | Multi Thread | +| **Eight Thread** | 143ms | 133ms | Async | Multi Thread | +| **Twelve Thread** | 207ms | 402ms | Async | Multi Thread | + +## JDB Structure +Below is how the JDB database is structured + +##### JDB Core Structure +| DATABASE | PASSWORD | +| --- | --- | +| database1 | password1 | +| database2 | password2 | +| database3 | password3 | + +##### Database Structure +| TABLE | PRIMARY KEY | PRIMARY KEY TYPE | +| --- | --- | --- | +| table1 | primary_key1 | primary_key_type1 | +| table2 | primary_key2 | primary_key_type2 | +| table3 | primary_key3 | primary_key_type3 | + +##### Table Structure +| | COLUMN1 | COLUMN2 | COLUMN3 | +| --- | --- | --- | --- | +| **ROW1** | value1 | value2 | value3 | +| **ROW2** | value1 | value2 | value3 | +| **ROW3** | value1 | value2 | value3 | + +## JDB Core Threads +In the JDB core there are different types of threads each with different jobs, here it is: + +- **Controller Unit Thread** +It divides the workload on the various Operation Threads according to the freest one +- **I/O Thread** +It performs backups to disk every 500ms from RAM Database +- **Operation Thread** +It performs computation or query operations, usually more than one of these threads are started + +## Getting Started +### Now Available in Async Multi-Thread, supported Windows Environment and Python Client! -_Library maked by [Laky64](https://t.me/Laky64)_ +First create the database folder, then create in the database folder with the name of the table to which you want to attribute, in which you want to insert the fields ## Installation with composer With **json file** (`Composer`): @@ -23,10 +67,10 @@ With **command line** (`Composer`): **-** `composer require laky64/jdb` -## Documentation +## Warning! Read this **documentation** carefully so as not to cause malfunctions with **JDB** -### JDB CORE +## JDB CORE #### Requirements: - **PHP > 7.4** @@ -56,247 +100,14 @@ include 'vendor/autoload.php'; new JDB_CORE(JDB_CORE::NUM_THREAD, 'database_folder', 'ip_memcached_server', 'port_memcached_server'); ``` -### JDBI Client (PHP) -Front-end to take request to JDB Core +## Available Clients +- [**PHP Client**](https://github.com/Laky-64/JDB/blob/master/PHP-README.md) +- [**Python Client**](https://github.com/Laky-64/JDB/blob/master/PYTHON-README.md) -#### Requirements: -- **PHP > 7.4** -- **PHP Memcache** -- **JDB Core Running** -- **Memcached Server Running** +## Contributing +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. -#### Introduction -For first initialize the **JDB Sock Connection** to **Memcached Server** -``` php -use laky64\database\JDBI; -include 'vendor/autoload.php'; -$JDBI = new JDBI('ip_memcached_server', 'port_memcached_server'); //Start Connection -... -$JDBI -> close(); //Close connection -``` -#### Show Processlist -Show processlist, return array on success and null on failure -``` php -... -$JDBI->query('SHOW PROCESSLIST;'); -... -``` -#### Make Database -For make database, return true on success and false on failure -``` php -... -$JDBI->query('CREATE DATABASE `database_name` PASSWORD `database_password`;'); -... -``` -#### Drop Database -For drop database, return true on success and false on failure -``` php -... -$JDBI->query('DROP DATABASE `database_name`;'); -... -``` -#### Connect to Database -For connect to database, return true on success and false on failure -``` php -... -$JDBI -> connect('database_name','database_password'); -... -``` -#### Make Table -For make table **(Need connection to database)**, return true on success and false on failure -##### With Auto-Increment primary key -``` php -... -$JDBI->query('CREATE TABLE `table_name` (`column1`, `column2`, `column3`) AS PRIMARY `column1` TYPE `AUTO_INCREMENT`;'); -... -``` -##### With Defined primary key -``` php -... -$JDBI->query('CREATE TABLE `table_name` (`column1`, `column2`, `column3`) AS PRIMARY `column1` TYPE `DEFINED`;'); -... -``` -#### Drop Table -For drop table **(Need connection to database)**, return true on success and false on failure -``` php -... -$JDBI->query('DROP TABLE `table_name`;'); -... -``` -#### Show all Table -Show all tables **(Need connection to database)**, return array on success and null on failure -``` php -... -$JDBI->query('SHOW TABLES;'); -... -``` -#### Dump Table -Dump Row **(Need connection to database)**, return array on success and null on failure -``` php -... -$JDBI->query('SELECT * FROM `table_name`;'); -... -``` -#### Add Column -Add Column **(Need connection to database)**, return true on success and false on failure -``` php -... -$JDBI->query('ALTER TABLE `table_name` ADD COLUMN (`column1`, `column2`);'); -... -``` -#### Drop Column -Add Column **(Need connection to database)**, return true on success and false on failure -``` php -... -$JDBI->query('ALTER TABLE `table_name` DROP COLUMN (`column1`, `column2`);'); -... -``` -#### Insert Row -Insert Row **(Need connection to database)**, return true on success and false on failure -``` php -... -$JDBI->query('INSERT INTO `table_name` (`column1`, `column2`, `column3`) VALUES (`value1`, `value2`, `value3`);'); -... -``` -#### Update Row -Insert Row **(Need connection to database)**, return true on success and false on failure -``` php -... -$JDBI->query('UPDATE `table_name` SET (`column1`, `column2`) VALUES (`value1`, `value2`) WHERE `column` IS `value`;'); -... -``` -#### Delete Row -Delete Row **(Need connection to database)**, return true on success and false on failure -``` php -... -$JDBI->query('DELETE FROM `table_name` WHERE `column` IS `value`;'); -... -``` -#### Dump Row -Dump Row **(Need connection to database)**, return array on success and null on failure -``` php -... -$JDBI->query('SELECT * FROM `table_name` WHERE `column` IS `value`;'); -... -``` -### JDBI Client (Python) -Front-end to take request to JDB Core +Please make sure to update tests as appropriate. -#### Requirements: -- **PHP > 7.4** -- **PHP Memcache** -- **Python > 3.9** -- **JDB Core Running** -- **Memcached Server Running** - -#### Introduction -For first initialize the **JDB Sock Connection** to **Memcached Server** -``` python -from vendor.laky64.jdb.src.JDBI import JDBI -JDBI_CLASS = JDBI('ip_memcached_server', 'port_memcached_server') -``` -#### Show Processlist -Show processlist, return array on success and None on failure -``` python -... -JDBI_CLASS.query('SHOW PROCESSLIST;') -... -``` -#### Make Database -For make database, return true on success and false on failure -``` python -... -JDBI_CLASS.query('CREATE DATABASE `database_name` PASSWORD `database_password`;') -... -``` -#### Drop Database -For drop database, return true on success and false on failure -``` python -... -JDBI_CLASS.query('DROP DATABASE `database_name`;') -... -``` -#### Connect to Database -For connect to database, return true on success and false on failure -``` python -... -JDBI_CLASS.connect('database_name','database_password') -... -``` -#### Make Table -For make table **(Need connection to database)**, return true on success and false on failure -##### With Auto-Increment primary key -``` python -... -JDBI_CLASS.query('CREATE TABLE `table_name` (`column1`, `column2`, `column3`) AS PRIMARY `column1` TYPE `AUTO_INCREMENT`;') -... -``` -##### With Defined primary key -``` python -... -JDBI_CLASS.query('CREATE TABLE `table_name` (`column1`, `column2`, `column3`) AS PRIMARY `column1` TYPE `DEFINED`;') -... -``` -#### Drop Table -For drop table **(Need connection to database)**, return true on success and false on failure -``` python -... -JDBI_CLASS.query('DROP TABLE `table_name`;') -... -``` -#### Show all Table -Show all tables **(Need connection to database)**, return array on success and None on failure -``` python -... -JDBI_CLASS.query('SHOW TABLES;') -... -``` -#### Dump Table -Dump Row **(Need connection to database)**, return array on success and None on failure -``` python -... -JDBI_CLASS.query('SELECT * FROM `table_name`;') -... -``` -#### Add Column -Add Column **(Need connection to database)**, return true on success and false on failure -``` python -... -JDBI_CLASS.query('ALTER TABLE `table_name` ADD COLUMN (`column1`, `column2`);') -... -``` -#### Drop Column -Add Column **(Need connection to database)**, return true on success and false on failure -``` python -... -JDBI_CLASS.query('ALTER TABLE `table_name` DROP COLUMN (`column1`, `column2`);') -... -``` -#### Insert Row -Insert Row **(Need connection to database)**, return true on success and false on failure -``` python -... -JDBI_CLASS.query('INSERT INTO `table_name` (`column1`, `column2`, `column3`) VALUES (`value1`, `value2`, `value3`);') -... -``` -#### Update Row -Insert Row **(Need connection to database)**, return true on success and false on failure -``` python -... -$JDBI->query('UPDATE `table_name` SET (`column1`, `column2`) VALUES (`value1`, `value2`) WHERE `column` IS `value`;'); -... -``` -#### Delete Row -Delete Row **(Need connection to database)**, return true on success and false on failure -``` python -... -JDBI_CLASS.query('DELETE FROM `table_name` WHERE `column` IS `value`;') -... -``` -#### Dump Row -Dump Row **(Need connection to database)**, return array on success and None on failure -``` python -... -JDBI_CLASS.query('SELECT * FROM `table_name` WHERE `column` IS `value`;') -... -``` \ No newline at end of file +## License +[MIT](https://choosealicense.com/licenses/mit/) \ No newline at end of file diff --git a/composer.json b/composer.json index 43456ea..551044d 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,8 @@ "ext-json": "*", "ext-openssl": "*", "amphp/amp": "^2.5", + "amphp/parallel-functions": "^v1.0.0", + "amphp/parallel": "^v1.4.0", "ext-memcache": "*" }, "type": "project" diff --git a/src/CustomMemcache.php b/src/CustomMemcache.php index 3ac92d5..9d158b3 100644 --- a/src/CustomMemcache.php +++ b/src/CustomMemcache.php @@ -14,7 +14,7 @@ public function close(){ return $this->INSTANCE->close(); } public function add($key, $var){ - $RESULT = $this->INSTANCE->set($key, $var); + $RESULT = @$this->INSTANCE->set($key, $var); if($RESULT){ $LIST_KEYS = json_decode($this->INSTANCE->get('MEMCACHE_KEYS'),true); $LIST_KEYS[$key] = true; @@ -30,15 +30,18 @@ public function delete($key){ return $RESULT; } public function getAllKeys(){ - $return_d = json_decode($this->INSTANCE->get('MEMCACHE_KEYS'),true); - $return_d = $return_d == null ? []:$return_d; $return_tmp = []; - foreach ($return_d as $key=>$item){ - $return_tmp[] = $key; + $result = @$this->INSTANCE->get('MEMCACHE_KEYS'); + if($result != null){ + $return_d = json_decode($result,true); + $return_d = $return_d == null ? []:$return_d; + foreach ($return_d as $key=>$item){ + $return_tmp[] = $key; + } } return $return_tmp; } public function get($key){ - return $this->INSTANCE->get($key); + return @$this->INSTANCE->get($key); } } \ No newline at end of file diff --git a/src/JDBI.php b/src/JDBI.php index 7d3c672..eec62f2 100644 --- a/src/JDBI.php +++ b/src/JDBI.php @@ -586,14 +586,14 @@ protected function get_database(){ protected function send_req_with_response(string $OPERATION_EXECUTE):string{ $curr_id = $this -> generateRandomString(64); $this->INSTANCE_RAM -> add('JDB_REQ_' . $curr_id, $OPERATION_EXECUTE); + //$start = microtime(true); $start_time = time(); while($this->INSTANCE_RAM -> get('JDB_RESULT_' . $curr_id) == ''){ if((time() - $start_time) > $this->TIMEOUT){ throw new Exception('Error when connecting to JDBI CORE: ERROR_CONN'); - }else{ - usleep(5000); } } + //echo (int)((microtime(true) - $start) * 1000) . 'ms ADD' .PHP_EOL; $DATA_RES = $this->INSTANCE_RAM -> get('JDB_RESULT_' . $curr_id); $this->INSTANCE_RAM -> delete('JDB_RESULT_' . $curr_id); return $DATA_RES; diff --git a/src/JDB_CORE.php b/src/JDB_CORE.php index f5af98a..867ae45 100644 --- a/src/JDB_CORE.php +++ b/src/JDB_CORE.php @@ -1,8 +1,13 @@ [], - 'CONTROLLER_UNIT' => 0 + 'OPERATION_THREADS' => [] ]; protected CustomMemcache $INSTANCE_RAM; + function __construct(int $NUM_THREAD, string $PATH_FOLDER, string $MEM_CACHE_IP = '127.0.0.1', string $MEM_CACHE_PORT = '1211'){ echo 'Detecting environment...' . PHP_EOL; if($PATH_FOLDER[0] == '/'){ @@ -77,36 +83,75 @@ function __construct(int $NUM_THREAD, string $PATH_FOLDER, string $MEM_CACHE_IP } echo 'Imported succefully database from disk!' . PHP_EOL; echo 'Starting running ' . $this->OPERATION_THREADS . ' threads...' . PHP_EOL; - Loop::run(function() { - Loop::repeat(1,function (){ - if($this->NUM_ACTIVE_OPERATION_THREAD < $this->OPERATION_THREADS){ - $this->NUM_ACTIVE_OPERATION_THREAD++; - $num_thread = $this->NUM_ACTIVE_OPERATION_THREAD; - Loop::delay(1000, function () use ($num_thread){ + if($NUM_THREAD == self::$ONE_THREAD){ + $this->NUM_ACTIVE_OPERATION_THREAD++; + Loop::run(function () { + $this->NUM_ACTIVE_OPERATION_THREAD++; + Loop::repeat(10,function (){ + if($this->TICK >= 500){ + $this->TICK = 0; + $this->execute_io(); + } + $this->execute_control_unit(); + $this->execute_operation(1); + $this->TICK += 10; + }); + }); + }else{ + Loop::run(function() { + Loop::repeat(1,function (){ + if($this->NUM_ACTIVE_OPERATION_THREAD < $this->OPERATION_THREADS){ + $this->NUM_ACTIVE_OPERATION_THREAD++; + $num_thread = $this->NUM_ACTIVE_OPERATION_THREAD; $this->join_operation_thread($num_thread); - }); - - } + } + }); + $this->join_io_thread(); + $this->join_control_unit_thread(); }); - $this->join_io_thread(); - $this->join_control_unit_thread(); - }); - + } }else{ die('The path not exist or is file'); } } + //JDBI I/O THREAD + protected function join_io_thread(){ + Loop::repeat($msInterval = 500, function (){ + $this->execute_io(); + usleep(10000); + }); + } + + protected function execute_io() { + if(!isset($this->STATE_CORE['IO_THREAD'])){ + echo 'Started I/O Thread' . PHP_EOL; + } + $this->STATE_CORE['IO_THREAD'] = [ + 'state' => 'RUNNING(' . time() . ')' + ]; + foreach ($this->DB_GLOBAL as $DB_NAME => $DB_CONTENT){ + $DATA = $DB_CONTENT; + if($DB_NAME[0] != '.'){ + $DATA = $this -> encrypt(json_encode($DB_CONTENT, true), $this->DB_GLOBAL['.'.$DB_NAME]); + } + file_put_contents($this->DATABASE_FOLDER . $this->ENVIRONMENT_SEPARATOR . $DB_NAME . '.jdb', $DATA); + } + } + //END I/O THREAD //JDBI CONTROL UNIT THREADS protected function join_control_unit_thread(){ - echo 'Started Control Unit Thread' . PHP_EOL; Loop::repeat($msInterval = 10, function (){ $this->execute_control_unit(); usleep(10000); }); } + protected function execute_control_unit() { + if(!isset($this->STATE_CORE['CONTROLLER_UNIT'])){ + echo 'Started Control Unit Thread' . PHP_EOL; + } $this->STATE_CORE['CONTROLLER_UNIT'] = [ 'state' => 'RUNNING(' . time() . ')' ]; @@ -135,35 +180,20 @@ protected function execute_control_unit() { } //END JDBI CONTROL UNIT THREAD - //JDBI CORE - protected function join_io_thread(){ - echo 'Started I/O Thread' . PHP_EOL; - Loop::repeat($msInterval = 500, function (){ - $this->execute_io(); - usleep(10000); - }); - } - protected function execute_io() { - $this->STATE_CORE['IO_THREAD'] = [ - 'state' => 'RUNNING(' . time() . ')' - ]; - foreach ($this->DB_GLOBAL as $DB_NAME => $DB_CONTENT){ - $DATA = $DB_CONTENT; - if($DB_NAME[0] != '.'){ - $DATA = $this -> encrypt(json_encode($DB_CONTENT, true), $this->DB_GLOBAL['.'.$DB_NAME]); - } - file_put_contents($this->DATABASE_FOLDER . $this->ENVIRONMENT_SEPARATOR . $DB_NAME . '.jdb', $DATA); - } - } + //OPERATION THREAD protected function join_operation_thread($num_thread){ - echo 'Started Operation Thread n.' . $num_thread . PHP_EOL; $this->DATA_INPUT_ARRAY_OPERATION[$num_thread] = []; Loop::repeat($msInterval = 10, function () use ($num_thread){ $this->execute_operation($num_thread); usleep(10000); }); } + protected function execute_operation($ID_THREAD) { + if(!isset($this->STATE_CORE['OPERATION_THREADS'][$ID_THREAD])){ + echo 'Started Operation Thread n.' . $ID_THREAD . PHP_EOL; + $this->DATA_INPUT_ARRAY_OPERATION[$ID_THREAD] = []; + } $this->STATE_CORE['OPERATION_THREADS'][$ID_THREAD] = [ 'lastupdate' => time(), 'pending' => count($this->DATA_INPUT_ARRAY_OPERATION[$ID_THREAD]) @@ -554,7 +584,7 @@ protected function execute_operation($ID_THREAD) { } unset($this->DATA_INPUT_ARRAY_OPERATION[$ID_THREAD][$id_operation]); } - //END JDBI CORE + //END OPERATION THREAD //OPENSSL CRYPTATION protected function encrypt($pure_string, $encryption_key) {