简体   繁体   English

使用java模拟多个用户连接到Cassandra

[英]Simulate multiple users connection to Cassandra using java

I'm developing an application using java.我正在使用 java 开发一个应用程序。 The objective is to simulate multiple users connection to Cassandra (concurrent connections), all of them connected to same cluster.目标是模拟多个用户连接到 Cassandra(并发连接),所有用户都连接到同一个集群。

My questions is: Should I implement multiple sessions where each session simulate a user.我的问题是:我应该实现多个会话,每个会话模拟一个用户。 or only one session for the whole application.?还是整个应用程序只有一个会话。? Also how to implement multiple sessions if possible.?如果可能的话,还如何实现多个会话。?

Its appreciated if there is a reference or examples.如果有参考或示例,不胜感激。

You should always consider using a single session with a connection pool for concurrent requests.您应该始终考虑将单个会话与连接池用于并发请求。 you can build a retry mechanism if the session goes bad.如果会话出错,您可以建立重试机制。 having said that you can technically create redundant sessions, the driver would allow it.话虽如此,您可以在技术上创建冗余会话,驱动程序会允许它。

Ideally, you should use only one Cluster / Session object per application, as each Session object creates a pool of connections to every node of the cluster + a control connection to get notifications about schema & topology changes, etc., and having too many connections would add an additional load to the nodes.理想情况下,您应该为每个应用程序只使用一个Cluster / Session对象,因为每个Session对象都会创建一个到集群每个节点的连接池+ 一个控制连接以获取有关架构和拓扑更改等的通知,并且连接过多会给节点增加额外的负载。 As described in the documentation , single network connection could carry on multiple requests simultaneously, and you can increase the number of the in-flight requests if you need, but it's not recommended to set them too high, as the high number of in-flight requests is a sign that nodes aren't able to execute queries so fast - this could happen if you're running queries that use ALLOW FILTERING , or fetching too much data.文档中所述,单个网络连接可以同时承载多个请求,您可以根据需要增加飞行中请求的数量,但不建议将它们设置得太高,因为飞行中的数量较多requests 表明节点无法如此快速地执行查询 - 如果您正在运行使用ALLOW FILTERING查询或获取过多数据,则可能会发生这种情况。

You can find more information in the DataStax's guide " Developing applications with DataStax drivers ".您可以在 DataStax 的指南“ 使用 DataStax 驱动程序开发应用程序”中找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM