public
Last active

klein test

  • Download Gist
gistfile1.md
Markdown

github.com/chriso/klein.php benchmarks

The following example highlights how klein.php can route by regular expression and render dynamic content at 2500+ requests per second.

Why is it so much faster than other PHP routers and frameworks?

xhprof was used to optimise the route matching process. Here's an example profile for a single request, and here's the associated callgraph.

Test Files

index.php

<?php require 'klein.php';

respond('/[:name]?', function ($request, $response) {
    $response->name = $request->param('name', 'world');
    $response->render('hello.phtml');
});

dispatch();

hello.phtml

Hello <?php echo $this->name ?>

Test Setup

Hardware: Macbook Pro (Core 2 Duo @ 2.26GHz + 4GB DDR3 Memory)

Software: Apache 2.2.17 and PHP 5.3.6 (mod_php) - APC is enabled (stat = 1)

Test Results

ab -n 10000 -c 10

Server Software:        Apache/2.2.17
Server Hostname:        localhost
Server Port:            80

Document Path:          /chris
Document Length:        11 bytes

Concurrency Level:      10
Time taken for tests:   3.954 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      2320000 bytes
HTML transferred:       110000 bytes
Requests per second:    2528.89 [#/sec] (mean)
Time per request:       3.954 [ms] (mean)
Time per request:       0.395 [ms] (mean, across all concurrent requests)
Transfer rate:          572.95 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0       9
Processing:     1    3   2.9      3      92
Waiting:        0    3   2.7      3      91
Total:          1    4   2.9      4      92

Percentage of the requests served within a certain time (ms)
  50%      4
  66%      4
  75%      4
  80%      4
  90%      5
  95%      6
  98%      9
  99%     13
 100%     92 (longest request)

ab -n 10000 -c 20

Server Software:        Apache/2.2.17
Server Hostname:        localhost
Server Port:            80

Document Path:          /chris
Document Length:        11 bytes

Concurrency Level:      20
Time taken for tests:   3.985 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      2321624 bytes
HTML transferred:       110077 bytes
Requests per second:    2509.32 [#/sec] (mean)
Time per request:       7.970 [ms] (mean)
Time per request:       0.399 [ms] (mean, across all concurrent requests)
Transfer rate:          568.92 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   1.2      0      22
Processing:     1    7   2.6      7      85
Waiting:        0    6   2.4      6      55
Total:          2    8   2.5      7      87

Percentage of the requests served within a certain time (ms)
  50%      7
  66%      8
  75%      8
  80%      8
  90%     10
  95%     11
  98%     14
  99%     17
 100%     87 (longest request)

ab -n 10000 -c 50

Server Software:        Apache/2.2.17
Server Hostname:        localhost
Server Port:            80

Document Path:          /chris
Document Length:        11 bytes

Concurrency Level:      50
Time taken for tests:   4.156 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      2323480 bytes
HTML transferred:       110165 bytes
Requests per second:    2406.31 [#/sec] (mean)
Time per request:       20.779 [ms] (mean)
Time per request:       0.416 [ms] (mean, across all concurrent requests)
Transfer rate:          546.00 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   1.8      1      32
Processing:     3   19  15.5     17     247
Waiting:        2   18  13.6     16     240
Total:          4   21  15.4     19     250

Percentage of the requests served within a certain time (ms)
  50%     19
  66%     19
  75%     20
  80%     21
  90%     22
  95%     25
  98%     37
  99%     53
 100%    250 (longest request)

Are you running this using Apache + mod_php ?

Here it is with PHP+FPM and Nginx. Running in a Linux VM on my Macbook Pro. C2D 2.66ghz.

It's pretty fast still. I notice that PHP+FPM, FastCGI and Nginx is a bit slower than Apache+mod_php.

ab -n 10000 -c 2 http://localhost:84/test


Server Software:        nginx/0.8.54
Server Hostname:        localhost
Server Port:            84

Document Path:          /test
Document Length:        10 bytes

Concurrency Level:      2
Time taken for tests:   6.146 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      1680000 bytes
HTML transferred:       100000 bytes
Requests per second:    1627.19 [#/sec] (mean)
Time per request:       1.229 [ms] (mean)
Time per request:       0.615 [ms] (mean, across all concurrent requests)
Transfer rate:          266.96 [Kbytes/sec] received

Try bumping up the concurrency to 20 or 30. I've seen a few benchmarks for Apache/mod_php vs. Nginx/PHP-FPM and they usually tie on RPS with the latter using significantly less memory. See how you go

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.