Horizontal stress testing: Ruby on Rails PK CakePHP (1)

Source: Internet
Author: User
Tags usleep ruby on rails

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

 
 
  1. OS: FreeBSD 8.1
  2. CPU: Intel 4 Core 2
  3. RAM: 4 GB memory
  4. PHP environment: nginx + php-fpm (5.3.3) + APC
  5. Rails environment: nginx + passenger + Ruby (1.8.7) on Rails (3.0.0)
  6. All software is installed using ports

Optimized fpm Configuration:

 
 
  1. pm.max_children = 1000 
  2. pm.start_servers = 20 
  3. pm.min_spare_servers = 5 
  4. 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:

 
 
  1. // app/controller/test_controller.rb  
  2. class TestController < ApplicationController 
  3.   def index  
  4.     sleep(0.2)  
  5.   end  
  6. end// app/views/test/index.html.rb  
  7. <% 128000.times do %><%=rand(8999)+1000%><% end %> 

PHP code:

 
 
  1. // vsruby.php  
  2.  
  3. usleep(200000);  
  4. echo "";  
  5. for($i = 0; $i < 128000;$i++)  
  6. {  
  7.   echo mt_rand(8999,9999);  
  8. }  
  9.  
  10. echo ""; 

CakePHP code:

 
 
  1. // CakePHP  
  2. // app/controller/test_controller.php  
  3.   class TestController extends AppController {  
  4.    var $name = 'Test';  
  5.    function index()  
  6.    {  
  7.     usleep(200000);  
  8.    }  
  9.   } // CakePHP  
  10. // app/views/test/index.ctp  
  11. for($i = 0; $i < 128000;$i++)  
  12. {  
  13.   echo mt_rand(8999,9999);  
  14. }  
  15. ?> 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.