卡桑德拉和火花

Cassandra and Spark

你好我有一个关于集群拓扑和数据复制的高级问题,关于 cassandra 和 spark 在 datastax enterprise 中一起使用。

据我所知,如果一个集群中有 6 个节点并且完成了繁重的计算(例如分析),那么如果需要,您可以拥有三个 spark 节点和 3 个 cassandra 节点。或者您不需要三个节点进行分析,但您的作业不会 运行 一样快。您不想在 cassandra 节点上进行繁重分析的原因是本地内存已经被用完来处理繁重的 read/write cassandra 负载。

这很清楚,但这是我的问题:

你是对的,你想分离你的 cassandra 和你的分析工作负载。 典型的设置可能是:

  • 一个数据中心的 3 个节点(名称:cassandra)
  • 第二个数据中心中的 3 个节点(名称:analytics)

创建键空间时,您使用 NetworkTopologyStrategy 和为每个数据中心定义的复制因子来定义它们,如下所示:

CREATE KEYSPACE myKeyspace WITH replication = {'class': 'NetworkTopologyStrategy', 'cassandra': 2, 'analytics': 2};

使用此设置,您的数据将在每个数据中心复制两次。这是由 cassandra 自动完成的。因此,当您在 DC cassandra 中插入数据时,插入的数据将自动复制到 DC analytics,反之亦然。注意:您可以通过为要分析的数据和不分析的数据使用单独的键空间来定义要复制的数据。

在您的 cassandra.yaml 中,您应该使用 GossipingPropertyFileSnitch。使用此告密者,您可以在文件 cassandra-rackdc.properties 中定义节点的 DC 和机架。然后通过八卦协议传播此信息。因此每个节点都了解您的集群的拓扑结构。

How does the replicated data work then?

常规 Cassandra 复制将在节点和 DC 之间运行。就复制而言,这与具有两个数据中心的仅 c* 集群相同。

Are all the cassandra only nodes in one rack, and all the spark nodes in another rack?

使用默认的 DSE Snitch,您的 C* 节点将在一个 DC 中,而 Spark 节点将在另一个 DC 中。它们都将位于默认机架中。如果您想使用多个机架,则必须使用高级告密者自行配置。 GPFS 或 PFS 是不错的选择,具体取决于您的编排机制。了解更多 in the DataStax Documentation

Does all the data get replicated to the spark nodes? How does that work if it does?

复制在键空间级别进行控制并取决于您的复制策略:

SimpleStrategy 只会询问您集群中所需的副本数量(它不支持数据中心,因此如果您有多个 DC,请不要使用它)

create KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3 }

这假设您只有一个 DC,并且每个数据位有 3 个副本

NetworkTopology 策略让您选择每个 DC 的副本数

create KEYSPACE tst WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1' : 2, 'DC2': 3 }

您可以选择每个 DC 具有不同数量的副本。

What is the recommended configuration steps to make sure the data is replicated properly to the spark nodes?

更新 RF 的过程是 in the datastax documentation。这是逐字的:

Updating the replication factor Increasing the replication factor increases the total number of copies of keyspace data stored in a Cassandra cluster. If you are using security features, it is particularly important to increase the replication factor of the system_auth keyspace from the default (1) because you will not be able to log into the cluster if the node with the lone replica goes down. It is recommended to set the replication factor for the system_auth keyspace equal to the number of nodes in each data center.

Procedure

Update a keyspace in the cluster and change its replication strategy options. ALTER KEYSPACE system_auth WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2}; Or if using SimpleStrategy:

ALTER KEYSPACE "Excalibur" WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }; On each affected node, run the nodetool repair command. Wait until repair completes on a node, then move to the next node.

知道增加集群中的 RF 会产生大量 IO 和 CPU 利用率以及网络流量,同时您的数据会在集群中移动。

如果您有实时生产工作负载,则可以使用 nodetool getstreamthroughput / nodetool setstreamthroughput throttle 影响。

您也可以 throttle the resulting compactionsnodetool getcompactionthroughput nodetool setcompactionthroughput

How does Cassandra and Spark work together on the analytics nodes and not fight for resources? If you are not going to limit Cassandra at all in the whole cluster, then what is the point of limiting Spark, just have all the nodes Spark enabled.

关键是您不会将主要事务读取/写入指向分析 DC(使用一致性级别 ONE_LOCAL 或 QUORUM_LOCAL 将这些请求指向CDC)。不用担心,您的数据仍然通过复制到达分析 DC,但您不会等待 ack 从分析节点返回以响应客户请求。第二个 DC 是 eventually consistent

你说得对,cassandra 和 spark 仍然 运行 在分析 DC 的同一个盒子上(这对数据局部性很重要)并且可以访问相同的资源(你可以做类似的事情控制最大火花核心,使 cassandra 仍有喘息的空间)。但是您可以通过拥有两个数据中心来实现 workload isolation

默认情况下,DataStax 驱动程序会将他们连接的第一个接触点的 DC 视为本地 DC,因此只需确保您的接触点列表仅包含本地 (c* DC) 中的机器。

您也可以根据驱动自行指定本地数据中心。这是 ruby driver 的示例,请查看其他语言的驱动程序文档。

use the :datacenter cluster method: First datacenter found will be assumed current by default. Note that you can skip this option if you specify only hosts from the local datacenter in :hosts option.