开发者

Matrix storage in Rails?

I'm wondering what's the best way to handle a huge matrix in Rails 3. This matrix would store distances between points (it's symetric).

Points could be added anytime so the matrix could be frequently updated.

I see two ways:

  • storing values in database and get distances through db requests开发者_开发百科 (easy but a bit slow)
  • storing values in a file and put this file in cache (could be hard to update)

Thoughts?

PS: I'm packaging this for a new release of my gmaps4rails gem (dedicated to make gmaps easy for rails users)


If you have to store a unique and big matrix, I would recommend doing it in a separate table (column/line/value). It will scale better than with a file, and :

  • You can access and update individual cell more easily
  • You mentioned using a file to cache your matrix, but if the need arise you can also fetch your entire table to cache your matrix
  • You can update rows, columns, and sub-matrixes with well formed queries

If you encounter performance problems when making your matrix grow, take a look at the activerecord-import library. It will help you batch insert data in your matrix.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜