Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python google app engine数据存储性能差,而数据输入具有更多属性_Python_Google App Engine_Google Cloud Datastore - Fatal编程技术网

Python google app engine数据存储性能差,而数据输入具有更多属性

Python google app engine数据存储性能差,而数据输入具有更多属性,python,google-app-engine,google-cloud-datastore,Python,Google App Engine,Google Cloud Datastore,版本1 class ActionLog(db.Model): action = db.StringProperty() time_slice = db.IntegerProperty() trace_code = db.StringProperty() # which profile this log belong to # Who facebook_id = db.StringProperty() # the user's facebook

版本1

class ActionLog(db.Model):
    action = db.StringProperty()
    time_slice = db.IntegerProperty()
    trace_code = db.StringProperty()    # which profile this log belong to

    # Who
    facebook_id = db.StringProperty()   # the user's facebook id
    ip = db.StringProperty()            # the user's ip address

    # When
    time = db.DateTimeProperty(auto_now_add=True)   # the time of this event

    # What
    url = db.StringProperty()           # the imgurl
    secret = db.StringProperty()        # the secret of imgurl instance
    tag = db.StringProperty()           # the tag
    referurl = db.StringProperty()      # the tag's link

    # Where
    weburl = db.StringProperty()        # the user's refer url
    domain = db.StringProperty()        # the refer url's domain
    BSP = db.StringProperty()           # the refer url's BSP

#execute
log = ActionLog(action=action,
        trace_code=trace_code,
        facebook_id=facebook_id,
        ip=ip,
        time_slice=time_slice,
        url=url,
        secret=secret,
        tag=tag,
        referurl=referurl,
        weburl=weburl,
        domain=domain,
        BSP=BSP)

db.put(log)
版本2

class ActionLog(db.Model):
    trace_code = db.StringProperty()
    url = db.StringProperty()
    secret = db.StringProperty()

    # use a dict like text property to store all implicit properties.
    desp = MyDictProperty() 
    time = db.DateTimeProperty(auto_now_add=True)   # the time of this event

#execute
log = ActionLog(
                    secret = secret,
                    url = url,
                    trace_code = trace_code,
                    desp = {
                            'action':action,
                            'facebook_id':facebook_id,
                            'ip':ip,
                            'tag':tag,
                            'referurl':referurl,
                            'weburl':weburl,                            
                            }
                    )

db.put(log)
这两个版本的代码基本上执行相同的任务,但是,版本1的代码在google app engine上执行简单的put操作(黄色或红色指示灯)的CPU时间将超过800毫秒。在合同中,版本2代码仅使用约300ms。(两种测试均在HRD数据存储上进行)

在M/S数据存储上,版本1代码将使用约400ms,版本2代码将使用约150ms

我可以想象版本1会比版本2慢,因为它使用了更多的键索引。然而,很难相信差别如此之大。同样令人惊讶的是,谷歌应用程序引擎无法处理如此简单的任务

这是否意味着我们不能期望GAE对具有10个以上属性的数据执行insert 还是我误解了什么


thx

对所有不需要索引的属性(即查询中不使用的属性)设置
index=False
。这减少了保存实体所需的索引写入次数


请参阅以获取解释。

第一个模型有13个索引属性,而第二个模型只有5个。第一个需要更多的时间,这并不奇怪——正如Dave所建议的,可以通过将属性设置为未索引来减少时间

这是否意味着我们不能期望GAE使用 超过10家酒店,或者我有什么误解吗

appengine执行插入操作很好-您只需做好准备,就可以花费更多的时间和更多的操作成本