Hello Alex,
thank you for your feedback. A basic approach to determine the amount of concurrency in my application, could be the following code:
-+-
while(true) {
// Generating new insert statements
char* insertStatement = "INSERT INTO .....";
size_t highBytesWatermark = session->getHighBytesWatermark();
size_t insertStatementSize = strlen(insertStatement);
// Ask the session, if there is a connection available that can handle the insert statement
bool connectionAvailable = session->isAConnectionAvailableWithLessThenPendingBytes(highBytesWatermark - insertStatementSize);
if(! connectionAvailable) {
// Doing a spinlock or maybe calling a blocking function e.g.
// session->waitForPendingBytesBelow(highBytesWatermark - insertStatementSize);
}
future insertFuture = session->execute(insertStatement);
}
-+-
Depending on the amount of pending write bytes, a new async insert statement is executed or the application waits until a connection is available, that can handle the statement.
The Cassandra java driver provides some information about the session, which can be used to achieve something similar. The session can be asked for the amount of 'in flight queries' [1]. As soon as the amount of in flight queries increases, the application could reduce the amount of generated insert statements or wait for some time.
Best Regards
Jan
====
URLs:
[1]
http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/Session.State.html#getInFlightQueries%28com.datastax.driver.core.Host%29