【发布时间】:2015-12-16 23:17:11
【问题描述】:
我是 Cassandra 的新手,并试图弄清楚大小调整的工作原理。我创建了一个键空间和一个表。然后,我生成了一个脚本,在 java 中将 100 万行创建到一个 csv 文件中,并将其插入到我的数据库中。 CSV 文件的大小约为 545 mb。然后我将它加载到数据库中并运行 nodetool cfstats 命令并收到此输出。它说使用的总空间是 50555052 字节(~50 mb)。怎么会这样?有了索引、列等的开销,我的总数据怎么能比原始 CSV 数据更小(不仅更小,而且更小)?也许我没有正确阅读这里的内容,但这看起来对吗?我在单台机器上使用 Cassandra 2.2.1。
Table: users
SSTable count: 1
Space used (live): 50555052
Space used (total): 50555052
Space used by snapshots (total): 0
Off heap memory used (total): 1481050
SSTable Compression Ratio: 0.03029072054256705
Number of keys (estimate): 984133
Memtable cell count: 240336
Memtable data size: 18385704
Memtable off heap memory used: 0
Memtable switch count: 19
Local read count: 0
Local read latency: NaN ms
Local write count: 1000000
Local write latency: 0.044 ms
Pending flushes: 0
Bloom filter false positives: 0
Bloom filter false ratio: 0.00000
Bloom filter space used: 1192632
Bloom filter off heap memory used: 1192624
Index summary off heap memory used: 203778
Compression metadata off heap memory used: 84648
Compacted partition minimum bytes: 643
Compacted partition maximum bytes: 770
Compacted partition mean bytes: 770
Average live cells per slice (last five minutes): 0.0
Maximum live cells per slice (last five minutes): 0
Average tombstones per slice (last five minutes): 0.0
Maximum tombstones per slice (last five minutes): 0
我生成 CSV 文件的 Java 代码如下所示:
try{
FileWriter writer = new FileWriter(sFileName);
for(int i=0;i<1000000;i++){
writer.append("Username " + i);
writer.append(',');
writer.append(new Timestamp(date.getTime()).toString());
writer.append(',');
writer.append("myfakeemailaccnt@email.com");
writer.append(',');
writer.append(new Timestamp(date.getTime()).toString());
writer.append(',');
writer.append("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ");
writer.append(',');
writer.append("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ");
writer.append(',');
writer.append("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ");
writer.append(',');
writer.append("tr");
writer.append('\n');
}
writer.flush();
writer.close();
}
catch(IOException e)
{
e.printStackTrace();
}
【问题讨论】:
-
不确定您的数据是什么样的,但如果 CSV 中充满逗号和引号,您可能会看到一些节省
-
我也是 Cassandra 的新手,我刚刚复制了一个 ~14GB 的 csv,其中包含 50 个字段的 ~23M 记录。 Cassandra 告诉我它只有大约 158MB 的磁盘。等待它在我的节点上复制,然后我将尝试一些查询以确保它都在那里。
标签: cassandra