# APC + Phar Performance (x-post from pecl.dev)

- Thread: https://externals.io/message/64121
- Original archive: https://news-web.php.net/php.internals/64121
- Started by Ralph Schindler on 2012-11-30T14:54:51+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #64121 — Ralph Schindler — 2012-11-30T14:54:51+00:00

URL: https://externals.io/message/64121#64121

Hey all,

After reading this post ( 
http://www.reddit.com/r/PHP/comments/13uwgk/phar_performance/ ), and 
having my own curiosity of the current state of things, I wanted to dig 
in an see what the performance of APC with phar files was.

I've found some oddities in performance, and I am hoping before I do any 
deeper investigation, someone might know something.

The app is here:
https://github.com/ralphschindler/test-phar-performance-apc/

The library I am attempting to introduce to the app is Zend_Db.phar.  I 
chose this b/c I fully know the code base, and the phar clocks in at 
519844 bytes uncompressed.

It breaks down like this:
   /index.php - baseline app without addition of library
   /index-with-filesys.php - Zend_Db library extracted to filesystem
   /index-with-phar.php - Zend_Db as phar included

Without APC, on my machine, I get a slight drop off, but acceptable. 
With APC, the drop off in performance is very noticable.  Even with 
stat=0, only in a very specific usage scenario (described below) does it 
actually nullify phar vs. filesystem.


Without APC (enabled=0)
-----------------------

$ ab -H "Connection: close" -n 500 http://test.dev/index-with-filesys.php

Requests per second:    111.19 [#/sec] (mean)
Time per request:       8.994 [ms] (mean)


$ ab -H "Connection: close" -n 500 http://test.dev/index-with-phar.php

Requests per second:    87.49 [#/sec] (mean)
Time per request:       11.429 [ms] (mean)


Then APC 3.1.13 (Beta) is introduced, the app is clearly faster on the 
filesystem, but not nearly as fast one would expect in the phar version:


With APC (enabled=1, stat=1)
----------------------------

$ ab -H "Connection: close" -n 500 http://test.dev/index-with-filesys.php

Requests per second:    474.47 [#/sec] (mean)
Time per request:       2.108 [ms] (mean)


$ ab -H "Connection: close" -n 500 http://test.dev/index-with-phar.php

Requests per second:    238.84 [#/sec] (mean)
Time per request:       4.187 [ms] (mean)


With APC (enabled=1, stat=0)
----------------------------

$ ab -H "Connection: close" -n 500 http://test.dev/index-with-filesys.php

Requests per second:    529.02 [#/sec] (mean)
Time per request:       1.890 [ms] (mean)


$ ab -H "Connection: close" -n 500 http://test.dev/index-with-phar.php

Requests per second:    246.71 [#/sec] (mean)
Time per request:       4.053 [ms] (mean)




With APC (enabled=1, stat=0) (With include_path hack)
-----------------------------------------------------

If this line:

   require '../vendor/Zend_Db-2.1.0beta1.phar';

is swapped out with this (to ensure the require is relative to include):

   set_include_path('.:' . realpath(__DIR__ . '/../vendor'));
   require 'Zend_Db-2.1.0beta1.phar';

I get the following:

$ ab -H "Connection: close" -n 500 http://test.dev/index-with-phar.php

Requests per second:    522.68 [#/sec] (mean)
Time per request:       1.913 [ms] (mean)



Can someone help me make sense of all this?  Here are my questions:

   * The phar files are listed in the apc_cache_info() with >1 hits, are 
the stat's to those phar files really much slower than to filesystem files?

   * Why does the include_path trick affect performance with regards to 
phar files?




-ralph

---

## #65564 — Ralph Schindler — 2013-02-02T16:12:18+00:00

URL: https://externals.io/message/64121#65564 · In reply to: #64121

Hi all,

After re-testing this scenario against Zend Optimizer+ on OS.X in 5.4 
yesterday ...

it's worth noting that Zend Optimizer+ *does not* suffer from the same 
file stat/include_path problems that APC does when dealing with phars.

An unpacked phar to filesystem (with autoloader, using absolutely path 
with __DIR__) performs the same as phar (autoloader as stub using 
include 'phar://' . __FILE__ . '/' . $fileInPhar).

-ralph


> Hey all,
>
> After reading this post (
> http://www.reddit.com/r/PHP/comments/13uwgk/phar_performance/ ), and
> having my own curiosity of the current state of things, I wanted to dig
> in an see what the performance of APC with phar files was.
>
> I've found some oddities in performance, and I am hoping before I do any
> deeper investigation, someone might know something.
>
> The app is here:
> https://github.com/ralphschindler/test-phar-performance-apc/
>
> The library I am attempting to introduce to the app is Zend_Db.phar.  I
> chose this b/c I fully know the code base, and the phar clocks in at
> 519844 bytes uncompressed.
>
> It breaks down like this:
>    /index.php - baseline app without addition of library
>    /index-with-filesys.php - Zend_Db library extracted to filesystem
>    /index-with-phar.php - Zend_Db as phar included
>
> Without APC, on my machine, I get a slight drop off, but acceptable.
> With APC, the drop off in performance is very noticable.  Even with
> stat=0, only in a very specific usage scenario (described below) does it
> actually nullify phar vs. filesystem.
>
>
> Without APC (enabled=0)
> -----------------------
>
> $ ab -H "Connection: close" -n 500 http://test.dev/index-with-filesys.php
>
> Requests per second:    111.19 [#/sec] (mean)
> Time per request:       8.994 [ms] (mean)
>
>
> $ ab -H "Connection: close" -n 500 http://test.dev/index-with-phar.php
>
> Requests per second:    87.49 [#/sec] (mean)
> Time per request:       11.429 [ms] (mean)
>
>
> Then APC 3.1.13 (Beta) is introduced, the app is clearly faster on the
> filesystem, but not nearly as fast one would expect in the phar version:
>
>
> With APC (enabled=1, stat=1)
> ----------------------------
>
> $ ab -H "Connection: close" -n 500 http://test.dev/index-with-filesys.php
>
> Requests per second:    474.47 [#/sec] (mean)
> Time per request:       2.108 [ms] (mean)
>
>
> $ ab -H "Connection: close" -n 500 http://test.dev/index-with-phar.php
>
> Requests per second:    238.84 [#/sec] (mean)
> Time per request:       4.187 [ms] (mean)
>
>
> With APC (enabled=1, stat=0)
> ----------------------------
>
> $ ab -H "Connection: close" -n 500 http://test.dev/index-with-filesys.php
>
> Requests per second:    529.02 [#/sec] (mean)
> Time per request:       1.890 [ms] (mean)
>
>
> $ ab -H "Connection: close" -n 500 http://test.dev/index-with-phar.php
>
> Requests per second:    246.71 [#/sec] (mean)
> Time per request:       4.053 [ms] (mean)
>
>
>
>
> With APC (enabled=1, stat=0) (With include_path hack)
> -----------------------------------------------------
>
> If this line:
>
>    require '../vendor/Zend_Db-2.1.0beta1.phar';
>
> is swapped out with this (to ensure the require is relative to include):
>
>    set_include_path('.:' . realpath(__DIR__ . '/../vendor'));
>    require 'Zend_Db-2.1.0beta1.phar';
>
> I get the following:
>
> $ ab -H "Connection: close" -n 500 http://test.dev/index-with-phar.php
>
> Requests per second:    522.68 [#/sec] (mean)
> Time per request:       1.913 [ms] (mean)
>
>
>
> Can someone help me make sense of all this?  Here are my questions:
>
>    * The phar files are listed in the apc_cache_info() with >1 hits, are
> the stat's to those phar files really much slower than to filesystem files?
>
>    * Why does the include_path trick affect performance with regards to
> phar files?
>
>
>
>
> -ralph
