{"id":53530,"date":"2019-12-04T00:00:00","date_gmt":"2019-12-03T21:00:00","guid":{"rendered":"https:\/\/prohoster.info\/blog\/blog_prohoster\/uskoryaem-php-konnektory-dlya-tarantool-s-pomoshhyu-async-swoole-i-parallel"},"modified":"2020-02-18T14:01:26","modified_gmt":"2020-02-18T11:01:26","slug":"uskoryaem-php-konnektory-dlya-tarantool-s-pomoshhyu-async-swoole-i-parallel","status":"publish","type":"post","link":"https:\/\/prohoster.info\/sq\/blog\/administrirovanie\/uskoryaem-php-konnektory-dlya-tarantool-s-pomoshhyu-async-swoole-i-parallel","title":{"rendered":"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/a4bfc8a3f7f7de0298623b1bf9dcfc54.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\nN\u00eb ekosistemin PHP aktualisht egzistojn\u00eb dy konektor\u00eb p\u00ebr t\u00eb punuar me serverin Tarantool \u2015 kjo \u00ebsht\u00eb zgjerimi zyrtar PECL <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/tarantool\/tarantool-php\">tarantool\/tarantool-php<\/a><\/noindex>, i shkruar n\u00eb C, dhe <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/tarantool-php\/client\">tarantool-php\/client<\/a><\/noindex>, i shkruar n\u00eb PHP. Un\u00eb jam autori i k\u00ebtij t\u00eb fundit.<\/p>\n<p>N\u00eb k\u00ebt\u00eb artikull do t\u00eb doja t\u00eb ndaja rezultatet e testimit t\u00eb performanc\u00ebs s\u00eb t\u00eb dy bibliotekave dhe t\u00eb tregoj se si me ndryshime minimale n\u00eb kod mund t\u00eb arrihet nj\u00eb rritje prej 3-5 p\u00ebrqind\u00ebsh (<i>n\u00eb teste sintetike!<\/i>).<br \/>\n<noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<h2>\u00c7far\u00eb do t\u00eb testojm\u00eb?<\/h2>\n<p>\nDo t\u00eb testojm\u00eb t\u00eb p\u00ebrmendurat m\u00eb sip\u00ebr <i>konektor\u00ebt<\/i> sinkron\u00eb<\/p>\n<ul>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/swoole\/swoole-src\">t\u00eb drejtuar asinkron, paralel dhe asinkron-paralel. \ud83d\ude42 Gjithashtu, nuk duam t\u00eb prekim kodin e vet\u00eb konektor\u00ebve. Aktualisht ekzistojn\u00eb disa zgjerime q\u00eb lejojn\u00eb arritjen e d\u00ebshiruar:<\/a><\/noindex> Swoole <i>\u2015 nj\u00eb k\u00ebt\u00eb e asinkron\u00eb e performant p\u00ebr PHP. P\u00ebrdoret nga gjigant\u00ebt e internetit si Alibaba dhe Baidu. Me versionin 4.1.0 doli metoda magjike<\/i>SwooleRuntime::enableCoroutine()\n<\/li>\n<li>, e cila lejon \"me nj\u00eb rresht kodi t\u00eb transformoni bibliotekat e rrjetit sinkron t\u00eb PHP n\u00eb asinkrone\". <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/dreamsxin\/ext-async\">Async \u2015 deri para pak koh\u00ebsh ishte nj\u00eb zgjerim i k\u00ebndsh\u00ebm p\u00ebr pun\u00ebn asinkrone n\u00eb PHP. Pse deri para pak koh\u00ebsh? Fatkeq\u00ebsisht, p\u00ebr nj\u00eb arsye q\u00eb nuk e di, autori e fshiu depozit\u00ebn dhe fatkeq\u00ebsia e projektit \u00ebsht\u00eb e paqart\u00eb. Do t\u00eb duhet t\u00eb p\u00ebrdorim<\/a><\/noindex> nga forkat. Si Swoole, kjo zgjerim lejon me nj\u00eb l\u00ebvizje t\u00eb leht\u00eb t\u00eb kthejm\u00eb pantallonat n\u00eb p\u00ebrfshirjen e asinkronis\u00eb duke z\u00ebvend\u00ebsuar implementimin standard t\u00eb TCP dhe TLS me versionet e tyre asinkrone. Kjo b\u00ebhet p\u00ebrmes opsionit &#171;<i>nga forkat. Si Swoole, ky zgjerim lejon me nj\u00eb l\u00ebvizje t\u00eb leht\u00eb t\u00eb kthesh asinkronitet duke z\u00ebvend\u00ebsuar implementimin standard t\u00eb TCP dhe TLS me versionet e tyre asinkrone. Kjo b\u00ebhet p\u00ebrmes opsionit \"<\/i>&#171;.\n<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/krakjoe\/parallel\">async.tcp = 1<\/a><\/noindex> Parallel\n<\/li>\n<\/ul>\n<p><\/p>\n<h2>\u2015 nj\u00eb zgjerim t\u00ebrheq\u00ebs nga i njohuri Joe Watkins, autori i biblioteka si phpdbg, apcu, pthreads, pcov, uopz. Zgjerimi ofron nj\u00eb API p\u00ebr pun\u00eb me shum\u00eb tela n\u00eb PHP dhe pozicionohet si z\u00ebvend\u00ebsim p\u00ebr pthreads. Nj\u00eb kufizim t\u00eb r\u00ebnd\u00ebsish\u00ebm t\u00eb bibliotek\u00ebs \u00ebsht\u00eb se ajo punon vet\u00ebm me versionin ZTS (Zend Thread Safe) t\u00eb PHP.<\/h2>\n<p>\nLe t\u00eb nisim nj\u00eb instanc\u00eb t\u00eb Tarantool-it me regjistrimin e paraprak t\u00eb shkarkuar (<i>Do t\u00eb nisim nj\u00eb instanc\u00eb t\u00eb Tarantool-it pa activizimin e regjistrit t\u00eb parapar\u00eb (<\/i>wal_mode = none<i>) dhe me nj\u00eb buffer rrjeti t\u00eb p\u00ebrmir\u00ebsuar (<\/i>readahead = 1 * 1024 * 1024<\/p>\n<p>). Opcioni i par\u00eb do t\u00eb p\u00ebrjashtoj\u00eb pun\u00ebn me diskun, nd\u00ebrsa i dyti do t\u00eb lejoj\u00eb leximin e m\u00eb shum\u00eb k\u00ebrkesave nga bufferi i sistemit operativ dhe k\u00ebshtu minimizimin e numrit t\u00eb thirrjeve sistemore.<br \/>\nP\u00ebr benchmark-et q\u00eb punojn\u00eb me t\u00eb dh\u00ebna (futje, fshirje, lexim etj.), para fillimit t\u00eb benchmark-ut do t\u00eb krijohet (rip\u00ebrt\u00ebrihet) hap\u00ebsira memtx, n\u00eb t\u00eb cil\u00ebn vlerat e indeksit primar krijohen nga nj\u00eb gjenerator i vlerave t\u00eb renditura t\u00eb numrave t\u00eb plot\u00eb (sequence).<\/p>\n<pre><code class=\"lua\">DDL e hap\u00ebsir\u00ebs duket k\u00ebshtu:<\/code><\/pre>\n<p>\nspace = box.schema.space.create(config.space_name, {id = config.space_id, temporary = true})\nspace:create_index('primary', {type = 'tree', parts = {1, 'unsigned'}, sequence = true})\nspace:format({{name = 'id', type = 'unsigned'}, {name = 'name', type = 'string', is_nullable = false}})<\/p>\n<pre><code class=\"lua\">N\u00ebse \u00ebsht\u00eb e nevojshme, para fillimit t\u00eb benchmark-ut, hap\u00ebsira plot\u00ebsohet me 10,000 k\u00ebtuza t\u00eb k\u00ebtij lloji<\/code><\/pre>\n<p>\n{id, \"tupl\u0435_\"}<\/p>\n<p>Qasja n\u00eb k\u00ebtuza b\u00ebhet p\u00ebrmes nj\u00eb vler\u00eb t\u00eb rast\u00ebsishme t\u00eb \u00e7el\u00ebsit.<\/p>\n<p><i>Benchmark-u p\u00ebrb\u00ebhet nga nj\u00eb k\u00ebrkes\u00eb t\u00eb vetme ndaj serverit, e cila ekzekutohet 10,000 her\u00eb (revolucione), t\u00eb cilat, nga ana e tyre, ekzekutohen n\u00eb iteracione. Iteracionet p\u00ebrs\u00ebriten derisa t\u00eb gjitha devijimet n\u00eb koh\u00eb mes 5 iteracioneve t\u00eb jen\u00eb brenda toleranc\u00ebs s\u00eb lejuar prej 3%*. Pas k\u00ebsaj rezultati mesatar merret. Nd\u00ebrmjet iteracioneve \u00ebsht\u00eb nj\u00eb pauz\u00eb prej 1 sekonde, p\u00ebr t\u00eb mos lejuar q\u00eb procesori t\u00eb kaloj\u00eb n\u00eb throttling. Grumbulluesi i mbeturinave Lua \u00ebsht\u00eb deaktivizuar para \u00e7do iteracioni dhe aktivizohet me detyrim pas p\u00ebrfundimit t\u00eb saj. Procesi PHP niset vet\u00ebm me zgjerimet e nevojshme p\u00ebr benchmark, me aktivizimin e bufferizimit t\u00eb daljes dhe deaktivizimin e grumbulluesit t\u00eb mbeturinave.<\/i><\/p>\n<h2>* Numri i revolucionave, iteracioneve dhe kufiri i toleranc\u00ebs mund t\u00eb ndryshohen n\u00eb parametrit e benchmark-ut.<\/h2>\n<p>\nRezultatet e publikuara m\u00eb posht\u00eb jan\u00eb realizuar n\u00eb MacBookPro (2015), sistemi operativ \u2014 Fedora 30 (versioni i b\u00ebrtham\u00ebs 5.3.8-200.fc30.x86_64). Tarantool u nis n\u00eb docker me parametrin &#171;<code>Rezultatet e publikuara m\u00eb posht\u00eb jan\u00eb b\u00ebr\u00eb n\u00eb MacBookPro (2015), sistemi operativ \u2013 Fedora 30 (versioni i b\u00ebrtham\u00ebs 5.3.8-200.fc30.x86_64). Tarantool \u00ebsht\u00eb drejtuar n\u00eb docker me parametrin \"<\/code>.<\/p>\n<p>--network host\"<\/p>\n<p>Versionet e paketave:<br \/>\nTarantool: 2.3.0-115-g5ba5ed37e<br \/>\nDocker: 19.03.3, build a872fc2f86<br \/>\nPHP: 7.3.11 (cli) (nd\u00ebrtuar: 22 Tetor 2019 08:11:04)<br \/>\ntarantool\/client: 0.6.0<br \/>\nrybakit\/msgpack: 0.6.1<br \/>\next-tarantool: 0.3.2 (+ patch p\u00ebr 7.3)*<br \/>\next-msgpack: 2.0.3<br \/>\next-async: 0.3.0-8c1da46<br \/>\next-swoole: 4.4.12<\/p>\n<p>* <i>ext-parallel: 1.1.3 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/tarantool\/tarantool-php\/pull\/148\/files\">patch<\/a><\/noindex>.<\/i><\/p>\n<h2>Rezultatet<\/h2>\n<p><\/p>\n<h4>M\u00ebnyra sinkrone<\/h4>\n<p>\nProtokolli i Tarantool-it p\u00ebrdor formatin binar <noindex><a rel=\"nofollow\" href=\"https:\/\/msgpack.org\/\">MessagePack<\/a><\/noindex> p\u00ebr serializimin e mesazheve. N\u00eb konektorin PECL, serializimi \u00ebsht\u00eb fshehur thell\u00eb n\u00eb brend\u00ebsi t\u00eb bibliotek\u00ebs dhe nuk \u00ebsht\u00eb e mundur t\u00eb ndikosh n\u00eb procesin e kodimit nga kodi i p\u00ebrdoruesit <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/tarantool\/tarantool-php\/issues\/89\">nuk \u00ebsht\u00eb e mundur<\/a><\/noindex>. Konnektori n\u00eb PHP t\u00eb past\u00ebr, nga ana tjet\u00ebr, ofron mund\u00ebsin\u00eb p\u00ebr t\u00eb personalizuar procesin e kodifikimit duke zgjeruar koduesin standard ose duke p\u00ebrdorur implementimin tuaj. Nga kutia jan\u00eb n\u00eb dispozicion dy kodues, nj\u00ebri i bazuar n\u00eb <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/msgpack\/msgpack-php\/\">msgpack\/msgpack-php<\/a><\/noindex> (zgjatja zyrtare e MessagePack PECL), tjetri \u2014 n\u00eb <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/rybakit\/msgpack.php\">rybakit\/msgpack<\/a><\/noindex> (n\u00eb PHP t\u00eb past\u00ebr).<\/p>\n<p>Para se t\u00eb krahasojm\u00eb konnektor\u00ebt, le t\u00eb masim performanc\u00ebn e koduesve t\u00eb MessagePack p\u00ebr konnektorin PHP dhe n\u00eb testet e m\u00ebtejshme do t\u00eb p\u00ebrdorim at\u00eb, i cili do t\u00eb tregoj\u00eb rezultatin m\u00eb t\u00eb mir\u00eb:<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/a293ec51cb8bf18cb88df2dc276142c4.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nMegjith\u00ebse versioni PHP (P\u00ebrzier) \u00ebsht\u00eb m\u00eb i ngadalsh\u00ebm se zgjatja PECL, n\u00eb projekte reale megjithat\u00eb do t'ju rekomandoja t\u00eb p\u00ebrdorni <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/rybakit\/msgpack.php\">rybakit\/msgpack<\/a><\/noindex>, sepse n\u00eb zgjatjen zyrtare t\u00eb MessagePack, specifikimi i formatit \u00ebsht\u00eb implementuar vet\u00ebm pjes\u00ebrisht (p\u00ebr shembull, nuk ka mb\u00ebshtetje p\u00ebr lloje t\u00eb dh\u00ebnash t\u00eb personalizuara, pa t\u00eb cilat nuk mund t\u00eb p\u00ebrdorni Decimal - lloji i ri i t\u00eb dh\u00ebnave, i prezantuar n\u00eb Tarantool 2.3) dhe ka nj\u00eb s\u00ebr\u00eb \u00e7\u00ebshtjesh t\u00eb tjera <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/msgpack\/msgpack-php\/issues\">problemeve<\/a><\/noindex> (duke p\u00ebrfshir\u00eb probleme t\u00eb kompatibilitetit me PHP 7.4). Dhe n\u00eb p\u00ebrgjith\u00ebsi, projekti duket se \u00ebsht\u00eb braktisur.<\/p>\n<p>Pra, le t\u00eb masim performanc\u00ebn e konnektor\u00ebve n\u00eb modin sinkron:<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/d8c5765956c62b927014ec4f26547820.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nSi\u00e7 duket nga grafiku, konnektori PECL (Tarantool) tregon nj\u00eb performanc\u00eb m\u00eb t\u00eb mir\u00eb n\u00eb krahasim me konnektorin n\u00eb PHP (Client). Por kjo nuk \u00ebsht\u00eb befasuese, duke pasur parasysh se ky i fundit, p\u00ebrve\u00e7 se \u00ebsht\u00eb implementuar n\u00eb nj\u00eb gjuh\u00eb m\u00eb t\u00eb ngadalshme, kryen gjithashtu m\u00eb shum\u00eb pun\u00eb: n\u00eb \u00e7do thirrje krijohet nj\u00eb objekt i ri <i>K\u00ebrkesa<\/i> dhe <i>P\u00ebrgjigje<\/i> (n\u00eb rastin e Select \u2014 madje edhe <i>Kriteret<\/i>, dhe n\u00eb rastin e Update\/Upsert \u2014 <i>Operacioneve<\/i>), entitete t\u00eb ve\u00e7anta <i>Connection<\/i>, <i>Packer <\/i>dhe <i>Handler<\/i> shtojn\u00eb gjithashtu overhead. \u00cbsht\u00eb e qart\u00eb q\u00eb p\u00ebr fleksibilitetin duhet t\u00eb paguash. Megjithat\u00eb, n\u00eb p\u00ebrgjith\u00ebsi, interpretuese PHP tregon nj\u00eb performanc\u00eb t\u00eb mir\u00eb, edhe pse diferenca \u00ebsht\u00eb aty, por ajo \u00ebsht\u00eb e vog\u00ebl dhe mund t\u00eb b\u00ebhet edhe m\u00eb e vog\u00ebl me p\u00ebrdorimin e preload n\u00eb PHP 7.4, pa folur p\u00ebr JIT n\u00eb PHP 8.<\/p>\n<p>Le t\u00eb vazhdojm\u00eb. N\u00eb Tarantool 2.0 ka ardhur mb\u00ebshtetje p\u00ebr SQL. Le t\u00eb provojm\u00eb t\u00eb kryejm\u00eb operacione Select, Insert, Update dhe Delete duke p\u00ebrdorur protokollin SQL dhe t\u00eb krahasojm\u00eb rezultatet me ekuivalent\u00ebt noSQL (binare):<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/cbc61697d9670dc7384c25de3c63c8d5.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nRezultatet e SQL nuk jan\u00eb shum\u00eb impresionuese (mosharoni se ende jemi duke testuar modin sinkron). Megjithat\u00eb, nuk do t\u00eb shqet\u00ebsohesha p\u00ebr k\u00ebt\u00eb para kohe, mb\u00ebshtetja p\u00ebr SQL \u00ebsht\u00eb ende n\u00eb zhvillim aktiv (relativisht s\u00eb fundmi, p\u00ebr shembull, \u00ebsht\u00eb shtuar mb\u00ebshtetja p\u00ebr <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/tarantool\/tarantool\/commit\/ff2091e09b5a7e9b7aa3f3e996dc7a06189889f3\">deklaratat e p\u00ebrgatitura<\/a><\/noindex>) dhe, duke par\u00eb list\u00ebn <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/tarantool\/tarantool\/issues?q=is%3Aissue+is%3Aopen+sql+label%3Aperformance\">issues<\/a><\/noindex>, motorin SQL e presin disa optimizime n\u00eb t\u00eb ardhmen.<\/p>\n<h4>Async<\/h4>\n<p>\nTani le t\u00eb shohim se si zgjatja Async mund t\u00eb na ndihmoj\u00eb p\u00ebr t\u00eb p\u00ebrmir\u00ebsuar rezultatet m\u00eb sip\u00ebr. P\u00ebr t\u00eb shkruar aplikacione asinkrone, zgjatja ofron nj\u00eb API t\u00eb bazuar n\u00eb korutina, dhe ne do ta p\u00ebrdorim at\u00eb. Duke eksperimentuar, zbulojm\u00eb se numri optimal i korutinave p\u00ebr mjedisin ton\u00eb \u00ebsht\u00eb 25:<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/4ceefef522b3bd91db7327c609ddda09.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n\u201cE shp\u00ebrndajm\u00eb\u201d 10,000 operacione n\u00eb 25 korutina dhe shohim se \u00e7far\u00eb rezultati kemi:<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/916e461dfa5d1be08317e3703c267afe.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nNumri i operacioneve n\u00eb sekond\u00eb u rrit m\u00eb shum\u00eb se tri her\u00eb p\u00ebr <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/tarantool-php\/client\">tarantool-php\/client<\/a><\/noindex>!<\/p>\n<p>Fatkeq\u00ebsisht, konnektori PECL nuk u aktivizua me ext-async.<\/p>\n<p>Por si \u00ebsht\u00eb me SQL?<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/39a0da214b893a217d9ae4eae23c4168.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nSi\u00e7 e shihni, n\u00eb modin asinkron diferenca midis protokollit binar dhe SQL u ul brenda kufijve t\u00eb gabimit.<\/p>\n<h4>t\u00eb drejtuar asinkron, paralel dhe asinkron-paralel. \ud83d\ude42 Gjithashtu, nuk duam t\u00eb prekim kodin e vet\u00eb konektor\u00ebve. Aktualisht ekzistojn\u00eb disa zgjerime q\u00eb lejojn\u00eb arritjen e d\u00ebshiruar:<\/h4>\n<p>\nP\u00ebrs\u00ebri zbulojm\u00eb numrin optimal t\u00eb korutinave, tani p\u00ebr Swoole:<br \/>\n<img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/70d5bb26b91b7459e2f0b80a3fab7e06.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nDo t\u00eb ndalemi n\u00eb 25. T\u00eb nj\u00ebjtin trik, q\u00eb me zgjatjen Async, e p\u00ebrs\u00ebrisim - shp\u00ebrndajm\u00eb 10,000 operacione midis 25 korutina. P\u00ebrve\u00e7 k\u00ebsaj, do t\u00eb shtojm\u00eb nj\u00eb prov\u00eb tjet\u00ebr, n\u00eb t\u00eb cil\u00ebn do t\u00eb ndajn\u00eb t\u00eb gjith\u00eb pun\u00ebn n\u00eb 2 procese (dmth \u00e7do proces do t\u00eb kryej\u00eb 5,000 operacione n\u00eb 25 korutina). Proceset do t\u00eb krijohen p\u00ebrmes <i>SwooleProcess<\/i>. <\/p>\n<p>Rezultatet:<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/55f55d2661aa43ca3b6641abfff078a6.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nSwole tregon nj\u00eb rezultat disi m\u00eb t\u00eb ul\u00ebt n\u00eb krahasim me Async kur ekzekutohet n\u00eb nj\u00eb proces, por me 2 procese, situata ndryshon ndjesh\u00ebm (numri 2 \u00ebsht\u00eb zgjedhur jo rast\u00ebsisht, n\u00eb makin\u00ebn time pik\u00ebrisht 2 procese treguan rezultatin m\u00eb t\u00eb mir\u00eb).<\/p>\n<p><i>P\u00ebr m\u00eb tep\u00ebr, n\u00eb zgjatjen Async gjithashtu ka API p\u00ebr punuar me procese, megjithat\u00eb nuk kam v\u00ebn\u00eb re ndonj\u00eb ndryshim nga ekzekutimi i benchmarkeve n\u00eb nj\u00eb apo disa procese (nuk p\u00ebrjashtohet se diku kam b\u00ebr\u00eb nj\u00eb gabim).<\/i><\/p>\n<p>SQL vs protokolli binar:<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/dfa56be01ebba25edbec492838112778.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nAshtu si me Async, diferenca midis operacioneve binar dhe SQL u zhduk n\u00eb m\u00ebnyr\u00eb asinkrone.<\/p>\n<h4>async.tcp = 1<\/h4>\n<p>\nDuke qen\u00eb se zgjatja Paralele nuk lidhet me korutina, por me procese, do t\u00eb masim numrin optimal t\u00eb proceseve paralele:<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/acc6796d5731b0402ad6323e0f5bf38f.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nAi \u00ebsht\u00eb 16 n\u00eb makin\u00ebn time. Le t\u00eb ekzekutojm\u00eb benchmarket e konnektor\u00ebve n\u00eb 16 procese paralele:<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/03210b70f15e445fdd311a17c1034290.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nSi\u00e7 e shihni, rezultati \u00ebsht\u00eb edhe m\u00eb i mir\u00eb se me zgjatjet asinkrone (p\u00ebrve\u00e7 Swoole t\u00eb aktivizuar n\u00eb 2 procese). Vini re se p\u00ebr konnektorin PECL, n\u00eb vendin e operacioneve Update dhe Upsert, \u00ebsht\u00eb bosh. Kjo \u00ebsht\u00eb p\u00ebr shkak se k\u00ebto operacione d\u00ebshtuan me nj\u00eb gabim - nuk di n\u00ebse \u00ebsht\u00eb faj i ext-parallel, ext-tarantool apo i t\u00eb dyjave.<\/p>\n<p>Tani le t\u00eb krahasojm\u00eb performanc\u00ebn e SQL:<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/4be3025b424ad6485dc96968ce224bf5.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nVini re ngjashm\u00ebrin\u00eb me grafikun p\u00ebr konnektor\u00ebt q\u00eb u aktivizuan sinkronikisht?<\/p>\n<h4>E gjith\u00eb kjo<\/h4>\n<p>\nN\u00eb fund, le t\u00eb sintetizojm\u00eb t\u00eb gjitha rezultatet n\u00eb nj\u00eb grafik, p\u00ebr t\u00eb par\u00eb pamjen e p\u00ebrgjithshme t\u00eb zgjatjeve q\u00eb po testojm\u00eb. Do t\u00eb shtojm\u00eb n\u00eb grafik vet\u00ebm nj\u00eb test t\u00eb ri, q\u00eb ende nuk e kemi b\u00ebr\u00eb - do t\u00eb nisnim korutinat Async paralelisht duke p\u00ebrdorur Parallel*. Ideja e integrimit t\u00eb zgjatjeve t\u00eb p\u00ebrmendura m\u00eb sip\u00ebr \u00ebsht\u00eb <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/krakjoe\/parallel\/issues\/25\">diskutuar<\/a><\/noindex> nga autor\u00ebt, megjithat\u00eb nuk \u00ebsht\u00eb arritur nj\u00eb konsensus, do t\u00eb duhet ta b\u00ebjm\u00eb k\u00ebt\u00eb vet\u00eb. <\/p>\n<p><i>* Nuk arrit\u00ebm t\u00eb nisim korutinat Swoole me Parallel, duket se k\u00ebto zgjatje jan\u00eb t\u00eb papajtueshme.<\/i><\/p>\n<p>Prandaj, rezultatet p\u00ebrfundimtare:<\/p>\n<p><img decoding=\"async\" alt=\"Po p\u00ebrshpejtojm\u00eb lidh\u00ebsit PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel\" src=\"\/wp-content\/uploads\/2019\/12\/85478d9dd5d8bd166f4aa91963c1af95.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<h2>N\u00eb vend t\u00eb p\u00ebrfundimit<\/h2>\n<p>\nMendimi im \u00ebsht\u00eb se rezultatet jan\u00eb mjaft t\u00eb k\u00ebnaqshme, dhe ndjej se kjo nuk \u00ebsht\u00eb akoma kufiri! N\u00ebse do t'ju nevojitej kjo n\u00eb nj\u00eb projekt real, e vendosni vet\u00ebm ju, un\u00eb do t\u00eb thosha se p\u00ebr mua ky ishte nj\u00eb eksperiment interesant, q\u00eb lejon vler\u00ebsimin e asaj \u00e7far\u00eb mund t\u00eb \u2018shp\u00ebrndahen\u2019 nga nj\u00eb lidhje TCP sinkron me p\u00ebrpjekje minimale. N\u00ebse keni ide p\u00ebr p\u00ebrmir\u00ebsimin e benchmark-\u00ebve - do t\u00eb pranoni me k\u00ebnaq\u00ebsi k\u00ebrkes\u00ebn tuaj p\u00ebr bashk\u00ebpunim. I gjith\u00eb kodi me udh\u00ebzime p\u00ebr nisje dhe rezultatet \u00ebsht\u00eb publikuar n\u00eb nj\u00eb <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/tarantool-php\/benchmarks\">repozitorit<\/a><\/noindex>.<br \/>\n<br \/>Burimi: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/mailru\/blog\/478336\/\">habr.com<\/a><\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0412 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0435 PHP \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0430 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c Tarantool \u2015 \u044d\u0442\u043e \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 PECL tarantool\/tarantool-php, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u043d\u0430 \u0421, \u0438 tarantool-php\/client, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 PHP. \u042f \u044f\u0432\u043b\u044f\u044e\u0441\u044c \u0430\u0432\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u0435\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u043a\u043e\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-53530","post","type-post","status-publish","format-standard","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u0412 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0435 PHP.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/sq\/blog\/administrirovanie\/uskoryaem-php-konnektory-dlya-tarantool-s-pomoshhyu-async-swoole-i-parallel\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"sq_AL\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0423\u0441\u043a\u043e\u0440\u044f\u0435\u043c PHP-\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u044b \u0434\u043b\u044f Tarantool \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Async, Swoole \u0438 Parallel | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u0412 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0435 PHP.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/sq\/blog\/administrirovanie\/uskoryaem-php-konnektory-dlya-tarantool-s-pomoshhyu-async-swoole-i-parallel\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-12-03T21:00:00+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-02-18T11:01:26+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Rrivendosim lidhjet PHP p\u00ebr Tarantool me ndihm\u00ebn e Async, Swoole dhe Parallel | ProHoster","description":"N\u00eb ekosistemin PHP.","canonical_url":"https:\/\/prohoster.info\/sq\/blog\/administrirovanie\/uskoryaem-php-konnektory-dlya-tarantool-s-pomoshhyu-async-swoole-i-parallel","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"sq_AL","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0423\u0441\u043a\u043e\u0440\u044f\u0435\u043c PHP-\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u044b \u0434\u043b\u044f Tarantool \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Async, Swoole \u0438 Parallel | ProHoster","og:description":"\u0412 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0435 PHP.","og:url":"https:\/\/prohoster.info\/sq\/blog\/administrirovanie\/uskoryaem-php-konnektory-dlya-tarantool-s-pomoshhyu-async-swoole-i-parallel","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2019-12-03T21:00:00+00:00","article:modified_time":"2020-02-18T11:01:26+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"53530","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":"2026-01-24 07:46:24","breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-02-28 20:23:55","updated":"2026-01-24 07:46:24","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/posts\/53530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/comments?post=53530"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/posts\/53530\/revisions"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/media?parent=53530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/categories?post=53530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/tags?post=53530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}