太多的写操作 [英] Too Many Write Ops

查看:125
本文介绍了太多的写操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序引擎(python)的目录应用程序,我遇到了太多的写操作问题。第一个问题是我有一个.NET脚本,它通过一个excel文件并将数据发布到我应用程序中的一个页面。当我运行它时,它已经获得了大约700条记录,并且我已经使用了我的写操作配额的75%。当我编写一个脚本来更新我的所有模型以为每个属性设置一个搜索字段时,就会发生同样的事情。我在大约20秒内从75%的配额上涨到96%,并且我在短时间内获得了太多写入的临时配额限制。我认为这个问题可能与索引有关,但当涉及到python和appengine时,我就是一个新手。以下是我的模型:

$ p $ class AlumniEntry(db.Model):
为单个模型校友
author = db.UserProperty()
entered = db.DateTimeProperty(auto_now_add = True)
title = db.StringProperty()
first_name = db.StringProperty必需=真)
first_name_search = db.StringProperty()
maiden_name = db.StringProperty()
maiden_name_search = db.StringProperty()
spouse_name = db.StringProperty()
spouse_name_search = db.StringProperty()
grad_year = db.StringProperty(required = True)
elementary = db.StringProperty(choices =('yes','no','idk'),default ='idk')

class LastName(db.Model):
entry = db.ReferenceProperty(AlumniEntry,collection_name ='last_names')
last_name = db.StringProperty = True)
last_name_search = db.StringProperty()

PhoneNumber(db.Model):
entry = db.ReferencePro perty(AlumniEntry,collection_name ='phone_numbers')
number = db.PhoneNumberProperty(default = None)

class Email(db.Model):
entry = db.ReferenceProperty(
email = db.EmailProperty(default = None)
email_search = db.EmailProperty(default = None)

class Address(db.Model ):
entry = db.ReferenceProperty(AlumniEntry,collection_name ='addresses')
street = db.StringProperty()
street_search = db.StringProperty()
city = db。 StringProperty()
city_search = db.StringProperty()
state = db.StringProperty()
state_search = db.StringProperty()
zip_code = db.StringProperty()

class UserAuth(db.Model):
added_by = db.StringProperty(required = True)
user_id = db.StringProperty(required = True)
indexed = False
,否则每个属性都会索引两次(一次升序,一次降序)。

请参阅 http://code.google。 com / appengine / docs / python / datastore / propertyclass.html#属性



在您的情况下,如果 street_search 是用于搜索的标准化形式 street ,然后将 street 标记为索引= False 会节省2次写入。


I'm developing a directory app on app-engine (python) and I've run into trouble with too many write ops. The first issue is that I have a .NET script that goes through an excel file and posts the data to a page in my app. When I ran it, it got through around 700 records and I had already used 75% of my write ops quota. The same thing happened when I wrote a script to update all of my models to have a search field for each property. I went from 75% of the quota filled to 96% in around 20 seconds and I got a temporary quota limit for too many writes in a short amount of time. I think the issue might be related to indexes but I'm sort of a newb when it comes to python and appengine. Here are my models :

class AlumniEntry(db.Model):
    """Models an entry for a single alumni"""
    author = db.UserProperty()
    entered = db.DateTimeProperty(auto_now_add=True)
    title = db.StringProperty()
    first_name = db.StringProperty(required=True)
    first_name_search = db.StringProperty()
    maiden_name = db.StringProperty()
    maiden_name_search = db.StringProperty()
    spouse_name = db.StringProperty()
    spouse_name_search = db.StringProperty()
    grad_year = db.StringProperty(required=True)
    elementary = db.StringProperty(choices=('yes', 'no', 'idk'), default='idk')

class LastName(db.Model):
    entry = db.ReferenceProperty(AlumniEntry, collection_name='last_names')
    last_name = db.StringProperty(required=True)
    last_name_search = db.StringProperty()

class PhoneNumber(db.Model):
    entry = db.ReferenceProperty(AlumniEntry, collection_name='phone_numbers')
    number = db.PhoneNumberProperty(default=None)

class Email(db.Model):
    entry = db.ReferenceProperty(AlumniEntry, collection_name='emails')
    email = db.EmailProperty(default=None)
    email_search = db.EmailProperty(default=None)

class Address(db.Model):
    entry = db.ReferenceProperty(AlumniEntry, collection_name='addresses')
    street = db.StringProperty()
    street_search = db.StringProperty()
    city = db.StringProperty()
    city_search = db.StringProperty()
    state = db.StringProperty()
    state_search = db.StringProperty()
    zip_code = db.StringProperty()

class UserAuth(db.Model):
    added_by = db.StringProperty(required=True)
    user_id = db.StringProperty(required=True)

解决方案

Unless you target a property in a search (or use it for ordering), making them unindexed saves index writes. Each property is indexed twice (once ascending, once descending) unless either the property type is inherently unindexed, or you set indexed=False.

See http://code.google.com/appengine/docs/python/datastore/propertyclass.html#Property

In your case, if street_search is a normalized form of street used for searching, then marking street as indexed=False will save 2 writes.

这篇关于太多的写操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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