เทียบความเร็ว Symfony 2.7, Laravel 5.1, Drupal 8
รันบน Ubuntu 14.04, 8GB, virtual machine บน Xen Server อีกที
โค้ดเบามากๆ แค่ generate random number
Laravel 5.1:
app/Http/routes.php:
Route::get(‘lucky’,’LuckyController@index’);
app/Http/Controllers/LuckyController.php:
middleware(‘guest’);
}
public function index()
{
$number = rand(0, 100);
return ‘Lucky number: ‘.$number.”;
}
}
Symfony:
<?php
// src/AppBundle/Controller/LuckyController.php
namespace AppBundleController;
use SymfonyBundleFrameworkBundleControllerController;
use SensioBundleFrameworkExtraBundleConfigurationRoute;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentHttpFoundationJsonResponse;
class LuckyController extends Controller {
/**
*@Route("/lucky")
*/
public function numberAction()
{
$number = rand(0, 100);
return new Response(
'Lucky number: ‘.$number.”
);
}
}
Drupal 8:
modules/hello_world/hello_world.routing.yml:
hello_world.lucky:
path: ‘/lucky’
defaults:
_controller: ‘Drupalhello_worldControllerLuckyController::lucky’
_title: ‘Lucky Number’
requirements:
_permission: ‘access content’
modules/hello_world/src/Controller/LuckyController.php
trigger(); # ไม่ให้ cache ผลลัพธ์
$number = rand(0, 100);
return array(
‘#type’ => ‘markup’,
‘#markup’ => ‘Lucky number: ‘.$number.”,
//’#cache’ => [ ‘max_age’ => 0,], # ทำแบบนี้แล้วไม่เห็นมันจะไม่ cache
//’cache’ => array( ‘max_age’ => 0,), # ทำแบบนี้แล้วไม่ cache แต่ผลลัพธ์มีกรอบสี่เหลี่ยมอะไรโผล่มาเพิ่มเฉย
);
}
}
ทดสอบด้วย ab
ab -c 10 -t 3
Symfony:
Document Path: /ottos/lucky
Document Length: 42 bytes
Concurrency Level: 10
Time taken for tests: 3.002 seconds
Complete requests: 229
Failed requests: 27
(Connect: 0, Receive: 0, Length: 27, Exceptions: 0)
Total transferred: 70282 bytes
HTML transferred: 9597 bytes
Requests per second: 76.27 [#/sec] (mean)
Time per request: 131.110 [ms] (mean)
Time per request: 13.111 [ms] (mean, across all concurrent requests)
Transfer rate: 22.86 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.3 0 4
Processing: 39 128 45.8 126 279
Waiting: 39 128 45.8 126 279
Total: 39 128 45.8 126 280
ERROR: The median and mean for the initial connection time are more than twice the standard
deviation apart. These results are NOT reliable.
Percentage of the requests served within a certain time (ms)
50% 126
66% 146
75% 162
80% 169
90% 183
95% 200
98% 232
99% 252
100% 280 (longest request)
Laravel:
Document Path: /ottol/lucky
Document Length: 42 bytes
Concurrency Level: 10
Time taken for tests: 3.018 seconds
Complete requests: 111
Failed requests: 6
(Connect: 0, Receive: 0, Length: 6, Exceptions: 0)
Total transferred: 116778 bytes
HTML transferred: 4658 bytes
Requests per second: 36.78 [#/sec] (mean)
Time per request: 271.918 [ms] (mean)
Time per request: 27.192 [ms] (mean, across all concurrent requests)
Transfer rate: 37.78 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.8 1 5
Processing: 119 262 78.9 249 609
Waiting: 118 261 78.9 249 608
Total: 121 262 79.1 250 611
Percentage of the requests served within a certain time (ms)
50% 249
66% 283
75% 306
80% 330
90% 353
95% 404
98% 447
99% 473
100% 611 (longest request)
Drupal 8:
Document Path: /ottod8/lucky
Document Length: 2340 bytes
Concurrency Level: 10
Time taken for tests: 3.006 seconds
Complete requests: 78
Failed requests: 14
(Connect: 0, Receive: 0, Length: 14, Exceptions: 0)
Total transferred: 233052 bytes
HTML transferred: 182508 bytes
Requests per second: 25.94 [#/sec] (mean)
Time per request: 385.440 [ms] (mean)
Time per request: 38.544 [ms] (mean, across all concurrent requests)
Transfer rate: 75.70 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.2 1 10
Processing: 152 362 74.7 360 592
Waiting: 152 362 74.6 360 592
Total: 154 363 74.6 360 593
Percentage of the requests served within a certain time (ms)
50% 360
66% 398
75% 411
80% 414
90% 460
95% 487
98% 521
99% 593
100% 593 (longest request)
ความเร็วเรียงตามผลลัพธ์เลย Symfony < Laravel < Drupal