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.
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
datastax-java-driver.advanced.metadata {
schema.debouncer {
window = 1 milliseconds
max-events = 1
}
}
in order to remove the 1 second delay. This is appropriate for my use case. But the change requires consideration depending on usage.