English 中文(简体)
Handling large ActiveRecord object set as binary data
原标题:

I have an issue with manipulating large number of record objects of type ActiveRecord model(Records are extracted from a complex operation but from the same table) and I want to pass that object set around between controller actions. So I have couple of solutions but is wage about which way to choose. Simpler but uglier solution is to save it in sessions. But as I know saving large object set in sessions clearly slows down application performance because of frequent serialization and de-serialization process(Serialization is time consuming I guess from Web services - SOAP and binary formatting). Second option which seems to be promising is saving all these ActiveRecord model objects as a blog in the database, and with one query we can retrieve all and can do the necessary operations with that dataset. But I don t know how to iterate through all objects after retrieving it from the database because it is still in binary object format. Calling inspect method shows all attributes and values but I am totally perplexed. Can anyone tell me how to save ActiveRecord model type objects as a single record binary obejct and retrieve it and go through the dataset. Do I need encoding like Base64 ?. Finally would memcached yield desired result?? or at least any links that can follow to solve this ?

And sorry for the lengthy question and thanks in advance.

最佳回答

The answer, and I hate saying this, is that probably the method is flawed. Is it going to take more time to query for this exact data again or to load up a BLOB row and unserialize it? My guess is that it takes roughly the same time without indexes but with indexes you may be able to get your entire resultset from the DB faster than even loaded the BLOB without even the unserialize call.

Now maybe I m wrong about that, but certainly the amount of data coming back is about the same so a large chunk of the db time is exactly the same.

Memcached would certainly prove helpful here but only in the same way that the query cache (assuming you re using MySQL) would be helpful. Repeated queries for the same thing should be returned laser fast by either method assuming the cache in either case is large enough to fit the object.

But you are correct that storing in the session is a bad way and BLOB is probably also at best about the same as just doing the query again and letting the query cache return it.

But just to cover all the bases, how big is the total dataset vs how much is coming back and how long are you seeing the queries take? I m guessing this post is really about performance but is clouded by implementational details.

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签