最近有很多关于卡桑德拉的话题。
Twitter, Digg, Facebook等都在使用它。
什么时候有意义:
使用卡桑德拉, 不用卡桑德拉,还有 使用RDMS而不是Cassandra。
最近有很多关于卡桑德拉的话题。
Twitter, Digg, Facebook等都在使用它。
什么时候有意义:
使用卡桑德拉, 不用卡桑德拉,还有 使用RDMS而不是Cassandra。
NoSQL的一般思想是,您应该使用最适合您的应用程序的数据存储。如果您有一个财务数据表,请使用SQL。如果您的对象需要复杂/缓慢的查询才能映射到关系模式,请使用对象或键/值存储。
当然,你遇到的任何现实问题都处于这两个极端之间,没有一个解决方案是完美的。您需要考虑每个存储的功能以及使用其中一个的后果,这将非常具体于您试图解决的问题。
在评估分布式数据系统时,您必须考虑CAP定理——您可以选择以下两个:一致性、可用性和分区容差。
Cassandra是一个可用的、支持最终一致性的分区容忍系统。要了解更多信息,请参阅我写的这篇博客文章:NoSQL系统的可视化指南。
Cassandra是一个特定问题的答案:当您有太多数据,以至于无法在一台服务器上存储时,您该怎么办?如何将所有数据存储在多个服务器上,同时不破坏银行账户,不让开发人员抓狂?Facebook每天都会收到4tb的压缩数据。这个数字很可能在一年内增长两倍以上。
如果您没有这么多数据,或者您有数百万美元来支付企业Oracle/DB2集群安装费用,以及安装和维护它所需的专家,那么您可以使用SQL数据库。
然而,Facebook不再使用cassandra,现在几乎只使用MySQL,在应用程序堆栈中移动分区,以获得更快的性能和更好的控制。
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.
在部署Cassandra的过程中与某人交谈,它不能很好地处理多对多。他们正在做初步测试。我和Cassandra的顾问谈过这个问题,他说如果你有这样的习题集,他就不建议你这么做。
Mongodb有非常强大的聚合函数和一个富有表现力的聚合框架。它具有许多开发人员习惯于从关系数据库世界中使用的特性。例如,它的文档数据/存储结构允许比Cassandra更复杂的数据模型。
当然,所有这些都是有代价的。因此,当您选择数据库(NoSQL、NewSQL或RDBMS)时,请考虑您要解决的问题和可伸缩性需求。没有一个数据库可以完成所有的工作。
除了这里的其他答案之外,沉重的单个查询与无数的轻查询负载是另一个需要考虑的问题。在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可以并行多个查询,但不太擅长优化单个查询。
让我们来读一些真实的案例:
http://planetcassandra.org/apache-cassandra-use-cases/
本文地址:http://planetcassandra.org/blog/post/agentis-energy-stores-over-15-billion-records-of-time-series-usage-data-in-apache-cassandra
他们详细阐述了不选择MySql的原因,因为数据库同步太慢。
(也是由于2- phase commit, FK, PK)
Cassandra基于Amazon Dynamo纸
特点:
稳定
高可用性
备份性能良好
读写比HBase好,(java中的BigTable克隆)。
wiki http://en.wikipedia.org/wiki/Apache_Cassandra
他们的结论是:
We looked at HBase, Dynamo, Mongo and Cassandra.
Cassandra was simply the best storage solution for the majority of our data.
截至2018年,
如果你需要支援,我建议你用ScyllaDB代替经典的cassandra。
Postgres kv插件也比cassandra快。无论如何不会有多实例可伸缩性。
没有什么是银弹,任何东西都是为了解决特定的问题而构建的,有自己的优点和缺点。这取决于你,你有什么问题陈述,什么是该问题的最佳解决方案。
我会按照你问的顺序一个一个地回答你的问题。因为Cassandra是基于NoSQL数据库家族的,所以在我回答你的问题之前,理解为什么使用NoSQL数据库是很重要的。
为什么使用NoSQL
In the case of RDBMS, making a choice is quite easy because all the databases like MySQL, Oracle, MS SQL, PostgreSQL in this category offer almost the same kind of solutions oriented toward ACID properties. When it comes to NoSQL, the decision becomes difficult because every NoSQL database offers different solutions and you have to understand which one is best suited for your app/system requirements. For example, MongoDB is fit for use cases where your system demands a schema-less document store. HBase might be fit for search engines, analyzing log data, or any place where scanning huge, two-dimensional join-less tables is a requirement. Redis is built to provide In-Memory search for varieties of data structures like trees, queues, linked lists, etc and can be a good fit for making real-time leaderboards, pub-sub kind of system. Similarly there are other databases in this category (Including Cassandra) which are fit for different problem statements. Now lets move to the original questions, and answer them one by one.
何时使用卡桑德拉
Being a part of the NoSQL family, Cassandra offers a solution for problems where one of your requirements is to have a very heavy write system and you want to have a quite responsive reporting system on top of that stored data. Consider the use case of Web analytics where log data is stored for each request and you want to built an analytical platform around it to count hits per hour, by browser, by IP, etc in a real time manner. You can refer to this blog post to understand more about the use cases where Cassandra fits in.
什么时候使用RDMS而不是Cassandra
Cassandra基于NoSQL数据库,不提供ACID和关系数据属性。如果您对ACID属性有强烈的需求(例如财务数据),Cassandra将不适合这种情况。显然,您可以为此制定一个变通方案,但是您最终将编写大量的应用程序代码来模拟ACID属性,并将严重延误上市时间。同时,使用Cassandra管理这种系统对您来说也是复杂而乏味的。
什么时候不用卡桑德拉
我认为上面的解释是否有意义不需要回答。
如果你需要一个SQL语义完全一致的数据库,Cassandra不是你的解决方案。Cassandra支持键值查找。它不支持SQL查询。Cassandra中的数据“最终是一致的”。数据的并发查找可能不一致,但最终查找是一致的。
如果你需要严格的语义,需要对SQL查询的支持,可以选择其他的解决方案,比如MySQL, PostGres,或者结合使用Cassandra和Solr。
它不支持跨 表。 不支持二级索引。 二级索引必须依赖Elastic search /Solr,并且必须编写自定义同步组件。 非ACID兼容系统。 查询支持有限。
除了上面给出的关于何时使用和何时不使用Cassandra的答案外,如果你决定使用Cassandra,你可能会考虑不使用Cassandra本身,而是使用它的众多表亲之一。
上面的一些答案已经指出了各种“NoSQL”系统,它们与Cassandra有许多相同的属性,有一些或大或小的差异,并且可能比Cassandra本身更适合您的特定需求。
Additionally, recently (several years after this question was originally asked), a Cassandra clone called Scylla (see https://en.wikipedia.org/wiki/Scylla_(database)) was released. Scylla is an open-source re-implementation of Cassandra in C++, which claims to have significantly higher throughput and lower latencies than the original Java Cassandra, while being mostly compatible with it (in features, APIs, and file formats). So if you're already considering Cassandra, you may want to consider Scylla as well.
Apache cassandra是一个分布式数据库,用于跨许多商用服务器管理大量结构化数据,同时提供高可用性服务,没有单点故障。
该架构完全基于上限定理,即可用性和分区容忍,有趣的是最终一致。
不要使用它,如果你不存储数据卷的机架集群, 如果您不存储时间序列数据,请不要使用, 不要使用如果你不分区你的服务器, 如果你要求强烈的一致性,请不要使用。
Cassandra是个不错的选择,如果:
您不需要DB中的ACID属性。 DB上会有大量的写操作。 需要与大数据、Hadoop、Hive和Spark集成。 需要实时数据分析和生成报告。 有一个强大的容错机制的要求。 有一个齐次系统的要求。 调优需要大量的自定义。
你应该问自己以下问题:
(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。它可能比大多数方法都简单,任何人都可以使用它。
在这里,我将重点介绍一些重要的方面,这些方面可以帮助你决定是否真的需要卡桑德拉。这个清单并不详尽,只是我脑海中最重要的一些观点
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.
Right. It makes sense to use Cassandra when you have a huge amount of data, a huge number of queries but very little variety of queries. Cassandra basically works by partitioning and replicating. If all your queries will be based on the same partition key, Cassandra is your best bet. If you get a query on an attribute that is not the partition key, Cassandra allows you to replicate the whole data with a new partition key. So now you have 2 replicas of the same data with 2 different partition keys.
这就引出了你的下一个问题。什么时候不用卡桑德拉。正如我提到的,Cassandra通过为每个新的分区键复制完整的数据库来扩展。但你不能一遍又一遍地复制。因此,当你有大量的查询,即每个查询在where子句中有不同的列时,Cassandra不是一个好的选择。
现在是第三个问题。使用RDBMS的关键在于需要ACID属性。如果您正在构建类似于支付服务的东西,并且希望每个交易都是隔离的,每个交易要么完成要么根本不发生,即使系统出现故障,更改仍然是持久的,并且在交易完成之前和之后各银行账户的资金是一致的,那么RDBMS是帮助您实现这一目标的唯一选择。
这篇文章实际上解释了整个事情,特别是什么时候使用Cassandra或不使用(相对于其他一些NoSQL选项)问题的一部分——>选择最好的数据库。一定要去看看。
编辑:为了回答proximab评论中的问题,当我们想到银行系统时,我们立即认为“ACID是最好的解决方案”。但即使是银行系统也由几个子系统组成,这些子系统甚至可能不处理任何与交易相关的数据,如账户持有人的个人信息、账户对账单、信用卡详细信息、信用历史等。
All of this information needs to be stored in some database or the another. Now if you store the account related information like account balance, that is something that needs to be consistent at all times. For example, if you try to send money from account A to account B, then the money that disappears from account A should instantaneousy show up in account B, and it cannot be present in both accounts at the same time. This system cannot be inconsistant at any point. This is where ACID is of utmost importance.
另一方面,如果您正在保存信用卡详细信息或信用记录,不应该落入坏人之手,那么您需要一些只允许授权用户访问的东西。我相信这是卡桑德拉支持的。也就是说,像信用记录和信用卡交易这样的数据,我认为这是一个不断增长的数据。此外,你可以查询的数据也只有这么多,即它有非常有限的查询数量。这两个条件使Cassandra成为一个完美的解决方案。