Cassandra Session vs Cluster分享什么? [英] Cassandra Session vs Cluster What to Share?

查看:63
本文介绍了Cassandra Session vs Cluster分享什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于Cassandra的Session和Cluster类(Java驱动程序)的思考,我想知道有什么区别。在Hibernate中,每次都会创建一个会话并共享该会话工厂。

Thinking about Cassandra's Session and Cluster classes (Java driver) I wonder whats the difference. In Hibernate one creates a session every time and shares the session factory.

从许多来源得知,可以考虑创建一个会话并在多个线程之间共享它。

From many sources I learned that it is considered to create a single session and share it across many threads.

我确实发现这有点古玩。我本来希望为每个线程或正在进行的操作/任务创建一个会话。

I do find this a bit curios. I would have expected that I create a session for each thread or ongoing action / task.


  • 这样做时是否有问题?

  • 对性能有什么影响,会话线程安全吗?

  • 在较大的结果集上是否遇到游标问题(或者cassandra没有)游标?)

  • 可以安全地假设Session是线程安全的吗?还是我应该注意某些极端情况?

  • Do I have issues when doing so?
  • Whats the performance impact and is session thread-safe?
  • Do I run into cursor problems on larger result-sets (or does cassandra has no cursors?)
  • Is it safe to assume that Session is thread-safe or are there edge cases I should be aware of?

推荐答案

在传统的RDBMS中,会话通常是指事务上下文,并且许多实现都不是线程安全的。同时,会话通常是在某种类型的连接池之上实现的,并且终止连接(通过错误)也会终止会话。

In traditional RDBMS, a session usually refers to a transactional context and many implementations aren't thread safe. Meanwhile, the session is usually implemented on top of some kind of connection pooling and the termination of a connection (via error) also terminates the session.

在Cassandra中,实际上没有多个调用的事务上下文,因此,一旦连接到键空间会话就可以共享,并且不会无需重新建立。另外,驱动程序已经处理了重新连接和连接池,因此 session 与连接无关。

In Cassandra, there isn't really a transactional context over multiple calls, so once connected to a keyspace, the session shareable and doesn't need to re-established. In addition, the driver already handles reconnection and connection pooling, so sessions aren't connection dependent.

最后,针对 session 已被缓存,因此重新创建会话并不得不不断地重新准备语句效率不高。

Finally, statements prepared against a session are cached and it would be inefficient to re-create sessions and have to re-prepare statements constantly.

这篇关于Cassandra Session vs Cluster分享什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆