I recently started testing some prototypes of noSQL for the client. They got a real-time application that makes a lot of attachments but reads less (they are currently using MySql and would like to try some noSQL solutions)
Last weekend I tried Cassandra 2.0, MongoDB 2.4.9 and Redis to compare with regular Mysql 5.5 DB. They all work in my Windows i3 kernel with 2.30 GHz / 8 GB RAM, so there are no high-end fashion machines.
The structure of the table is simple, as shown below. Although it is a MySql DESC, Cassandra has the same structure, and in MongoDb it is stored as JSON / BSON, but it has the same structure and indexes. It has two indexes (oneway_id and twoway_id) for all three db.
Structure (for all four db)
+--------------+---------------------+
| Field | Type |
+--------------+---------------------+
| tmstamp | bigint(20) unsigned |
| field_1 | bigint(20) unsigned |
| field_2 | varchar(64) |
| field_3 | varchar(64) |
| field_4 | tinyint(3) unsigned |
| field_5 | bigint(20) unsigned |
| field_6 | varchar(25) |
| field_7 | varchar(15) |
| field_8 | varchar(15) |
| field_9 | varchar(15) |
+--------------+---------------------+
DB / Environment Details
- MySql 5.6 (64 bit) with mysql connector java 5.1.28
- Apache Cassandra 2.0 with datastax 2.0 Java drivers
- MongoDB 2.4.6 with Java mongo driver 2.12.0
- Redis 2.8.17 runs on a Linux machine
- Oracle Java 1.6 (64 bit)
- Microsoft Windows 7 (64 bit)
- Intel i3 core 2.30 Ghz processor
- RAM 8 GB
Simple Java test cases were created, and these are the results that I got (although not always the same numbers, but the latencies are almost the same):
100,000 entries
- MySql 1000,000 - 46 seconds
- Kassandra - 54 seconds
- MongoDb - 2 seconds
500,000 entries
- MySql 1,000,000 - 142 seconds
- Kassandra - 299 seconds
- MongoDb - 41 secs
1,000,000 entries
- MySql 1000,000 - 349 seconds
- Kassandra - 699 seconds
- MongoDb - 51 secs
- Redis - 34 seconds
My question is, why does Cassandra go for such a small and simple table insert for so long?
Cassandra sql-, . , . , , :
http://www.datastax.com/dev/blog/client-side-improvements-in-cassandra-2-0
asyncExecute, .
, , ( , )
PreparedStatement ps = session.prepare("INSERT INTO some_table (val_1, val_2, val_3, val_4) VALUES (?, ?, ?, ?)");
BatchStatement batch = new BatchStatement();
//for loop start
batch.add(ps.bind(uid, mid1, title1, body1));
//for loop end
session.execute(batch);
-
String sqlInsert = "INSERT INTO some_table (val_1, val_2, val_3, val_4) VALUES (";
// for loop start
sqlInsert += uid+", "+", "+mid1+", "+title1+", "+body1+")";
session.execute(sqlInsert);
// for loop end
Cassandara , mysql - , MongoDB , Cassandra? , - ?
JSON/BSON Cassandra, MongoDB? , ? ? ? , , MongoDB , Cassandra!