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
end

Original runtime: 74.0s (Ruby 1.8) / 33.9s (Ruby 1.9)
New runtime: 25.8s (Ruby 1.8) / 16.7s (Ruby 1.9)

anyShare一切看了好文章不转的行为,都是耍流氓!
          

无觅相关文章插件,快速提升流量

分类 MongoDB · tag ,