Chinaunix

标题: MongoDB Ruby 客户端升级,性能大幅提升 [打印本页]

作者: feiyang10086    时间: 2012-02-22 18:39
标题: MongoDB Ruby 客户端升级,性能大幅提升
MongoDB Ruby 客户端升级,性能大幅提升




最近MongoDB的Ruby客户端进行了一次升级,主打性能增强,官方的benchmark显示速度达原来的2倍左右。下面是其官方原文及benchmark:

原地址:http://github.com/mongodb/mongo-ruby-driver/pull/3

The Ruby driver was quite inefficient with handling data. Strings (read from the network or passed by the user) were being unpacked into arrays all over the place and vice versa. We’ve modified the driver to work with strings instead of byte arrays as much as possible. Most notably: ByteBuffer has been rewritten to use a binary string as underlying storage object instead of an array.

The Ruby 1.8 implementation of BSON::OrderedHash was inefficient: it uses a Set even though it’s not necessary. We removed the dependency on Set and greatly improved OrderedHash’s 1.8 performance.

The end result is a driver that’s 274% faster on Ruby 1.8 and 204% faster on Ruby 1.9. We used the following benchmark:

requests = Mongo::Connection.new.db('foobar').collection('requests')
query = { :_id => "6d61bbc7e32795e7ace8b98e8e83961cb8e3ee53" }
40000.times do
    requests.find(query, :limit => -1) do |cursor|
        cursor.next_document
    end
endOriginal runtime: 74.0s (Ruby 1. / 33.9s (Ruby 1.9)
New runtime: 25.8s (Ruby 1. / 16.7s (Ruby 1.9)



作者: 小忻黑夜    时间: 2012-02-24 17:27
谢谢分享




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2