我想使用 Cassandra 来存储会话相关信息。我没有真正的 HTTP 会话 - 它是不同的协议,但概念相同。
Memcached 没问题,但我想另外保存数据。
Cassandra 设置:
- 非复制键空间
- 单列族,其中键是会话 ID,行中的每一列存储单个键/值 - (
Map>
)
- 列 TTL = 10 分钟
- 写入 CL = 1 次
- 读取 CL = 1
- 2.000 次写入/秒
- 5.000 次读取/秒
数据示例:
session1:{ // CF row key
{prop1:val1, TTL:10 min},
{prop2:val2, TTL:10 min},
.....
{propXXX:val3, TTL:10 min}
},
session2:{ // CF row key
{prop1:val1, TTL:10 min},
{prop2:val2, TTL:10 min},
},
......
sessionXXXX:{ // CF row key
{prop1:val1, TTL:10 min},
{prop2:val2, TTL:10 min},
}
在这种情况下,一致性不是问题,但性能可能会出现问题,尤其是磁盘IO。
由于会话中的数据保留时间很短,因此我想避免将其存储在硬盘驱动器上 - 除了提交日志之外。
我有一些问题:
- 如果列在将其刷新到 SSTable 之前在 Memtable 中过期,将
Cassandra 无论如何将此类列存储在 SSTable 中(将其刷新到 HDD)?
- 我的密钥空间禁用了复制,在这种情况下,没有必要将此类过期列存储在 SSTable 中,对吧?
- 每个 CF 帽子最多 10 列。在这种情况下,我将启用行缓存并禁用键缓存。但我希望我的数据保持不变
在 Memtable 中可用,在这种情况下我可以禁用整个缓存,对吧?
- 对于此类会话存储用例的任何 Cassandra 配置提示将不胜感激:)
谢谢,
马切伊
I would like to use Cassandra to store session related informations. I do not have real HTTP session - it's different protocol, but the same concept.
Memcached would be fine, but I would like to additionally persist data.
Cassandra setup:
- non replicated Key Space
- single Column Family, where key is session ID and each column within row stores single key/value - (
Map<String,Set<String,String>>
)
- column TTL = 10 minutes
- write CL = ONE
- read CL = ONE
- 2.000 writes/s
- 5.000 reads/s
Data example:
session1:{ // CF row key
{prop1:val1, TTL:10 min},
{prop2:val2, TTL:10 min},
.....
{propXXX:val3, TTL:10 min}
},
session2:{ // CF row key
{prop1:val1, TTL:10 min},
{prop2:val2, TTL:10 min},
},
......
sessionXXXX:{ // CF row key
{prop1:val1, TTL:10 min},
{prop2:val2, TTL:10 min},
}
In this case consistency is not a problem, but the performance could be, especially disk IO.
Since data in my session leaves for short time, I would like to avoid storing it on hard drive - except for commit log.
I have some questions:
- If column expires in Memtable before flushing it to SSTable, will
Cassandra anyway store such column in SSTable (flush it to HDD)?
- Replication is disabled for my Key Space, in this case storing such expired column in SSTable would not be necessary, right?
- Each CF hat max 10 columns. In such case I would enable row cache and disable key cache. But I am expecting my data to be still
available in Memtable, in this case I could disable whole cache, right?
- Any Cassandra configuration hints for such session-store use case would be really appreciated :)
Thank you,
Maciej
发布评论
评论(2)
这是我所做的 - 它工作正常:
在此设置中,将从内存表中读取数据,并且不会使用缓存。 Memtable 可以分配足够的堆来保存我的数据,直到它过期甚至更长时间。
将数据刷新到 SSTable 后,压缩将立即删除过期行,因为
gc_grace=0
。Here is what I did - and it works fine:
gc_grace to 0
- means delete columns on first compaction. This is fine, since data is not replicated.In this setup, data will be read from memtable and cache will be not used. Memtable can allocate enough heap to keep my data until it expires or even longer.
After flushing data to SSTable, compaction will immediately remove expired rows, since
gc_grace=0
.考虑到您的用例,如果我没记错的话,您希望将所有键值[sessionID=>sessionData]对保存在内存中,并且这些值每10分钟就会过期[意味着您不希望持久化]。
那么为什么你不能尝试像 redis 这样的内存存储呢?
来自文档:
Redis 是一个开源的高级键值存储。它通常被称为数据
结构服务器,因为键可以包含字符串、散列、列表、集合和排序集合。
由于你不需要复制redis主从架构甚至可能不会影响你
Redis支持TTL也
据我所知cassandra适用于广泛胖行[更多列更少行]而不是瘦行[前一个的转置]。您的用例似乎并非如此。
问候,
泰米尔语
Considering your use case if I'm not wrong you wish to have all your key value[sessionID=>sessionData] pairs in memory and those values will expire every 10min[Means you don't want persistence].
Then why can't you try something like redis which is a in-memory store.
From Doc:
Redis is an open source, advanced key-value store. It is often referred to as a data
structure server since keys can contain strings, hashes, lists, sets and sorted sets.
Since u don't need replication redis master slave architecture even might not affect you
Redis supports TTL also
AFAIK cassandra is good for wide fat rows[More columns less rows] rather skinny rows[transpose of previous]. Your use case doesn't seem so.
Regards,
Tamil