The context
I have just one Cassandra node, installed locally on my PC with Windows 10 (Core i5, 16GB ram, SSD drive).
I created a table like this:
CREATE KEYSPACE covid19 WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': '1'
};
CREATE TABLE covid19.cases (
pesel text,
test_date date,
result boolean,
PRIMARY KEY ((pesel), test_date)
)
WITH CLUSTERING ORDER BY (test_date DESC);
The pesel is unique, 10-digits id of a person.
Then I generated 10 000 rows of sample data, that looks like this:
INSERT INTO cases (pesel, test_date, result) VALUES ('0000000001', '2020-03-10', true);
INSERT INTO cases (pesel, test_date, result) VALUES ('0000000002', '2020-03-10', false);
INSERT INTO cases (pesel, test_date, result) VALUES ('0000000003', '2020-03-10', false);
INSERT INTO cases (pesel, test_date, result) VALUES ('0000000004', '2020-03-12', false);
INSERT INTO cases (pesel, test_date, result) VALUES ('0000000005', '2020-03-12', false);
INSERT INTO cases (pesel, test_date, result) VALUES ('0000000006', '2020-03-12', false);
...
Finally, I loaded the data using cqlsh: source 'cases.cql';
Problem 1
To load 10 000 rows it takes 51 seconds. Is that normal?
I was expecting inserts to Cassandra to be ultra fast, while this pretty much comparable with SQLite without transaction (59s). If I wrap inserts with BEGIN & COMMIT in SQLite, this takes less than a second. This brings us to another problem...
Problem 2
Batch inserting. Slow batch inserting. To single partition, on single node.
I wrapped inserts with BEGIN BATCH and APPLY BATCH;. After that, the source was taking so long, I stopped measuring after passing 4 minutes mark.
Yes, I am aware of wrong usage of batch inserts. As far as I understood, it is an anti-pattern to use batch insert if it would require inserts to different partitions, which makes sense. This is not the case here.
Why is batch inserting so slow on single node (thus single partition)?
What am I missing here?