[
https://issues.apache.org/jira/browse/BEAM-4049?focusedWorklogId=92540&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-92540
]
ASF GitHub Bot logged work on BEAM-4049:
----------------------------------------
Author: ASF GitHub Bot
Created on: 19/Apr/18 12:34
Start Date: 19/Apr/18 12:34
Worklog Time Spent: 10m
Work Description: echauchot commented on a change in pull request #5112:
[BEAM-4049] Improve CassandraIO write throughput by performing async queries
URL: https://github.com/apache/beam/pull/5112#discussion_r182729329
##########
File path:
sdks/java/io/cassandra/src/main/java/org/apache/beam/sdk/io/cassandra/CassandraServiceImpl.java
##########
@@ -351,33 +354,54 @@ public TokenRange(
*/
protected class WriterImpl<T> implements Writer<T> {
+ /**
+ * The threshold of 100 concurrent async queries is a heuristic commonly
used
+ * by the Apache Cassandra community. There is no real gain to expect in
tuning this value.
+ */
+ private static final int CONCURRENT_ASYNC_QUERIES = 100;
+
private final CassandraIO.Write<T> spec;
private final Cluster cluster;
private final Session session;
private final MappingManager mappingManager;
+ private List<ListenableFuture<Void>> writeFutures;
public WriterImpl(CassandraIO.Write<T> spec) {
this.spec = spec;
this.cluster = getCluster(spec.hosts(), spec.port(), spec.username(),
spec.password(),
spec.localDc(), spec.consistencyLevel());
this.session = cluster.connect(spec.keyspace());
this.mappingManager = new MappingManager(session);
+ this.writeFutures = Lists.newArrayList();
}
/**
* Write the entity to the Cassandra instance, using {@link Mapper}
obtained with the
- * {@link MappingManager}. This method use {@link Mapper#save(Object)}
method, which is
- * synchronous. It means the entity is guaranteed to be reliably committed
to Cassandra.
+ * {@link MappingManager}. This method use {@link
Mapper#saveAsync(Object)} method, which is
+ * asynchronous. Beam will wait for all futures to complete, to guarantee
all writes have
+ * succeeded.
*/
@Override
- public void write(T entity) {
+ public void write(T entity) throws ExecutionException,
InterruptedException {
Mapper<T> mapper = (Mapper<T>) mappingManager.mapper(entity.getClass());
- mapper.save(entity);
+ this.writeFutures.add(mapper.saveAsync(entity));
+ if (this.writeFutures.size() % CONCURRENT_ASYNC_QUERIES == 0) {
Review comment:
you can limit the back pressure at a client level (what you already do) but
you can't set the number of bundles. It is the decision of the runner based on
its orientation (more batch or more streaming oriented) and the mode (streaming
or batch) and also the configuration of the engine (nb of workers for ex).
Indeed, it is not exposed to the users as they cannot do better than the runner.
I'm still +1 to not adding knobs for this heuristic value.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 92540)
Time Spent: 6h (was: 5h 50m)
> Improve write throughput of CassandraIO
> ---------------------------------------
>
> Key: BEAM-4049
> URL: https://issues.apache.org/jira/browse/BEAM-4049
> Project: Beam
> Issue Type: Improvement
> Components: io-java-cassandra
> Affects Versions: 2.4.0
> Reporter: Alexander Dejanovski
> Assignee: Alexander Dejanovski
> Priority: Major
> Labels: performance
> Time Spent: 6h
> Remaining Estimate: 0h
>
> The CassandraIO currently uses the mapper to perform writes in a synchronous
> fashion.
> This implies that writes are serialized and is a very suboptimal way of
> writing to Cassandra.
> The IO should use the saveAsync() method instead of save() and should wait
> for completion each time 100 queries are in flight, in order to avoid
> overwhelming clusters.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)