I’ve a Jar file that initialises my Cassandra database during which it creates ~13 tables. This file is being run by our tests where we start a Cassandra test container and use the jar to set it up.
But I’m surprised to see that each table takes ~1-2 seconds to initialise, totaling ~15 seconds. If I manually create one of these tables, using cqlsh
, it takes ~100-120 ms.
Is there an explanation for this delay? Is there a work around?
I came across Why does it take so long to create a table? but I don’t have any tabs in my tables.
Update
The Java Code boils down to
cqlSession.execute( SimpleStatement.newInstance(query).setIdempotent(isIdempotent) );
which uses the java-driver-core
version 4.14.1
. The query
looks like
CREATE TABLE settings (key text, value text, PRIMARY KEY (key))
and took 1.125 seconds.
2
Answers
Turns out in the
java-driver-core
there is a feature called debouncing. Here requests are accumulated over 1 second / an upper count before being sent to Cassandra. You can see the code here.There are driver config settings that can be used to control the debounce behaviour, which I set as
in order to remove the 1 second delay. This is appropriate for my use case. But the change requires consideration depending on usage.
Because Cassandra is a distributed system, when you create a table you need to make sure that changes are propagated to all nodes so schema will be in agreement. This is especially important when you use something like Java driver that by default uses round-robin policy, so different DDL statements could be sent to different nodes, causing schema mismatch errors. You can find an example of how to do that correctly here.
In
cqlsh
it’s not the issue as it always uses the same connection to send all commands, so you won’t get schema mismatch because schema versions are generated on the same node.