In my Ruby On Rails app I have to store (relative) large matrices of about 300x300 elements (float values, mostly different) per document. On every retrieval of a document the full matrix has to be loaded for custom calculations. The matrices are also updated quite often (so that write performance and memory caching is an issue, too).
What's a good way to store such matrices (performance wise)? Some alternatives that come to my mind:
- A table with the columns
row
,column
andvalue
. But I guess fetching and storing a whole matrix (with about 90000 cells) is not a good idea to do on every request (some memory caching will help). - Store the matrix serialized in a text field/column. Do you have any ideas how it compares to 1. from a performance standpoint?
- Use some document database (e.g. Mongo) and store the whole matrix inside one field of the document (not sure where the benefit in comparison to 2. is).