GAE数据存储性能与SQLi

2024-04-26 01:37:39 发布

您现在位置:Python中文网/ 问答频道 /正文

在dev服务器和生产服务器上使用GAE数据存储时,我看到了糟糕的性能。我有以下简化模型:

class Team(db.Model):
    name = db.StringProperty()
    # + 1 other property
    # home_games from Game
    # away_games from Game

class Game(db.Model):
    date = db.DateProperty()
    year = db.IntegerProperty()
    home_team = db.ReferenceProperty(Team, collection_name='home_games')
    away_team = db.ReferenceProperty(Team, collection_name='away_games')
    # + 4 other properties
    # results from TeamResults

class TeamResults(db.Model):
    game = db.ReferenceProperty(Game, collection_name='results')
    location = db.StringProperty(choices=('home', 'away'))
    score = db.IntegerProperty()
    # + 17 other properties

我只有一个索引,关于游戏的年份和日期。插入一个包含478支球队和786场比赛的小数据集需要大约50秒。一个简单的查询:

^{pr2}$

花了大约45秒。在

移动基于SQLite的数据集需要更大的存储空间。我的数据建模不好吗?数据存储就这么慢吗?在

编辑1
为了提供更多背景信息,我从用户上传的文件中插入数据。文件被上传到blobstore,然后我使用csv.reader去解析它。这种情况会定期发生,并且查询是基于cron作业运行的。在


Tags: 数据namefrom服务器gamehomedbmodel
3条回答

我看不到任何证据表明您正在对您的任何属性使用indexed=False。每个这样的属性在每次写入时都会额外进行两次写入(一次用于升序索引,一次用于降序索引)。这些加起来很快。在

你的问题是你一个接一个地插入这些记录

您需要使用批插入,请参见https://developers.google.com/appengine/docs/python/tools/uploadingdata

或者您可能希望插入记录列表,如文档中所述:

https://developers.google.com/appengine/docs/python/datastore/entities#Batch_Operations

您不需要批量加载程序,因为您已经上传了CSV。但您可以使用批插入。 请看以下提示:http://googleappengine.blogspot.nl/2009/06/10-things-you-probably-didnt-know-about.html 寻找:5。您可以批处理put、get和delete操作以提高效率

相关问题 更多 >