Press "Enter" to skip to content

Yaf 3.1: A 10% Performance Boost

Yaf (Yet Another Framework) was the first PECL extension I ever released, and the start of my journey into PHP core maintenance. I've always had a soft spot for it. Over the past 8-plus years Yaf has also won the affection of quite a few friends. Of course, Yaf still has plenty of shortcomings — but after all, it's aimed mainly at performance scenarios and can't satisfy every need.

Since Yaf == performance, I used the time at home during the pandemic to do another round of optimization on Yaf, hoping to push performance a bit further.

The main changes:

1. Refactored Yaf_Loader::autoload
2. Rewrote the core logic of Yaf_Route_Static/Rewrite
3. is_localnamespace now uses hash matching instead of the previous string matching
4. Rewrote most of the logic to avoid memory allocation

Because the changes are fairly substantial, I also bumped the version, from 3.0.9 to 3.1.0. Download: Yaf At PECL

So, as usual, let's measure the performance change. First we use tools/cg/yaf_cg from the Yaf source to generate a test:

tools/cg/yaf_cg benchmark /var/www/html/yaf

Test server configuration:

32GB RAM 
Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz * 24
Nginx 12 processes
PHP-FPM 24 processes

We first test with yaf-3.0.9 (200 concurrent):

ab -n 100000 -c 200 http://10.33.1.23:8000/yaf/

Server Software:        nginx/1.9.7
Server Hostname:        10.33.1.23
Server Port:            8000

Document Path:          /yaf/
Document Length:        26 bytes

Concurrency Level:      200
Time taken for tests:   17.950 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      19100000 bytes
HTML transferred:       2600000 bytes
Requests per second:    5571.17 [#/sec] (mean)
Time per request:       35.899 [ms] (mean)
Time per request:       0.179 [ms] (mean, across all concurrent requests)
Transfer rate:          1039.15 [Kbytes/sec] received

Then we test with yaf-3.1.0 (200 concurrent):

ab -n 100000 -c 200 http://10.33.1.23:8000/yaf/

Server Software:        nginx/1.9.7
Server Hostname:        10.33.1.23
Server Port:            8000

Document Path:          /yaf/
Document Length:        26 bytes

Concurrency Level:      200
Time taken for tests:   16.046 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      19100000 bytes
HTML transferred:       2600000 bytes
Requests per second:    6232.05 [#/sec] (mean)
Time per request:       32.092 [ms] (mean)
Time per request:       0.160 [ms] (mean, across all concurrent requests)
Transfer rate:          1162.42 [Kbytes/sec] received

As you can see, QPS jumped from 5571 to 6232 — an 11% improvement.

Of course, for a real-world project this gain may not be very noticeable; I'm just illustrating the version-to-version comparison here. 🙂

Also, since this round changed a fairly large amount of code, even though I've tested it as thoroughly as I can, problems may still slip through. If you run into any issue in actual use, feel free to file an Issue on Github, or just email me at laruence at php dot net. One note: don't put attachments in the email — PHP's mail system filters out emails with attachments.

Enjoy!

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.