2

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:

  1. A table with the columns row, column and value. 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).
  2. Store the matrix serialized in a text field/column. Do you have any ideas how it compares to 1. from a performance standpoint?
  3. 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).
4

1 回答 1

0

任何类型的 ACID 兼容存储的按需写入和检索性能都将成为一个问题。作为最佳实践,我建议采用缓存重策略,将矩阵保存在内存中,如果您需要跨多个服务器,也许可以使用 memcache。然后,您可以从请求周期中取出读取和写入,随后您不必太在意写入性能,并且可以使用任何东西(例如 MySQL 中的文本字段或其他任何东西)。

为此,我建议编写一个执行以下操作的自定义矩阵类:

  • 检查缓存以获取其数据的副本,如果不可用,则从数据库加载并填充缓存。
  • 更新缓存副本时异步写入数据库。
  • 为您的代码提供优化的数据接口
于 2013-03-27T16:44:24.480 回答