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

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

问题描述

我使用Cassandra 1.2.2。我发现它很容易使用杰克逊映射我的对象来回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列,您只需插入名为地址的列。如果你有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天全站免登陆