- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
阻止 com.datastax.driver.core.Session 执行方法
public ResultSet execute(Statement statement);
对此方法的评论:
This method blocks until at least some result has been received from the database. However, for SELECT queries, it does not guarantee that the result has been received in full. But it does guarantee that some response has been received from the database, and in particular guarantee that if the request is invalid, an exception will be thrown by this method.
来自 com.datastax.driver.core.Session 的非阻塞执行方法
public ResultSetFuture executeAsync(Statement statement);
This method does not block. It returns as soon as the query has been passed to the underlying network stack. In particular, returning from this method does not guarantee that the query is valid or has even been submitted to a live node. Any exception pertaining to the failure of the query will be thrown when accessing the {@link ResultSetFuture}.
我有 02 个关于它们的问题,因此如果您能帮助我理解它们,那就太好了。
假设我有 100 万条记录,我希望所有这些记录都到达数据库(没有任何丢失)。
问题 1:如果我有 n 个线程,则所有线程都将具有需要发送到数据库的相同数量的记录。它们都使用阻塞执行调用继续向 cassandra 发送多个插入查询。如果我增加 n 的值,是否也有助于加快我需要将所有记录插入到 cassandra 的时间?
这会导致 cassandra 的性能问题吗? Cassandra 是否必须确保对于每个插入记录,集群中的所有节点都应立即了解新记录?为了保持数据的一致性。 (我假设 cassandra 节点甚至不会考虑使用本地机器时间来控制记录插入时间)。
问题2:使用非阻塞执行,如何确保所有插入都成功?我知道的唯一方法是等待 ResultSetFuture 检查插入查询的执行情况。我还有什么更好的办法吗?非阻塞执行是否比阻塞执行更容易失败?
非常感谢您的帮助。
最佳答案
If I have n number of threads, all threads will have the same amount of records they need to send to the database. All of them continue sending multiple insert queries to cassandra using blocking execute call. If I increase the value of n, will it also helps to speed up the time that I need to insert all records to cassandra?
在某种程度上。让我们稍微分离一下客户端实现细节,并从“并发请求数”的角度来看问题,因为如果使用executeAsync,则不需要为每个正在进行的请求都有一个线程。在我的测试中,我发现虽然拥有大量并发请求有很多值(value),但存在一个阈值,达到该阈值就会出现 yield 递减或性能开始下降。我的一般经验法则是(number of Nodes *
native_transport_max_threads (default: 128)
* 2)
,但或多或少您可能会发现更优化的结果。
这里的想法是,排队的请求数量超过 cassandra 一次处理的数量并没有多大值(value)。在减少正在进行的请求数量的同时,您还可以限制驱动程序客户端和 cassandra 之间连接上不必要的拥塞。
Question 2: With non-blocking execute, how can I assure that all of the insertions is successful? The only way I know is waiting for the ResultSetFuture to check the execution of the insert query. Is there any better way I can do ? Is there a higher chance that non-blocking execute is easier to fail then blocking execute?
通过 get
等待 ResultSetFuture是一种途径,但如果您正在开发完全异步的应用程序,您希望尽可能避免阻塞。使用 Guava ,你最好的两个武器是 Futures.addCallback
和 Futures.transform
.
Futures.addCallback
允许您注册 FutureCallback
当驱动程序收到响应时执行。 onSuccess
在成功的情况下执行,onFailure
否则。
Futures.transform
允许您有效地映射返回的 ResultSetFuture
进入别的东西。例如,如果您只需要 1 列的值,您可以使用它来转换 ListenableFuture<ResultSet>
到 ListenableFuture<String>
无需在 ResultSetFuture
上阻止您的代码然后获取 String 值。
在编写数据加载程序时,您可以执行以下操作:
Semaphore
或具有固定数量许可的其他结构(这将是您的飞行请求的最大数量)。每当您使用 executeAsync
提交查询时,获得许可证。您实际上应该只需要 1 个线程(但可能需要引入一个 # cpu 核心大小的池来执行此操作)来从信号量获取许可并执行查询。它只会阻止获取,直到有可用的许可为止。Futures.addCallback
对于从 executeAsync
返回的 future 。回调应该调用 Sempahore.release()
两者皆 onSuccess
和onFailure
案例。通过释放许可证,这应该允许您在步骤 1 中的线程继续并提交下一个请求。要进一步提高吞吐量,您可能需要考虑使用 BatchStatement
并批量提交请求。如果您保持较小的批处理(50-250 是一个不错的数字)并且批处理中的插入全部共享相同的分区键,那么这是一个不错的选择。
关于cassandra - Cassandra 如何处理 datastax java 驱动程序中的阻塞执行语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34949292/
对于一个简单的聊天程序,我使用了一个通过 boost::python 包装的 c 库。 使用 PyQT 编写了一个简单的 GUI。接收消息是通过阻塞调用完成的lib说。对于独立刷新的 GUI,通信部分
当我创建以下内容时,我试图创建一个可以被异常终止的线程类(因为我试图让线程等待一个事件): import sys class testThread(threading.Thread): def
我正在用 Haskell 编写服务器,我想在客户端断开连接后显式关闭它们。当我调用 hClose ,线程将阻塞,直到客户端关闭其一侧的句柄。有没有办法让它在不阻塞的情况下关闭? 提前致谢! 最佳答案
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: garbage collection Operation 我有几个相关问题。 1.JAVA垃圾收集器运行时,是否占用
我有一个 Angular 函数,它在初始 URL 中查找“列表”参数,如果找到,就会出去获取信息。否则我想获得地理位置。如果存在 URL 参数,我不想获取地理位置。我使用的术语是否正确? constr
我读了很多关于锁定数据库、表和行的文章,但我想要较低的锁定,比如只锁定“操作”,我不知道如何调用它,假设我在 php 中有函数: function update_table() { //que
在我的多线程 mfc 应用程序中,m_view->SetScrollPos 处于阻塞状态并且所有应用程序都被卡住。 View 是在另一个线程中创建的,这是这种行为的原因吗? //SetScrollPo
FreeSwitch 软件在几天内运行良好(~3 - 5 天),然后由于 FreeSwitch 被阻止,新的来电请求被接受!!正在进行的调用继续他们的 session ,他们的调用似乎没有受到影响,但
我有一组按钮,当鼠标悬停在这些按钮上时,它们会改变颜色。这些的 CSS 以这种方式运行: #navsite ul li button { height: 60px; width: 60
由于某些原因,当我调用 WSARecvFrom 时,该函数在接收到某些内容之前不会返回。 _socket = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, N
我了解一些关于 Oracle 阻塞的知识——更新如何阻塞其他更新直到事务完成,写入者如何不阻塞读取者等。 我理解悲观和乐观锁定的概念,以及有关丢失更新等典型银行教科书示例。 我也理解 JDBC 事务隔
在两个代码点之间,我是否可以判断进程是否已被内核抢占,或者更确切地说,当时是否有任何其他代码在同一处理器上运行? //Point A some_type capture = some_capture(
这是我在 Oracle 的面试问题。 有一个堆栈,即使堆栈已满,push 操作也应该等到它完成,即使堆栈为空,pop 操作也应该等到它完成。 我们怎样才能做到这一点? 我的回答 让一个线程做push
我想知道是否有人可以告诉我如何有效地使用循环平铺/循环阻塞进行大型密集矩阵乘法。我正在用 1000x1000 矩阵做C = AB。我按照 Wikipedia 上的循环平铺示例进行操作,但使用平铺得到的
我正在阅读有关绿色线程的内容,并且能够理解这些线程是由 VM 或在运行时创建的,而不是由操作系统创建的,但我无法理解以下语句 When a green thread executes a blocki
我正在创建的 JavaScript API 具有以下结构: var engine = new Engine({ engineName: "TestEngine", engineHost
ChildWindow 是一个模态窗口,但它不会阻塞。有没有办法让它阻塞?我基本上想要一个 ShowDialog() 方法,该方法将调用 ChildWindow.Show() 但在用户关闭 Child
我需要一些关于如何调试 10.6 版本下的 Cocoa 并发问题的指导。我正在将“for”循环转换为使用 NSOperations,但大多数时候,代码只是在循环的某个时刻卡住。我可以在控制台中看到 N
我正在使用 ReportViewer 控件和自定义打印作业工作流程,这给我带来了一些问题。我的代码看起来有点像这样: ids.ForEach(delegate(Guid? guid)
我有以下成功复制文件的代码。但是,它有两个问题: progressBar.setValue() 之后的 System.out.println() 不会打印 0 到 100 之间的间隔(仅打印“0”直到
我是一名优秀的程序员,十分优秀!