Google 云数据存储。如何提供数据?
Google Cloud DataStore. How to serve data?
和许多人一样,我对 NoSQL 世界并不陌生。我做了很多研究,但我仍然缺少一点,我找不到合适的答案。
系统简介:
我正在构建一个收集不同网站访问者数据的系统。每次访问都是数据存储中的一个实体,具有设备类型、IP、访问时间等属性
数据存储中将有数百万次访问。
我的问题是如何将这些数据提供给客户。我的数据在数据存储中设置为 "Visit" 个实体。
现在,当客户登录时,我不想向他们展示数百万条记录。例如,我想向他们展示一般统计数据。例如在移动设备上的访问次数、某个时间范围内来自特定国家/地区的访问次数等等。
由于我是 NoSQL 数据库的新手,所以我不确定应该如何在客户的仪表板中显示这些统计数据。
据我所知,Datastore 不支持聚合,也不支持获取查询结果的计数。
我查看了 BigQuery,但 BigQuery 适用于 Datastore "backups",我需要实时提供数据,无需手动备份。
我还阅读了有关计数器和分片计数器的内容,这是正确的方法吗?每个跟踪组的每个 属性 的每个客户都有一个计数器?并以这种方式显示总数?对于一个简单的目的来说听起来太多了。
任何能使我朝着正确方向前进的意见或解释都将不胜感激。
此致
As I know, Datastore has no support for aggregates, or getting count
of query results for example.
这不是真的。您可以使用一行代码获取查询返回的多个实体。查询本身可以keys-only,速度很快,基本免费
是的,就性能而言,计数器是解决您的问题的好方法。但它们确实有一些缺点,例如存储大小以及每次您想要引入一种新类型的统计信息时,您都需要为其创建一个计数器。
除了您当前的 "Visit" 实体之外,您还可以选择将聚合数据存储在数据存储区的分片计数器中。这些计数器可以实时更新,也可以通过任务队列之一中的任务更新。创建一个将为当前访问实体创建各种计数器的任务将是相当直接的。
分片是一种创建多个 "underlying" 实体的方法,这些实体在组合时代表一些有意义的数据。进行分片是为了确保不会因并发更新而出现性能问题。
If you had a single entity that was the counter and the update rate
was too fast, then you would have contention as the serialized writes
would stack up and start to timeout. The way to solve this problem is
a little counter-intuitive if you are coming from a relational
database; the solution relies on the fact that reads from the App
Engine datastore are extremely fast and cheap. The way to reduce the
contention is to build a sharded counter – break the counter up into N
different counters. When you want to increment the counter, you pick
one of the shards at random and increment it. When you want to know
the total count, you read all of the counter shards and sum up their
individual counts. The more shards you have, the higher the throughput
you will have for increments on your counter. This technique works for
a lot more than just counters and an important skill to learn is
spotting the entities in your application with a lot of writes and
then finding good ways to shard them.
我建议您查看 link 以获取更多信息和一些有用的示例。
和许多人一样,我对 NoSQL 世界并不陌生。我做了很多研究,但我仍然缺少一点,我找不到合适的答案。
系统简介:
我正在构建一个收集不同网站访问者数据的系统。每次访问都是数据存储中的一个实体,具有设备类型、IP、访问时间等属性
数据存储中将有数百万次访问。
我的问题是如何将这些数据提供给客户。我的数据在数据存储中设置为 "Visit" 个实体。
现在,当客户登录时,我不想向他们展示数百万条记录。例如,我想向他们展示一般统计数据。例如在移动设备上的访问次数、某个时间范围内来自特定国家/地区的访问次数等等。
由于我是 NoSQL 数据库的新手,所以我不确定应该如何在客户的仪表板中显示这些统计数据。
据我所知,Datastore 不支持聚合,也不支持获取查询结果的计数。
我查看了 BigQuery,但 BigQuery 适用于 Datastore "backups",我需要实时提供数据,无需手动备份。
我还阅读了有关计数器和分片计数器的内容,这是正确的方法吗?每个跟踪组的每个 属性 的每个客户都有一个计数器?并以这种方式显示总数?对于一个简单的目的来说听起来太多了。
任何能使我朝着正确方向前进的意见或解释都将不胜感激。
此致
As I know, Datastore has no support for aggregates, or getting count of query results for example.
这不是真的。您可以使用一行代码获取查询返回的多个实体。查询本身可以keys-only,速度很快,基本免费
是的,就性能而言,计数器是解决您的问题的好方法。但它们确实有一些缺点,例如存储大小以及每次您想要引入一种新类型的统计信息时,您都需要为其创建一个计数器。
除了您当前的 "Visit" 实体之外,您还可以选择将聚合数据存储在数据存储区的分片计数器中。这些计数器可以实时更新,也可以通过任务队列之一中的任务更新。创建一个将为当前访问实体创建各种计数器的任务将是相当直接的。
分片是一种创建多个 "underlying" 实体的方法,这些实体在组合时代表一些有意义的数据。进行分片是为了确保不会因并发更新而出现性能问题。
If you had a single entity that was the counter and the update rate was too fast, then you would have contention as the serialized writes would stack up and start to timeout. The way to solve this problem is a little counter-intuitive if you are coming from a relational database; the solution relies on the fact that reads from the App Engine datastore are extremely fast and cheap. The way to reduce the contention is to build a sharded counter – break the counter up into N different counters. When you want to increment the counter, you pick one of the shards at random and increment it. When you want to know the total count, you read all of the counter shards and sum up their individual counts. The more shards you have, the higher the throughput you will have for increments on your counter. This technique works for a lot more than just counters and an important skill to learn is spotting the entities in your application with a lot of writes and then finding good ways to shard them.
我建议您查看 link 以获取更多信息和一些有用的示例。