Ruby on Rails is famous for its elegant MVC Architecture, which is so attractive and beautiful, while CakePHP is one of the common frameworks in PHP development. If you don't want to be bound to the traditional PHP brick-and-mortar development, you can try to switch to the MVC Architecture, but the performance and deployment problems of Rails have been worrying.
The topics of comparison between the two have different opinions on the Internet, and few have seen objective and persuasive arguments and fully simulate the stress assessment in the actual environment. As an important decision of architecture selection, we cannot be human or cloud, nor can we imagine it out of thin air. We must have sufficient test data to help make the right decisions.
The heart was not as good as action, and immediately started to arrange a simulation environment test. The first step is to design a test plan:
Stress Testing focuses On the efficiency of Ruby On Rails and CakePHP. Therefore, the same Nginx production environment is used, but all database operations are avoided to avoid the impact of the bottleneck On the database.
The main part of the code is to output 128000 4-digit decimal random numbers to simulate page data output totaling about KB. The invocation commands are very basic and fair for script testing.
However, since it is a virtual high-pressure test, there should be a simulation alternative to the time overhead of database read/write operations in the actual environment, so the server with high data pressure can be simulated through Sleep Ms. Of course, we all know that Sleep has no real cpu overhead, so it will not affect the fairness of the test results.
The test tool uses the classic apacheworkflow. Successively tested the medium pressure of 10 concurrent 100 requests (-c 10-n 100) and 200 concurrent 5000 requests (-c 200-n 5000.
Environment
- OS: FreeBSD 8.1
- CPU: Intel 4 Core 2
- RAM: 4 GB memory
- PHP environment: nginx + php-fpm (5.3.3) + APC
- Rails environment: nginx + passenger + Ruby (1.8.7) on Rails (3.0.0)
- All software is installed using ports
Optimized fpm Configuration:
- pm.max_children = 1000
- pm.start_servers = 20
- pm.min_spare_servers = 5
- pm.max_spare_servers = 1000
Passenger's optimized configuration nginx. conf ):
Passenger_max_pool_size 300; // The maximum allowed value of 4 GB memory, and passphrase cannot be started after append.
Create a Test App using a Rails script:
Rails new dummy
Ruby on Rails code:
- // app/controller/test_controller.rb
- class TestController < ApplicationController
- def index
- sleep(0.2)
- end
- end// app/views/test/index.html.rb
- <% 128000.times do %><%=rand(8999)+1000%><% end %>
PHP code:
- // vsruby.php
-
-
- usleep(200000);
- echo "";
- for($i = 0; $i < 128000;$i++)
- {
- echo mt_rand(8999,9999);
- }
-
- echo "";
CakePHP code:
- // CakePHP
- // app/controller/test_controller.php
-
- class TestController extends AppController {
- var $name = 'Test';
- function index()
- {
- usleep(200000);
- }
- } // CakePHP
- // app/views/test/index.ctp
-
- for($i = 0; $i < 128000;$i++)
- {
- echo mt_rand(8999,9999);
- }
- ?>