【问题标题】:How to resolve "cassandra.cluster.NoHostAvailable" in a Python multi threaded program如何在 Python 多线程程序中解析“cassandra.cluster.NoHostAvailable”
【发布时间】:2016-02-23 11:02:00
【问题描述】:

我正在尝试使用多线程 Python 程序将记录插入 Cassandra。我在 3 台机器上同时运行这个程序。有一段时间记录被插入,但后来我遇到了异常。我正在使用 datastax 提供的驱动程序。

cassandra.cluster.NoHostAvailable

我做了一些搜索发现(来源:https://datastax.github.io/python-driver/api/cassandra/cluster.html

异常 cassandra.cluster.NoHostAvailable
操作时引发 已尝试但所有连接都忙、已失效、已关闭或 使用时出现错误。

我的问题是:
1. 如果与 Cassandra 有太多联系,这是一个正常的例外吗?
2. 在我想创建许多与 cassandra 的连接/会话的情况下,我将如何解决这个问题。 (我知道创建太多会话是不可取的,它会影响服务器性能,因为每个会话都会消耗少量内存)

下面是代码片段。

cluster = Cluster(['192.168.1.21'])
session = cluster.connect('myNameSpace')

def insertInToCassandra(catRange):
    for x in catRange:
        //function to insert records into Cassandra table

ProductRange = [
    range(900,920),
    range(921,940),
    range(941,960),
    range(961,980),
    range(981,1000)
     ]

# Make the Pool of workers
pool = ThreadPool(20)

# Open the urls in their own threads
# and return the results
results = pool.map(insertInToCassandra, ProductRange)

#close the pool and wait for the work to finish
pool.close()
pool.join()

【问题讨论】:

    标签: python cassandra cassandra-2.0


    【解决方案1】:

    这是一个正常的异常,如果一个或多个 cassandra 节点不可用,尤其是当它进入 GC 旋转或以其他方式崩溃时,可能会发生这种异常。

    根据您的复制因子 (RF) 和一致性级别 (CL),单个节点脱机可能会或可能不会破坏应用程序(RF 为 3 且 CL 为仲裁,任何单个节点故障应该没有问题)。

    您应该使用 nodetool status 检查 cassandra 集群的运行状况,并检查 /var/log/cassandra/system.log 是否有节点上下波动的迹象。

    【讨论】:

    • 感谢杰夫的回答。现在RF是2,我想我需要把它改成3
    猜你喜欢
    • 2010-10-13
    • 2011-06-15
    • 2011-05-21
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多