Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用DataStax C驱动程序的Cassandra执行时间较慢_C#_Azure_Nosql_Cassandra - Fatal编程技术网

C# 使用DataStax C驱动程序的Cassandra执行时间较慢

C# 使用DataStax C驱动程序的Cassandra执行时间较慢,c#,azure,nosql,cassandra,C#,Azure,Nosql,Cassandra,我已经成功地在Microsoft Azure中设置了Cassandra群集。当前,群集在Azure中的2个VM上包含2个节点。我一直在使用OpsCenter检查集群的状态,一切似乎都很有希望。然而,我已经为集群创建了一个简单的C测试客户端,使用DataStax C驱动程序连接到集群,该集群实际上正在工作,但速度非常慢 static class SimpleClient { private static Session _session; public static Session

我已经成功地在Microsoft Azure中设置了Cassandra群集。当前,群集在Azure中的2个VM上包含2个节点。我一直在使用OpsCenter检查集群的状态,一切似乎都很有希望。然而,我已经为集群创建了一个简单的C测试客户端,使用DataStax C驱动程序连接到集群,该集群实际上正在工作,但速度非常慢

static class SimpleClient
{
    private static Session _session;
    public static Session Session 
    { 
        get 
        { 
            return _session; 
        } 
    }

    private static Cluster _cluster;
    public static Cluster Cluster 
    { 
        get 
        { 
            return _cluster; 
        } 
    }

    public static void Connect(String node)
    {
        Console.WriteLine("Connecting to " + node);
        _cluster = Cluster.Builder().AddContactPoint(node).Build();
        _session = _cluster.Connect();
        Metadata metadata = _cluster.Metadata;
        Console.WriteLine("Connected to cluster: " + metadata.ClusterName.ToString());
    }

    public static void Close()
    {
        _cluster.Shutdown();
    }

    public static void CreateTable()
    {
        Console.WriteLine("Creating table with name test1");
        _session.Execute(" CREATE TABLE kstt.test1 ( identifier text PRIMARY KEY, name text ); ");
        Console.WriteLine("Table created with name test1");
    }

    public static void InsertToTable()
    {
        Console.WriteLine("Inserting data into test1");
        _session.Execute(" INSERT INTO kstt.test1 ( identifier, name ) VALUES ( '" + "hello" + "', '" + "man" + "' );");
        Console.WriteLine("Data inserted into test1");
    }

    public static void ReadFromTable(int times)
    {
        Console.WriteLine("Reading data from test1");
        for (int i = 0; i < times; i++)
        {
            RowSet results = _session.Execute(" SELECT * FROM kstt.test1; ");
            foreach (CqlColumn cqlColumn in results.Columns)
            {
                Console.WriteLine("Keyspace: " + cqlColumn.Keyspace + " # Table: " + cqlColumn.Table + " # Name: " + cqlColumn.Name); 
            }
        }
        Console.WriteLine("Data was read from test1");
    }

    public static void DropTable()
    {
        Console.WriteLine("Dropping table test1");
        try
        {
            _session.Execute(" DROP TABLE kstt.test1; ");
        }
        catch { }
        Console.WriteLine("Dropped table test1");
    }
}
这段代码实际上可以工作。但是它的速度非常慢,连接大约需要10秒,执行查询需要10秒。我认为这与Azure中内置的负载平衡器以及cassandra.yaml设置有关

我还注意到集群返回2个IP。一个是集群的外部ip,另一个是一个特定节点的内部ip,当然从外部是无法访问的

这是我们的设置:

端口9042上的负载平衡器

端口9160上的负载平衡器

cassandra-node1,外部ip为66.55.44.33,内部ip为33.44.33.44

cassandra-node2,外部ip为66.55.44.33,内部ip为11.22.11.22

卡桑德拉·亚马尔

收听cassandra-node1的地址:33.44.33.44 cassandra-node1的RPC地址:33.44.33.44

cassandra-node2的收听地址:11.22.11.22 cassandra-node2的RPC地址:11.22.11.22


有时,在执行查询时,程序甚至会出现WriteTimeoutException。

虽然仅根据这些细节很难调查性能问题,但下面是几个问题/注释:

你的客户是从哪里来的? Cassandra节点之间以及从客户机到C*节点的ping时间是多少? 实际上,端口9042上不需要负载平衡器,因为驱动程序将能够自己进行负载平衡。 通常,通过使用准备好的语句,您会看到一些改进
从运行代码的任何地方到Cassandra节点的ping时间是多少?10秒显然是不合理的,我看不出你的代码有任何错误。当群集在Azure中时,客户端正在从我的家庭网络运行。我不能ping Azure虚拟机,所以我真的不知道这件事的响应时间。值得注意的是,代码实际上可以正常工作,但非常缓慢。请尝试在azure内部设置客户端,以排除外部接口上的问题。您可以使用PSP ping azure vm并ping您已公开的端点端口。或者您可以设置一个实例ip和ping,因为它将直接指向VM,而不是云服务本身。