从Cloud SQL迁移到DataStore [英] Migrate from Cloud SQL to DataStore

查看:96
本文介绍了从Cloud SQL迁移到DataStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建应用程序,我需要制作后期Feed。现在我使用基于 MySQL 的App Engine标准版和Cloud SQL实例 db-n1-standard-1 但我注意到它是非常贵。应用程序处于生产模式下,并在第一个月的价格远高于我的预期。 Cloud SQL中成本最高的是实例小时数因此,我决定将其迁移到数据存储上。



我有三个表格, 1 - 用户 2 - 3 comments 每个表格都包含大约10亿次以上的行。 帖子和评论表是
,增长速度非常快,预计有数百万行。

用户表

  user_id名称电邮电话
-------------------------------------------- ------
u123 abc abc@m.com 123456
u124 Cde cde@m.com 789065
u786 Qwe qwe@m.com 754599
。 。 。 。
。 。 。 。
。 。 。 。

发布表格

  post_id user_id类型src日期
----------------------------- -------------------------------------------
p098 u123 img path / to / file 13-3-17
p456 u123 vid path / to / file 14-3-17
p239 u124 img path / to / file 15-3-17
。 。 。 。 。
。 。 。 。 。
。 。 。 。 。

评论表

  cmnt_id post_id user_id comment 
------------------------------ --------------------------
m392 p098 u123一些文本
m234 p098 u786一些文本
m324 p456 u123一些文本
。 。 。 。
。 。 。 。
。 。 。 。

您可以看到 User 可以发布一个或多个 帖子和单个帖子
一个或多个我需要将发布数据与数据发布到发布 >发表评论我知道我需要为此使用
JOIN 。而且我可以在Cloud SQL中轻松使用它,因为它基于MySQL。

这三个表格有它们之间的关系,因为我知道Cloud SQL是关系数据库,但DataStore不是。



我想到在DataStore中转换这些表格



1 - 创建实体为用户并保存所有用户记录
2-创建实体为文章并保存全部帖子记录
3 - 创建实体为评论并保存所有评论记录

Post ID始终是我知道哪些帖子,我需要获取数据



例如,我需要关于ID p098

code>我正在使用 Java 我决定创建两个线程第一个线程获取 post 数据来自数据实体和第二个
线程获取注释数据来自评论实体。然后,我通过使用java合并这两个数据集,以生成与 JOIN 相同的结果,如 MySQL 因为我认为DataStore不是允许 JOINS



这里我需要一些建议。


  1. 这是一个很好的方法吗?

  2. 在这种情况下提供最佳性能?
  3. 如果成千上万的用户(大量用户)正在访问帖子和评论数据,那么同一时间
    哪一个可以更好地处理它?<​​/ li>
  4. 如果我在
    的情况下从Cloud SQL迁移到DataStore,那么价格效应如何?

  5. 如果您的应用程序需要连续的数据库,然后SQL实例运行连续的
    使其成本高昂,不是吗?
    例如在我的应用程序中每个用户打开应用程序时需要显示帖子如果
    是大量用户,那么我认为SQL实例永远不会关闭。其中
    表示它在一个月内运行 730小时

  6. 任何建议?


解决方案



我可能还有Posts作为User实体的用户



<所以你最终得到一个像这样的结构:




|用户,123 | - > |帖子,456 | - > |评论,789 |
(Grand Dad)(爸爸)(Child)



编辑:Tim Hoffman是对的,评论应该是User的孩子,而不是User> Post。

I'm creating App where I need to make Post Feeds. Right now I'm using App Engine Standard and Cloud SQL instance db-n1-standard-1 which is based on MySQL But I notice it is very expensive. App is under production mode and In first month price is much higher than my expectation. Most costly thing in Cloud SQL is instance hours rate So, I decide to migrate it on datastore.

I have three tables, 1- users 2- posts 3- comments And Every Table has round about 10 Millions Rows. Posts and Comments table are growing very fast 100 of millions rows are expected.

Users Table

user_id         name        email           phone
--------------------------------------------------
u123            Abc         abc@m.com       123456
u124            Cde         cde@m.com       789065
u786            Qwe         qwe@m.com       754599
 .               .              .               .
 .               .              .               .
 .               .              .               .

Posts Table

post_id         user_id         type        src                 date
------------------------------------------------------------------------
p098            u123            img         path/to/file        13-3-17
p456            u123            vid         path/to/file        14-3-17
p239            u124            img         path/to/file        15-3-17
 .               .               .              .                   .
 .               .               .              .                   .
 .               .               .              .                   .

Comments Table

cmnt_id         post_id         user_id         comment
--------------------------------------------------------
m392            p098            u123            Some Text
m234            p098            u786            Some Text
m324            p456            u123            Some Text
 .               .               .                .
 .               .               .                .
 .               .               .                .

As you can see User can post one or more posts and single post has one or more comments

I need to get posts data along with post comments I know I need to use JOIN for this. And I can easily use it in Cloud SQL because it's based on MySQL.

These three tables have relation between them and As I know Cloud SQL is relational database but DataStore is not.

I have idea in my mind to convert these tables in DataStore

1- Create Entity as Users and save all users records there 2- Create Entity as Posts and save all posts records there 3 - Create Entity as Comments and save all comments records there

Post id is always I know for which post I need to get data

For example I need post data about id p098 I'm using Java I decide to create two threads First thread get post data from Posts Entity and second thread get comment data from Comments Entity. Then I merge these two data set by using java to generate same result as JOIN Like MySQL Because I think DataStore is not allow JOINS

Here I need some Suggestions.

  1. Is it a good way to do that ?
  2. Which Provide the best Performance in this Situation ?
  3. If Thousands of User(Large Number of Users) is accessing Posts and Comments data as same time which one can handle it better ?
  4. What about Pricing Effect if I migrate from Cloud SQL to DataStore in this situation ?
  5. If your App need continuous database then SQL instance run continuous which make it high cost, isn't it ? For example in my App every user when open app need to show Posts if there is large number of users then I think SQL instance never shutdown. Which means it run 730 hr in a month.
  6. Any recommendation ?

解决方案

I would put Comments as Child entity of Posts. Query by Ancestors is faster than other queries for your Join.

I might also have Posts as Child entity of User

So you end up with a structure like:

| User, 123 | --> | Post, 456 | --> | Comment, 789 | (Grand Dad) (Dad) (Child)

EDIT: Tim Hoffman is right, Comment should be child of "User" and not "User > Post".

这篇关于从Cloud SQL迁移到DataStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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