<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d4684235500622716427\x26blogName\x3dCaiwangqin\x27s+blog\x26publishMode\x3dPUBLISH_MODE_HOSTED\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://blog.caiwangqin.com/search\x26blogLocale\x3dzh_CN\x26v\x3d2\x26homepageUrl\x3dhttp://blog.caiwangqin.com/\x26vt\x3d3393395200455623441', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Caiwangqin's blog

Focus on Cloud Service, Smart Hardware, Architecture, Technic and beyond…

使用 hdparm 测试硬盘速度


使用 hdparm 测试硬盘速度:

hdparm linux 测试硬盘及改变硬盘设定的指令

#hdparm -t /dev/hda < - - - 测试硬盘/dev/hda 的速度

如果是scsi 的话/dev/sda , /dev/sdb

#hdparm -c 1 /dev/hda < - - - 开启ide 硬盘的32bit

#hdparm -d 1 /dev/hda < - - - 开启dma mode


以下是我对三台安装 Debian 操作系统的计算机所做的测试结果:

1×250Gb STAT PC

# hdparm -t /dev/sda2

Timing buffered disk reads: 264 MB in 3.01 seconds = 87.60 MB/sec

2×140Gb SCSI RAID1

# hdparm -t /dev/md0

Timing buffered disk reads: 226 MB in 3.02 seconds = 74.83 MB/sec

# hdparm -t /dev/md2

Timing buffered disk reads: 208 MB in 3.02 seconds = 68.97 MB/sec


# hdparm -t /dev/sda1

Timing buffered disk reads: 226 MB in 3.01 seconds = 75.00 MB/sec
# hdparm -t /dev/sdb1

Timing buffered disk reads: 344 MB in 3.03 seconds = 113.71 MB/sec
# hdparm -t /dev/sdb2

Timing buffered disk reads: 318 MB in 3.02 seconds = 105.32 MB/sec


posted by Jesse Cai, 上午11:15 | Permalink | 0 comments |

Switch Rails cache files from file_store to ramfs_store


we found the problem of my last post, like this post, Innodb Locks cause something else spend long time in transaction.

It is expire_action from disk in our case. we used action_cache plugin in rails application, we have multiple languange versions of zh and en, so we write expire_reg_action to expire both cache when content after_save, this will spent long time when delete cache from huge files.

so we switch Rails cache files from file_store to ramfs_store temporary, it works perfect right now.

mount -t ramfs ramfs /home/yay/rails_app/current/tmp/cache

reference :

  1. rails缓存机制的几个问题

  2. Innodb Locks, ActiveRecord and acts_as_ferret Problem


posted by Jesse Cai, 上午7:30 | Permalink | 0 comments |

Try Phusion Passenger/mod_rails

chinaonrails.com上看到 bd7lx 发布的 简化部署插件 乘客搭上阿帕奇Phusion Passenger (a.k.a. mod_rails for Apache), 对其部署的简单和性能都欣喜不已,但官方的文章不一定真实可靠,特自行测试一番,Let’s go.


Linux p1 2.6.24-1-amd64 #1 SMP Mon Feb 11 13:47:43 UTC 2008 x86_64 GNU/Linux


apt-get install apache2

apt-get install apache2-prefork-dev

apt-get install libapr1-dev

apt-get install apache2-mpm-prefork

gem install passenger


我的 httpd.conf 文件

LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so
RailsSpawnServer /var/lib/gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server
RailsRuby /usr/bin/ruby1.8

<VirtualHost *:80>
ServerName dailybuild.p1.cn
DocumentRoot /home/yay/delta/project1/current/public

<Directory “/home/yay/delta/project1/current/public”>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all


  1. mod_rails 还不支持所有的plugin , 如: file_column.

  2. 对 public/ 目录下的静态文件,需要多一点配制,不要把思维停止在好看的视频上。

  3. 要用于 production 环境,需要做更多的测试,如: httperf。更多测试数据稍后分享。


posted by Jesse Cai, 上午4:46 | Permalink | 0 comments |

Change MySQL table engine from InnoDB to MyISAM


there is something wrong with Innodb transactions, i found it from rails production log below:

ActiveRecord::StatementInvalid (Mysql::Error: Lock wait timeout exceeded; try restarting transaction: UPDATE articles SET `created_at` = ‘2008-04-23 17:22:42′, `rating_count` = 0, `votes` = 0, `title` = ‘P1派对衣着榜4月第2周’, `content_text` = ‘’, `award_id` = NULL, `status` = 0, `category_id` = 1, `image` = NULL, `user_id` = 18098, `score` = 0.0, `description` = ‘’, `layout_id` = NULL, `imagethumb` = NULL, `sequence` = 100, `attachment_id` = NULL, `counts` = 0, `city_id` = 1, `counts_24h` = 0 WHERE id = 910):

i have tried to resolve this problem for many hours, but can not found any directions, someone suggest me change InnoDB to MyISAM, so i changed MySQL table engine from InnoDB to MyISAM. do more testing…

alter table articles engine=MyISAM;

I have done this progress for resolve this problem:

  • check mysql slow log , lot’s of sql go into mysql slow log, cause we used many derived tables in query, it seems derived tables can not use index(Derived Tables and Views Performance). but the query time is fast, almost all query execute in 0.0x sec.

long_query_time = 2
log_slow_queries = ON

  • stop batch update sql statement, like update online

  • improve Update code and create progress

if you already fixed this problem, please let me know. thanks.


posted by Jesse Cai, 上午10:28 | Permalink | 0 comments |

Improve rails performance for P1.cn


最近由于 P1.cn 业务的推广,我们的 rails application 在以下几个方面遇到考验,分享一下我们处理这个问题的方法。

1. rails performance


  1. rails 的相关 plugin 性能及差,如 acts_commentable ,去掉这类的 plugin

  2. 改变数据库结构,使部分数据冗余,如 nickname, 使数据库关联查询变少

  3. memcached: cache db query in memcached, use acts_as_cached, cached_model, QueryCache (like javaeye)

  4. action cache: action cache 所有show action

  5. fragment cache: 少部分 privacy 页面使用

2. db cluster

master/slave mysql database, 现在是 one master, one slave, 计划结合 MySQL Proxy 做 one master , multiple slave

3. distributed file storage

用户图片增长速度非常快,我们感觉到了 storage 的压力,这是个即将到来的问题,但我不确定使用哪种方式来分布文件存储,我了解以下几种方式,但没有应用经验:

  1. NFS (大部分人不建议使用)

  2. DRBD - raid 1, 没有使用经验

  3. mogile fs - 文档几乎没有

  4. SAN

4. Nginx + mongrel cluster or something else

我们现在使用的是 Nginx + mongrel cluster , 发现 mongrel 在处理时,如果发生了一次异常,后续的请求都会被阻塞。以下是我们的处理方式:

  1. Swiftiply event mongrel instead of mongrel

  2. more mongrel running on different servers



posted by Jesse Cai, 上午5:08 | Permalink | 0 comments |