Add cache for Phalcon [Benchmark of php frameworks v0.0.6]

in #utopian-io7 years ago (edited)

In Release 0.0.6:

  • Add new tests for phalcon:
    • Use Cache for load posts from DB in 'posts' most heavy page.
  • Add posibility for viewing testing result of releseas
    • results for 0.0.5
    • results of testing release 0.0.6

More informations about changes.

About cache and eager loading in laravel, I wrote in my previews post.
Now we add caching functional on page 'posts' in phalcon framework.
Let`s add new Controller:

PostwsController() in phalcon-3.2/app/controllers/PostswcController.php

use Phalcon\Cache\Backend\File as BackFile;
use Phalcon\Cache\Frontend\Data as FrontData;
/**
 * Index action
 */
public function indexAction()
{
    $posts = null;
    $frontCache = new FrontData(
        [
            'lifetime' => 172800,
        ]
    );
    $cache = new BackFile(
        $frontCache,
        [
            'cacheDir' => '../app/cache/',
        ]
    );

    $cacheKey = 'posts.cache';

    $posts = $cache->get($cacheKey);

    if ($posts === null) {

        $this->persistent->parameters = null;
        $parameters = $this->persistent->parameters;
        if (!is_array($parameters)) {
            $parameters = [];
        }
        //$parameters["limit"] = "100";
        //$parameters["limit"] = array('number' => 100, 'offset' => 10);
        $parameters["order"] = "id";

        $posts = Posts::find($parameters);
        $cache->save($cacheKey, $posts);
    }

 if (count($posts) == 0) {
  $this->flash->notice("The search did not find any posts");

  $this->dispatcher->forward([
   "controller" => "postsCache",
   "action" => "index"
  ]);

  return;
 }
    //var_dump($posts);
 $this->view->posts = $posts;
}

Views we can copy from posts to postswc:

phalcon-3.2/app/views/layouts/posts.phtml -> phalcon-3.2/app/views/layouts/postswc.phtml
folder phalcon-3.2/app/views/posts -> folder phalcon-3.2/app/views/postswc

And that`s all. New page 'postswc' we can see by link

After tests we see that adding a cache did not change the situation. In table !!phalcon-postswc row.

frameworkrequests per secondrelativepeak memoryrelative
phalcon-index113.172,829.30.491.0
phalcon-authors22.35558.80.611.3
phalcon-categories13.61340.30.621.3
laravel-index8.67216.86.2112.7
laravel-posts-el-cache8.00200.07.3415.1
laravel-posts-el7.79194.87.3415.1
laravel-categories6.97174.37.5915.6
laravel-authors6.90172.57.3415.1
!! phalcon-postswc0.102.52.455.0
phalcon-posts0.092.32.364.8
laravel-posts0.041.015.1331.0
laravel-posts-cache0.041.018.4637.9

006screenshot-php-frameworks.semasping.info 2018-01-29 20-43-59-307.png

I'll tell you about adding eager loading next time, because there is not eager loading in Phalcon from the box.
In this release I have change the sctructure for releases result viewing.

For every next release it's testing results will be commited in repository (bm/result-releases/0.0.5/output, bm/result-releases/0.0.6/output, bm/result-releases/...../output, etc.)
And they can be viewed on http://php-frameworks.semasping.info/bm/result-releases/0.0.6/index.php where 0.0.6 - release version.
That links will be added to release informations on github

This release: https://github.com/semasping/php_frameworks_for_tests/releases/tag/0.0.6

Commits in this release:

Roadmap:

  • Try to use Cache for all frameworks (Done for laravel. Done for Phalcon)
  • Find Eager Loading functional for Phalcon 3.2 (or try stibiumz/phalcon.eager-loading for Phalcon 1.3.* - 2.0.*.)
  • Implementing a test application and running tests on Symfony
  • Implementing a test application and running tests on Yii
  • Connection with https://blackfire.io/
  • Deal with the Docker and wrap it all up in it. To be able to quickly deploy to a more powerful server for comparison.

PS: More information about structure of test application



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

Very detailed

Please add a license to your repo.

You can contact us on Discord.
[utopian-moderator]

Thank you!

Please add a license to your repo

Done

Ни фига не поняла, но я За! За качественные вклады в мир open-source:-)

Hey @semasping I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.16
TRX 0.16
JST 0.031
BTC 58954.91
ETH 2508.61
USDT 1.00
SBD 2.45