分布式系统的可靠、延时、一致性等问题是一般性问题,不局限于数据库,而Cassandra提供了一个很好的解决思路。

Cassandra号称能做到跨数据中心的数据库访问的高效访问,它的实现方式其实是把延时、吞吐量与一致性的权衡交给了用户来选择。Cassandra提供了两种访问级别: LOCAL_QUORUM和EACH_QUORUM,其中

  • LOCAL_QUORUM能语意为本数据中心内超过半数的副本成功执行,才返回用户操作成功;而
  • EACH_QUORUM语意为每个数据中心都超过半数的副本执行成功,才返回用户操作成功;

因此不难想象EACH_QUORUM由于需要跨datacenter访问,所以延时会很大,且带宽、吞吐量相应的也会性能降低。

---------------ref:http://www.packtpub.com/article/apache-cassandra-working-multiple-datacenter-environments

Quorum operations in multi-datacenter environments

Most applications use Cassandra for its capability to perform low-latency read and write operations. When a cluster is all located in a single physical location, the network latency is low and bandwidth does not (typically) have a cost. However, when a cluster is spread across different geographical locations, latency and bandwidth costs are factors that need to be considered. Cassandra offers two consistency levels: LOCAL_QUORUM and EACH_QUROUM. This recipe shows how to use these consistency levels.

Getting ready

The consistency levels LOCAL_QUORUM and EACH_QUORUM only work when using a datacenter-aware strategy such as the NetworkTopologyStrategy. See the recipe Scripting a multiple datacenter installation for information on setting up that environment.

READ.LOCAL_QUORUM returns the record with the most recent timestamp once a majority of replicas within the local datacenter have replied.
READ.EACH_QUORUM returns the record with the most recent timestamp once a majority of replicas within each datacenter have replied.
WRITE.LOCAL_QUORUM ensures that the write has been written to <ReplicationFactor> / 2 + 1 nodes within the local datacenter (requires network topology strategy).
WRITE.EACH_QUORUM ensures that the write has been written to <ReplicationFactor> / 2 + 1 nodes in each datacenter (requires network topology strategy).

How it works...

Each datacenter-aware level offers tradeoffs versus non-datacenter-aware levels. For example, reading at QUORUM in a multi-datacenter configuration would have to wait for a quorum of nodes across several datacenters to respond before returning a result to the client. Since requests across a WAN link could have high latency (40ms and higher), this might not be acceptable for an application that returns results to the clients quickly. Those clients can use LOCAL_QUORUM for a stronger read then ONE while not causing excess delay. The same can be said for write operations at LOCAL_QUORUM, although it is important to point out that writes are generally faster than reads.

It is also important to note how these modes react in the face of network failures. EACH_ QUORUMwill only succeed if each datacenter is reachable and QUORUM can be established in each.LOCAL_QUORUM can continue serving requests even with the complete failure of a datacenter.

ref:http://www.datastax.com/docs/0.7/operations/datacenter

---------------------------------------------

毫无疑问,当使用EACH_QUORUM时,可以保证全局数据的一致性;这点不再赘述。

但是,使用LOCAL_QUORUM时,又如何保证全局数据一致性?例如两个DATACENTER“同时”(在足够短的时间内)写一条数据时,就很可能出现数据冲突。

  • 当然可以放任它写时导致的不一致,而在读的时候解决冲突。据说Amazon web server就是这样做的(没有考究过,但他们的场景确可能这么做)。读的时候也是有这两个一致性级别的读操作。当发现不一致时,就把数据的不一致的解决抛给用户解决,或者通过写入的时间戳、写入者的级别 或者其他判断标准来解决冲突。
  • 另外,我们可以假设写入的用户是有地域局部性的。也就是说,大部分的写入都是从某个datacenter写入,偶尔小部分有从其他datacenter写入,所以只要我们把所有的写操作都重定向到一个datacenter,那一致性的问题就解决了。这种方法是牺牲了那“小部分”用户的性能,从而达到全局的性能最大化;

举个DataStax Enterprise的例子:

The required end result is for users in the US to contact one datacenter while UK users contact another to lower end-user latency. An additional requirement is for both of these datacenters to be a part of the same cluster to lower operational costs. This can be handled using the following rules:

  • When reading and writing from each datacenter, ensure that the clients the users connect to can only see one datacenter, based on the list of IPs provided to the client.
  • If doing reads at QUORUM, ensure that LOCAL_QUORUM is being used and not EACH_QUORUM since this latency will affect the end user’s performance experience.
  • Depending on how consistent you want your datacenters to be, you may choose to run repair operations (without the -pr option) more frequently than the required once per gc_grace_seconds.

ref:http://planetcassandra.org/blog/post/datastax-developer-blog-multi-datacenter-replication-in-cassandra/

----------------------------

上面都是写入的情况,当读的时候,其实也是类似的处理。Cassandra对读操作也提供了LOCAL_QUORUM和EACH_QUORUM的两个级别,对于这两个级别的定义是类似的。读操作存在一致性问题是因为各个datacenter之间是异步复制的,所以数据更新后的某个时间窗口(数秒),在不同datacenter读取到的数据是可能不一样的,所以才需要这样的一致性级别要求。一般情况下,DataStax的例子中,他们说吧“reading and writing”都固定到一个datacenter中了。

如果你也看过google的spaner, 你会发现虽然google用了原子钟这种高大上的工具,把写的延时“稍微”降了一些,但是,同样的道理,它也提供了很大的空间给用户配置,例如选择离用户最近的datacenter,讲“大多数”的副本放在离“大多数”用户最近的地方。 我归结为,无论多强大,都无法超越光速的限制。

Cassandra 如何处理跨数据中心的数据库延时问题的更多相关文章

  1. SQL Azure (17) SQL Azure V12 - 跨数据中心标准地域复制(Standard Geo-Replication)

    <Windows Azure Platform 系列文章目录> 熟悉Microsoft Azure平台的读者都了解,Azure SQL Database提供不同等级的,跨数据中心的异地冗余 ...

  2. Azure SQL Database (24) 使用新管理界面,创建跨数据中心标准地域复制(Standard Geo-Replication)

    <Windows Azure Platform 系列文章目录> 文本是对:SQL Azure (17) SQL Azure V12 - 跨数据中心标准地域复制(Standard Geo-R ...

  3. MySQL金融应用场景下跨数据中心的MGR架构方案(1)

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 0. 内容提纲 运行环境 部署MGR A&B 部署MGR A.B之间的复制通道 几个注意事项 如何在多个数据中心部 ...

  4. Windows Azure Virtual Network (13) 跨数据中心之间的虚拟网络点对点连接VNet Peering

    <Windows Azure Platform 系列文章目录> 今天是大年初二,首先祝大家新年快乐,万事如意. 在笔者之前的文章中:Windows Azure Virtual Networ ...

  5. Uber如何搭建一个基于Kafka的跨数据中心复制平台 原创: 徐宏亮 AI前线 今天

    Uber如何搭建一个基于Kafka的跨数据中心复制平台 原创: 徐宏亮 AI前线 今天

  6. 原生Redis跨数据中心双向同步优化实践

    一.背景 公司基于业务发展以及战略部署,需要实现在多个数据中心单元化部署,一方面可以实现多数据中心容灾,另外可以提升用户请求访问速度.需要保证多数据中心容灾或者实现用户就近访问的话,需要各个数据中心拥 ...

  7. 怎样打造一个分布式数据库——rocksDB, raft, mvcc,本质上是为了解决跨数据中心的复制

    摘自:http://www.infoq.com/cn/articles/how-to-build-a-distributed-database?utm_campaign=rightbar_v2& ...

  8. MySQL金融应用场景下跨数据中心的MGR架构方案(2)

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 如何在多个数据中心部署多套MGR集群,并实现故障快速切换. 上篇文章介绍了如何在多数据中心部署多套MGR集群,并构建集群间 ...

  9. SDN与NFV技术在云数据中心的规模应用探讨

    Neo 2016-1-29 | 发表评论 编者按:以云数据中心为切入点,首先对SDN领域中的叠加网络.SDN控制器.VxLAN 3种重要技术特点进行了研究,接下来对NFV领域中的通用服务器性能.服务链 ...

随机推荐

  1. Zookeeper VS Chubby

    目录 区别的根源      1)一致性      2)Client Cache vs No Cache 总结 参考资料 区别的根源 一个设计良好的系统应该是围绕并为其设计目标服务的. Chubby:p ...

  2. python中字符串格式化的意义(化妆)

    格式 描述%% 百分号标记 #就是输出一个%%c 字符及其ASCII码%s 字符串%d 有符号整数(十进制)%u 无符号整数(十进制)%o 无符号整数(八进制)%x 无符号整数(十六进制)%X 无符号 ...

  3. 第二十三篇 jQuery 学习5 添加元素

    jQuery 学习5 添加元素   同学们,这节课,使用jQuery动态添加元素,是很关键的一课,一般用在什么地方呢:别人发表一篇文章,你评论楼主的时候,总不能是提交表单,到后台的其他页面处理,然后再 ...

  4. re:正则表达式,字符串处理的杀手锏

    介绍 正则表达式是一种用形式化语法描述的文本匹配模式,可以进行复杂的字符串匹配. Python中的正则表达式通过re模块提供,功能比Python内置的str更强,但是速度没有str提供的方法快. 因此 ...

  5. selenium-Xpath使用方法

    01:什么是Xpath Xpath是一门xml文档中查找信息的语言,Xpath可用来在xml文档中对元素和属性进行遍历,主流的浏览器都支持xpath,因为HTML页面在DOM中表示xhtml文档 xp ...

  6. 京东POP店铺使用京东物流,如何拦截订单

    先进入物流工作台:https://wl.jdwl.com/ 然后操作中心-销售订单查询 然后点击展开按钮 粘贴要查询的订单号 勾选订单,点击取消按钮

  7. 27. ClustrixDB 分布式架构/一致性、容错和可用性

    一致性 许多分布式数据库都采用最终一致性而不是强一致性来实现可伸缩性.但是,最终的一致性会增加应用程序开发人员的复杂性,他们必须针对可能出现的数据不一致的异常进行开发. ClustrixDB提供了一个 ...

  8. css动画速度与三次贝赛尔曲线

      今天要说的是css的动画曲线.   首先要说的是语法: value: 1.linear:线性动画,也就是匀速,以相同的速度开始以相同的速度结束. 2.ease:默认的动画效果,特点是先快后慢,时间 ...

  9. Windows:在特定路径下启动命令行

    造冰箱的大熊猫,本文适用于Windows 7@cnblogs 2018/11/30 在Windows文件浏览器中,按下“Shift+鼠标右键”,点击“在此处打开命令窗口”.

  10. CPU风扇转速异常

    本文适用于Ubuntu 16.04,造冰箱的大熊猫@cnblogs 2018/10/9 近日发现一个问题,新笔记本的CPU风扇转速很高.笔记本刚刚启动,就能听到风扇呼呼的声音,转速高的异常.以前不是这 ...