考虑将序列化的 java 对象作为 JSON 存储到 cassandra 中.有什么收获? [英] Thinking of storing serialized java objects into cassandra as JSON. What is the catch?

查看:26
本文介绍了考虑将序列化的 java 对象作为 JSON 存储到 cassandra 中.有什么收获?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Cassandra 1.2.2.我发现使用 Jackson 将我的对象映射到 json 和 java 以存储在数据库中非常容易.我实际上很想对我的所有数据执行此操作.我的问题是,这是个好主意吗?对我的应用程序这样做有什么缺点.我的第一个猜测可能是更多的处理开销,但果汁值得榨吗?还有我需要了解的其他缺点吗?

I am using Cassandra 1.2.2. I am finding it so easy to use Jackson to map my objects to and fro json and java for storing in database. I am actually tempted to do this to all of my data. My question is, Is this a good idea? What are the disadvantages of doing this to my application. My first guess is probably more processing overheads but is the juice worth the squeeze? and are there any other disadvantages that i need to know about?

推荐答案

一个缺点是要修改原始数据,反序列化,修改,序列化,写出整个对象.在 Cassandra 中,写入比读取高效得多,因此尽可能避免在写入之前读取是有益的.

One disadvantage is that to modify the data you have to read in the original, deserialize, make your change, serialize and write out the whole object. In Cassandra, writes are much more efficient than reads so it is beneficial to avoid reads before writes if possible.

另一种方法是为 JSON 中的每个字段使用单独的列.您可以对多维数据使用复合列.

The alternative is to use separate columns for each field in your JSON. You can use composite columns for multi-dimensional data.

所以如果你有数据:

{
  name: "fred"
  address: "some town"
  age: 42
}

并且您想更改地址,如果您将这些作为单独的 Cassandra 列,您只需插入一个名为 address 的列.如果您将 JSON 序列化,您将不得不做更多的工作.如果您的数据是一次性写入,则这不适用.

and you wanted to change the address, if you had these as separate Cassandra columns you'd just insert a column called address. If you had the JSON serialized you'd have to do much more work. This doesn't apply if your data is write-once.

即使您的数据是一次性写入的,如果您只想从数据中读取一个字段,如果单独存储,您也可以只读取该列,而不是读取整个内容并反序列化.这仅适用于您想要读取部分数据的情况.

Even if your data is write-once, if you just wanted to read one field from the data you can just read that column if stored separately rather than reading the whole thing and deserializing. This only applies if you want to read parts of your data.

总而言之,如果您必须更新数据或只想一次读取部分内容,则使用单独的列可能会带来显着的性能优势.

In conclusion, there could be significant performance advantages to using separate columns if you have to update your data or if you only want to read parts at once.

这篇关于考虑将序列化的 java 对象作为 JSON 存储到 cassandra 中.有什么收获?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆