你会如何​​设计一个社交网站如Twitter的AppEngine上的数据存储? [英] How would you design an AppEngine datastore for a social site like Twitter?

查看:168
本文介绍了你会如何​​设计一个社交网站如Twitter的AppEngine上的数据存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道什么是设计一个社交应用,会员做活动和使用谷歌的AppEngine跟随其他成员的活动的最佳方式。

I'm wondering what would be the best way to design a social application where members make activities and follow other member's activities using Google AppEngine.

要更具体的让我们假设我们有这些实体:

To be more specific lets assume we have these entities:


  • 用户谁拥有的朋友

  • 活动这将重新由用户所做的present动作(可以说每个人都有一个字符串消息和的ReferenceProperty其拥有者的用户,也可以通过AppEngine上的主要使用家长协会)

  • Users who have friends
  • Activities which represent actions made by users (lets say each has a string message and a ReferenceProperty to its owner user, or it can use parent association via appengine's key)

困难的部分是跟随你的朋友的活动,这意味着从聚合所有好友的最新活动。
通常情况下,这将是活动表,您的好友列表之间的连接,但是那不是一个可行的设计AppEngine上,因为没有联接模拟它需要发射了N次查询(其中N是朋友号码),然后在内存中合并 - 非常昂贵,而且可能会超出要求期限...)

The hard part is following your friend's activities, which means aggregating the latest activities from all your friends. Normally, that would be a join between the Activities table and your friends list but thats not a viable design on appengine as there are no join simulating it will require firing up N queries (where N is number of friends) and then merging in memory - very expensive and will probably exceed request deadline...)

我目前想实现这一点使用收件箱在哪里排队一个新的活动的创建将触发一个后台进程,将放在新的活动的重点在收件箱的每一个下列用户的:

I'm currently thinking of implementing this using inbox queues where creation of a new Activity will fire a background process that will put the new activity's key in the "inbox" of every following user:


  • 入门所有谁遵循X上的用户是一个可能的AppEngine上查询

  • 不是一个非常昂贵的批量输入到一个新的收件箱实体店基本上(用户,活动密钥)元组。

我会很高兴听到想到这种设计或替代的建议等。

I'll be happy to heard thought on this design or alternative suggestions etc.

推荐答案

看看的 PDF>构建可扩展的,复杂的应用程序),在谷歌I /由Brett斯拉特金o给定一个迷人的谈话。他谈到建立类似Twitter的一个可伸缩的消息服务的问题。

Take a look at Building Scalable, Complex Apps on App Engine (pdf), a fascinating talk given at Google I/O by Brett Slatkin. He addresses the problem of building a scalable messaging service like Twitter.

下面是他的解决方案使用列表属性:

Here's his solution using a list property:

class Message(db.Model):
    sender = db.StringProperty()
    body = db.TextProperty()

class MessageIndex(db.Model):
    #parent = a message
    receivers = db.StringListProperty()

indexes = MessageIndex.all(keys_only = True).filter('receivers = ', user_id)
keys = [k.parent() for k in indexes)
messages = db.get(keys)

这关键只查询查找信息指数与接收等于你没有反序列化和序列化接收器的列表中指定的人。然后使用这些指数只抓取您想要的信息。

This key only query finds the message indices with a receiver equal to the one you specified without deserializing and serializing the list of receivers. Then you use these indices to only grab the messages that you want.

下面的错误的方式以做到这一点:

class Message(db.Model):
    sender = db.StringProperty()
    receivers = db.StringListProperty()
    body = db.TextProperty()

messages = Message.all().filter('receivers =', user_id)

这是低效的,因为查询必须解包所有您的查询返回的结果。所以,如果你在每个接收器列表1000用户返回100的邮件,你不得不反序列化100,000(100×1000)列表的属性值。太贵了数据存储中的延迟和CPU。

This is inefficient because queries have to unpackage all of the results returned by your query. So if you returned 100 messages with 1,000 users in each receivers list you'd have to deserialize 100,000 (100 x 1000) list property values. Way too expensive in datastore latency and cpu.

我起初是由这一切弄得pretty,所以我写了一个的 -dbl>简短的教程。享受:)

I was pretty confused by all of this at first, so I wrote up a short tutorial about using the list property. Enjoy :)

这篇关于你会如何​​设计一个社交网站如Twitter的AppEngine上的数据存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆