最近有很多关于卡桑德拉的话题。

Twitter, Digg, Facebook等都在使用它。

什么时候有意义:

使用卡桑德拉, 不用卡桑德拉,还有 使用RDMS而不是Cassandra。


当前回答

在这里,我将重点介绍一些重要的方面,这些方面可以帮助你决定是否真的需要卡桑德拉。这个清单并不详尽,只是我脑海中最重要的一些观点

Don't consider Cassandra as the first choice when you have a strict requirement on the relationship (across your dataset). Cassandra by default is AP system (of CAP). But, it supports tunable consistency which means it can be configured to support as CP as well. So don't ignore it just because you read somewhere that it's AP and you are looking for CP systems. Cassandra is more accurately termed “tuneably consistent,” which means it allows you to easily decide the level of consistency you require, in balance with the level of availability. Don't use Cassandra if your scale is not much or if you can deal with a non-distributed DB. Think harder if your team thinks that all your problems will be solved if you use distributed DBs like Cassandra. To start with these DBs is very simple as it comes with many defaults but optimizing and mastering it for solving a specific problem would require a good (if not a lot) amount of engineering effort. Cassandra is column-oriented but at the same time each row also has a unique key. So, it might be helpful to think of it as an indexed, row-oriented store. You can even use it as a document store. Cassandra doesn't force you to define the fields beforehand. So, if you are in a startup mode or your features are evolving (as in agile) - Cassandra embraces it. So better, first think about queries and then think about data to answer them. Cassandra is optimized for really high throughput on writes. If your use case is read-heavy (like cache) then Cassandra might not be an ideal choice.

其他回答

NoSQL的一般思想是,您应该使用最适合您的应用程序的数据存储。如果您有一个财务数据表,请使用SQL。如果您的对象需要复杂/缓慢的查询才能映射到关系模式,请使用对象或键/值存储。

当然,你遇到的任何现实问题都处于这两个极端之间,没有一个解决方案是完美的。您需要考虑每个存储的功能以及使用其中一个的后果,这将非常具体于您试图解决的问题。

除了这里的其他答案之外,沉重的单个查询与无数的轻查询负载是另一个需要考虑的问题。在nosql风格的DB中自动优化单个查询本身就比较困难。我使用过MongoDB,在尝试计算复杂查询时遇到了性能问题。我没有使用Cassandra,但我预计它会有同样的问题。

另一方面,如果您的负载预期是许多小型查询的负载,并且您希望能够轻松地向外扩展,那么您可以利用大多数NoSql数据库提供的最终一致性。注意,最终一致性实际上不是非关系数据模型的特性,但是在基于nosql的系统中实现和设置一致性要容易得多。

For a single, very heavy query, any modern RDBMS engine can do a decent job parallelizing parts of the query and take advantage of as much CPU and memory you throw at it (on a single machine). NoSql databases don't have enough information about the structure of the data to be able to make assumptions that will allow truly intelligent parallelization of a big query. They do allow you to easily scale out more servers (or cores) but once the query hits a complexity level you are basically forced to split it apart manually to parts that the NoSql engine knows how to deal with intelligently.

根据我使用MongoDB的经验,由于查询的复杂性,MongoDB最终无法对其进行优化,也无法在多个数据上运行部分查询。Mongo可以并行多个查询,但不太擅长优化单个查询。

你应该问自己以下问题:

(Volume, Velocity) Will you be writing and reading TONS of information , so much information that no one computer could handle the writes. (Global) Will you need this writing and reading capability around the world so that the writes in one part of the world are accessible in another part of the world? (Reliability) Do you need this database to be up and running all the time and never go down regardless of which Cloud, which country, whether it's VM , Container, or Bare metal? (Scale-ability) Do you need this database to be able to continue to grow easily and scale linearly (Consistency) Do you need TUNABLE consistency where some writes can happen asynchronously where as others need to be certified? (Skill) Are you willing to do what it takes to learn this technology and the data modeling that goes with creating a globally distributed database that can be fast for everyone, everywhere?

如果在这些问题中,你认为“可能”或“不”,你应该用别的词。如果你对所有问题的答案都是“当然”,那么你应该用卡桑德拉。

当你可以在一个盒子上做所有事情时,使用RDBMS。它可能比大多数方法都简单,任何人都可以使用它。

如果你需要一个SQL语义完全一致的数据库,Cassandra不是你的解决方案。Cassandra支持键值查找。它不支持SQL查询。Cassandra中的数据“最终是一致的”。数据的并发查找可能不一致,但最终查找是一致的。

如果你需要严格的语义,需要对SQL查询的支持,可以选择其他的解决方案,比如MySQL, PostGres,或者结合使用Cassandra和Solr。

another situation that makes the choice easier is when you want to use aggregate function like sum, min, max, etcetera and complex queries (like in the financial system mentioned above) then a relational database is probably more convenient then a nosql database since both are not possible on a nosql databse unless you use really a lot of Inverted indexes. When you do use nosql you would have to do the aggregate functions in code or store them seperatly in its own columnfamily but this makes it all quite complex and reduces the performance that you gained by using nosql.