【问题标题】:Set keys and rows cache to a column family using pycassa?使用pycassa将键和行缓存设置为列族?
【发布时间】:2025-11-28 19:20:07
【问题描述】:

我想知道 pycassa 是否可以将 keys_cachedrows_cached 字段设置为特定的列族(甚至是键空间)?如此处所示,使用 cassandra cli:http://www.datastax.com/docs/1.0/configuration/storage_configuration

我在文档中找到了采用key_cache_size 参数的alter_column_family 函数:http://pycassa.github.io/pycassa/api/pycassa/system_manager.html

但是当我在设置列族的键缓存大小(http://pycassa.github.io/pycassa/assorted/pycassa_shell.html)后使用 pycassaShell 检查缓存值时,它仍然告诉我:

Row Cache:                       None%
Key Cache:                       None%

而且两者之后的性能/内存使用也没有差异,并且由于alter_column_family 采用**kwargs 参数,并且显然不检查它们,所以使用任何参数名称调用成功......所以我认为key_cache_size什么都没有……而且我没有找到关于什么是可能的可选参数的文档。

这是收到alter_column_family 呼叫时的 cassandra 日志:

INFO 17:39:26,338 Update ColumnFamily '53c7deadcc9b10271a2df9f0/B' From org.apache.cassandra.config.CFMetaData@3fbd01a[cfId=2dd38542-82ea-381f-be51-44a30af61f24,ksName=53c7deadcc9b10271a2df9f0,cfName=B,cfType=Standard,comparator=org.apache.cassandra.db.marshal.IntegerType,comment=,readRepairChance=0.1,dclocalReadRepairChance=0.0,replicateOnWrite=true,gcGraceSeconds=864000,defaultValidator=org.apache.cassandra.db.marshal.DoubleType,keyValidator=org.apache.cassandra.db.marshal.IntegerType,minCompactionThreshold=4,maxCompactionThreshold=32,column_metadata={java.nio.HeapByteBuffer[pos=0 lim=3 cap=3]=ColumnDefinition{name=6b6579, validator=org.apache.cassandra.db.marshal.IntegerType, type=PARTITION_KEY, componentIndex=null, indexName=null, indexType=null}, java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]=ColumnDefinition{name=76616c7565, validator=org.apache.cassandra.db.marshal.DoubleType, type=COMPACT_VALUE, componentIndex=null, indexName=null, indexType=null}, java.nio.HeapByteBuffer[pos=0 lim=7 cap=7]=ColumnDefinition{name=636f6c756d6e31, validator=org.apache.cassandra.db.marshal.IntegerType, type=CLUSTERING_KEY, componentIndex=null, indexName=null, indexType=null}},compactionStrategyClass=class org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy,compactionStrategyOptions={},compressionOptions={sstable_compression=org.apache.cassandra.io.compress.LZ4Compressor},bloomFilterFpChance=<null>,memtable_flush_period_in_ms=0,caching=KEYS_ONLY,defaultTimeToLive=0,speculative_retry=NONE,indexInterval=128,populateIoCacheOnFlush=false,droppedColumns={},triggers={}] To org.apache.cassandra.config.CFMetaData@11131f6f[cfId=2dd38542-82ea-381f-be51-44a30af61f24,ksName=53c7deadcc9b10271a2df9f0,cfName=B,cfType=Standard,comparator=org.apache.cassandra.db.marshal.IntegerType,comment=,readRepairChance=0.1,dclocalReadRepairChance=0.0,replicateOnWrite=true,gcGraceSeconds=864000,defaultValidator=org.apache.cassandra.db.marshal.DoubleType,keyValidator=org.apache.cassandra.db.marshal.IntegerType,minCompactionThreshold=4,maxCompactionThreshold=32,column_metadata={java.nio.HeapByteBuffer[pos=0 lim=7 cap=7]=ColumnDefinition{name=636f6c756d6e31, validator=org.apache.cassandra.db.marshal.IntegerType, type=CLUSTERING_KEY, componentIndex=null, indexName=null, indexType=null}, java.nio.HeapByteBuffer[pos=0 lim=3 cap=3]=ColumnDefinition{name=6b6579, validator=org.apache.cassandra.db.marshal.IntegerType, type=PARTITION_KEY, componentIndex=null, indexName=null, indexType=null}, java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]=ColumnDefinition{name=76616c7565, validator=org.apache.cassandra.db.marshal.DoubleType, type=COMPACT_VALUE, componentIndex=null, indexName=null, indexType=null}},compactionStrategyClass=class org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy,compactionStrategyOptions={},compressionOptions={sstable_compression=org.apache.cassandra.io.compress.LZ4Compressor},bloomFilterFpChance=<null>,memtable_flush_period_in_ms=0,caching=KEYS_ONLY,defaultTimeToLive=0,speculative_retry=NONE,indexInterval=128,populateIoCacheOnFlush=false,droppedColumns={},triggers={}]
INFO 17:39:26,349 CFS(Keyspace='system', ColumnFamily='schema_columnfamilies') liveRatio is 5.344978165938865 (just-counted was 5.344978165938865).  calculation took 0ms for 25 cells
INFO 17:39:26,349 Enqueuing flush of Memtable-schema_keyspaces@2042821730(138/8832 serialized/live bytes, 3 ops)
WARN 17:39:26,350 setting live ratio to maximum of 64.0 instead of Infinity
INFO 17:39:26,351 CFS(Keyspace='system', ColumnFamily='schema_keyspaces') liveRatio is 64.0 (just-counted was 64.0).  calculation took 1ms for 0 cells
INFO 17:39:26,351 Writing Memtable-schema_keyspaces@2042821730(138/8832 serialized/live bytes, 3 ops)
INFO 17:39:26,368 Completed flushing var/lib/cassandra/data/system/schema_keyspaces/system-schema_keyspaces-jb-79-Data.db (177 bytes) for commitlog position ReplayPosition(segmentId=1405696976943, position=238330)
INFO 17:39:26,373 Enqueuing flush of Memtable-schema_columnfamilies@200691258(1145/6120 serialized/live bytes, 25 ops)
INFO 17:39:26,373 Writing Memtable-schema_columnfamilies@200691258(1145/6120 serialized/live bytes, 25 ops)
INFO 17:39:26,381 Completed flushing var/lib/cassandra/data/system/schema_columnfamilies/system-schema_columnfamilies-jb-74-Data.db (787 bytes) for commitlog position ReplayPosition(segmentId=1405696976943, position=238330)

有一个有趣的caching=KEYS_ONLY 参数,它似乎与 pycassaShell 输出相矛盾,但与此键缓存大小的大小无关,与行缓存无关。无论我输入key_cache_size=2000000 还是None,我都会得到相同的输出。

那么有人知道如何通过 pycassa 做到这一点吗?

【问题讨论】:

    标签: python caching cassandra thrift pycassa


    【解决方案1】:

    您使用的是哪个版本的 Cassandra? pycassa 在列族属性方面有点过时了(尤其是在 pycassaShell 中)。

    key_cache_sizerow_cache_size 在 Cassandra 1.1 的 cassandra.yaml 中被替换为全局选项(key_cache_size_in_mbrow_cache_size_in_mb)。 caching 选项是您应该为每个列族设置的选项,它可以设置为 KEYS_ONLYROWS_ONLYALLNONE

    附带说明一下,此时您通常应该使用 cqlsh 而不是 cassandra-cli 和 python CQL driver 而不是 pycassa(我维护两者),尤其是对于新项目。

    【讨论】:

    • 谢谢!好吧,实际上它并没有改变性能,但由于我的请求没有磁盘访问,我猜行缓存正在工作。我的问题是我有一个包含 37 列和 5735 个键的列族,我很少在其中写入,但我经常需要完全阅读它,我尝试使用 CQL 驱动程序来解决这个非常具体的问题,SELECT * 几乎是 3比 pycassa 的 get_range() 慢几倍,我想这与结果的分页有关,但在任何一种情况下都没有控制它的选项,除了在我的程序端缓存它之外还有什么想法吗?
    • 啊刚刚找到SimpleStatementfetch_size arg。但是我仍然有一个PagedResult,并且在迭代它时它显然会阻止每 5000 个条目,无论我输入什么fetch_size
    • 好的,所以我手动覆盖了我的Session.default_fetch_size,因为它显然不适用于SimpleStatementfetch_size arg,现在它可以工作了,但它仍然比 pycassa 慢 50% get_range()(5.2 秒对 3.6 秒)。我想知道为什么这么小的桌子这么慢......
    • 刚刚尝试将 cassandra 数据目录放入 tmpfs 以确保没有任何更改,我想一切都从一开始就在文件缓存中。不过,我发现检索这张小桌子非常慢。