Hi Michael,
Thanks for the tip on the C extension. We were missing that from the
server.
However, that still just cut our time in about half. So instead of 12
seconds, the array conversion is taking about 6 seconds.
I thought it may just be a Ruby issue since it is a pretty big array.
However, if I loop through the Ruby array and save it as a new Ruby
array it takes about 1/10th of a second, so it is definitely something
to do with the cursor.
Below is a quick function I created to demonstrate what I am talking
about. Here are the results of running this on our server:
>> mongo_array_timer
FROM MONGO CURSOR
Array size: 1083; Duration to convert to array: 6.169699
FROM RUBY ARRAY
Array size: 1083; Duration to convert to new array: 0.123068
The Mongo to array conversion is < 1 second if we select an individual
column, but it is > 15 seconds if I do not specify a select clause
since Person includes some embedded objects.
Anything else we can do to improve performance?
- Jim
def mongo_array_timer
p=Person.find(:all, :select=>Person.field_names)
p2=[]
set_time = Time.now
p.each {|pp| p2<<pp} ;nil
puts "FROM MONGO CURSOR"
puts "Array size: #{p2.size}; Duration: #{Time.now - set_time}"
set_time = Time.now
p3=[]
p2.each {|pp| p3<<pp} ;nil
puts "FROM RUBY ARRAY"
puts "Array size: #{p3.size}; Duration: #{Time.now - set_time}"
end
On May 29, 12:01 pm, Michael Dirolf <
m...@10gen.com> wrote:
> Another thing that will affect performance is the optional C extension
> - do you have this installed? Instructions are in the README:
>
>
http://github.com/mongodb/mongo-ruby-driver/blob/d679a17478081fecfd84...