记录阿里巴巴QA架构组成长点滴。2008年关键词为效率,技术,影响力!QA/测试架构师定义:开发和设计测试框架测试库;纵横全局的考虑产品的功能,设计复杂的测试系统;负责研发某一项特定的测试技术;为公司考虑如何提高测试效率。领导公司测试技术的发展和测试策略上的方向,关注整个公司的测试部门的问题,前瞻性的考虑未来的版本的测试策略和技术。测试架构师计划/设计测试平台,关注着产品的测试过程,提供咨询服务,影响到公司内的测试机构测试社区,以及开发机构等,对产品各个方面施加深远而正确的影响,最终提高整体软件质量。

大型RAILS应用(网络考试)性能测试与调优过程

上一篇 / 下一篇  2008-06-30 11:24:30 / 个人分类:性能测试与容量规划

一 背景介绍

  系统为上海一家IT公司rail on ruby快速开发出来的网络考试系统。核心功能:登录、考试。考试分为html的单/多选题,flash展现的操作题。在内部一次模拟考试中,系统曾经出现性能故障,导致无法正常做题。
  
二 系统架构分析

 接到性能测试任务,第一感觉:要很注意每一个细节,包括用户行为模拟、场景设计合理全面等。
 
 咨询了解到系统架构为: ruby+rails+ apache2.x+mysql5。
 
 登录系统:登录web与登录的DB分开
 考试系统:考试web与考试DB 集中部署在一台机器上。答一道题目即插入数据库


三 用户行为分析

1 考试要求在 0~45分钟内考试完毕
2 多数考生一般先做选择题,再做操作题;少部分反之。
3 多数考生做完全部题目,少部分考生中途就提交结束答卷
4 题目可以回退或者选择任意一题目修改答案
5 同一个考生在提交答卷后,不能再答题

由于系统更加细致的数据没有log分析,就简单采用80-20原则随机模拟。

四 脚本开发小技巧
1  随机模拟脚本
init.c 加入 srand(time(NULL));

action.c 加入  rand() % 100;
 
2 cookie处理

服务器端检查cookie信息。
加入web_add_auto_header 确保后续每一个http请求都自动把cookie加入header

3 并发处理
由于一次性考试,故并发数没有按考试人数缩放,但考试按照一定的随机think time等待。
 
五 系统调优

 主要的线索是environment.rb定义的config.log_level 生成product.log,
以及rail bench。

(一) 精简登录首页
 
1 登录:削减登录网页,很轻量级,仅仅包含Login 窗口

(二) flash下载模式变更
 原来做操作题目,该flash操作题才下载到客户端。
为了减轻并发下载flash的网络流量压力,变更为在登录成功后,客户端javascrīpt采用ajax技术(xmlhttpquest)随机1-60秒内后台主动下载flash试题到客户端。改变网络流量瞬间飙升的情况。

(三) apache2.0 调整httpd.conf 关键参数以及加载mod_proxy 、mod_mem_cache

1 apache httpd work mpm模式。
增加 MaxClient。

<IfModule worker.c>
StartServers         2
ServerLimit         2500
MaxClients         2500
MinSpareThreads     75
MaxSpareThreads     255
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>


2 上apache 负载均衡模块 mod_proxy

ProxyRequests off

<Proxy balancer://kaoshi>
BalancerMemberhttp://localhost:6000
BalancerMemberhttp://localhost:6001
BalancerMemberhttp://localhost:6002
BalancerMemberhttp://localhost:6003
BalancerMemberhttp://localhost:6004
BalancerMemberhttp://localhost:6005
</Proxy>
ProxyPass /images !
ProxyPass /stylesheets !
ProxyPass /javascrīpts !
ProxyPass /expert_photos !
ProxyPass /uploads !

ProxyPass / balancer://kaoshi/
ProxyPassReverse / balancer://kaoshi/
ProxyPreserveHost on


3  LoadModule mem_cache_module modules/mod_mem_cache.so加载cache模块

       CacheEnable mem /
       MCacheMaxStreamingBuffer 65536
       MCacheRemovalAlgorithm LRU
       MCacheSize 3000000
       MCacheMaxObjectCount 256000
       CacheIgnoreHeaders None
       CacheIgnoreCacheControl On
       MCacheMinObjectSize 1
       MCacheMaxObjectSize 2560000
       CacheDefaultExpire 10

 

(四)  rails 相关调整


1 变更默认连接器为C-based MySQL library mysql-2.7。
2  直接写SQL不用activeRecord 接口。
3  修改mogrel 服务参数

mongrel_cluster.yml

cwd: /home/www/kaoshi/current
port: "6000"
environment: production
address: 0.0.0.0
servers: 7


4 rails负载均衡


[app@b2bsearch114 controllers]$ pwd
/home/app/download/match_export/app/controllers

class ExamsController < ApplicationController
  IPS = %w(10.0.6.91 10.0.6.91 10.0.6.91 10.0.6.91 10.0.6.91 10.0.6.91)

  def host
    index = (session["no"] || 1) %  IPS.size
    render :text => IPS[index]
  end

5 rails 部署Memcached缓存模块


(五)  数据库结构以及SQL 调优

调整MYSQL配置文件、以及增加部分字段索引之后,iowati%从20%下降到0.4%
祥见
http://nnix.blogbus.com/logs/14824821.html
/bin/sh /usr/bin/mysqld_safe --user=mysql

 [root@aligame etc]# vi my.cnf

[client]
#password       = your_password
port            = 3306
socket          = /var/lib/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /var/lib/mysql/mysql.sock
skip-locking
key_buffer = 64M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
thread_concurrency = 8
query_cache_size = 64M
event_scheduler=1
lower_case_table_names=1
max_connections=200
back_log=512
default-character-set=utf8

log_slow_queries
log_long_format
long_query_time=1
server-id       = 1
#innodb_data_file_path = ibdata1:1025M;ibdata2:256M:autoextend
innodb_buffer_pool_size = 1024M
innodb_max_dirty_pages_pct = 90
innodb_additional_mem_pool_size = 16M
#innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_log_files_in_group = 2
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
innodb_file_io_threads = 4
innodb_thread_concurrency = 8

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

 

这 log_slow_queries,log_long_format,long_query_time=1 慢的查询语句将被打印

在目录下可见*slow.log文件记录可能有性能问题的SQL


七 小结
 
   本次rails程序从应用程序调优、APACHE配置与调优、MYSQL索引与SQL优化多个细节提升性能。
调整从最显著的一个瓶颈(apache Maxclient->Mysql SQL)开始的,一次仅调整一个。
  本次调优一个环节后,瓶颈从一个环节转移到另外一个环节。


 


TAG: rails 性能 测试 调优 mysql apache 性能测试与容量规划

 

评分:0

我来说两句

日历

« 2024-04-18  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 154142
  • 日志数: 163
  • 文件数: 1
  • 建立时间: 2008-02-26
  • 更新时间: 2008-12-10

RSS订阅

Open Toolbar