【问题标题】:Cassandra performance: update columns per rowsCassandra 性能:每行更新列
【发布时间】:2017-06-15 13:11:15
【问题描述】:

当我们在一个查询中增加每行要更新的列数时,cassandra 的性能会提高还是降低。

说我们有一个最好的表组(例如 FB 组):

1/table Group(groupId Int, name String, members Map(userId -> roles))

2/表组(groupId Int, name String, admins Set[Int], moderators Set[Int], simpleMembers Set[Int])

我们假设用户可以拥有版主和管理员角色 因此,当删除此用户时,我们必须在第二种方法中更新 2 列管理员和版主,而在第一种方法中,我们必须只更新列成员。

【问题讨论】:

    标签: cassandra phantom-dsl


    【解决方案1】:

    来自 Marko 的 cmets 的 Copid --

    Basically the write performance will not be affected but the read performance will suffer if you have very
    very long rows and always read stuff from the back of it. 
    Over time when you insert the data cassandra will also have to read more sstables to satisfy your read requests, 
    so with time read performance will degrade if you are not careful
    

    我只想考虑避免删除。如果我们可以设计上述用例来避免删除。

           create table groups(
            groupid int,
            userid int,
            groupName text static, 
            attributes Map( text , text),
            primary key (groupid,userid)
        );
    

    查询 --

    insert into groups (groupid,userid,groupName,attributes) values (100,200,'friends',{'admin':'false','moderator':'true','user-member':'true'});
    
    update groups set attributes['admin'] = 'true' where groupid=100 and userid = 200;
    

    这样我们就不必删除表中的任何值。同样在未来,如果我们想添加新的属性,我们不必改变表定义。

    【讨论】:

    • 假设您的群组中有 1000 名成员。当组名更改时,您必须更新 1000 行。这不是很糟糕吗?
    • 我们可以保持组名不变
    • 基本上写入性能不会受到影响,但如果您的行非常长并且总是从后面读取内容,则读取性能会受到影响。随着时间的推移,当您插入数据时,cassandra 还必须读取更多的 sstable 以满足您的读取请求,因此如果您不小心,随着时间的推移读取性能会下降。
    • @Gunwant 所做的事情是正确的,只是组的静态列,你会没事的。此外,如果单个组中有 100 000 个用户,您可能需要引入分桶。你有超过这个数量的用户吗? (数千个很好......如果还有更多,请告诉我:p)
    • @MarkoŠvaljek 和 Gunwaant 谢谢,不,大约有 100 000 个用户,嗯,当更关心读取性能时,第一个是最快的吗?我实际上有关于该组的其他信息,我不想为每一行都进行数据冗余,在我的情况下似乎太多了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    相关资源
    最近更新 更多