I added ~ 1/4 million simple Items last night and managed to consume
12 hours of CPU time in under 1.5 hours of wall clock time.
Here is the model, below is the code. I don't know how much simpler
this could get. Account and Tenant are essentially EMPTY objects
having keys and their name in the Key field as well, but otherwise
empty.
class FlatItem(db.Model):
account = db.ReferenceProperty(Account) populated with account
tenant = db.ReferenceProperty(Tenant) populated with tenant
refersto = db.SelfReferenceProperty() None
when = db.DateTimeProperty() populated
amount = db.FloatProperty() populated with random value
tax = db.FloatProperty() None
text = db.StringProperty(multiline=True) about 420 characters (not
sent in request)
image = db.BlobProperty() None
def post(self):
start = datetime.now()
account_keys = self.request.get('account_name',
allow_multiple=True)
added = 0
for account_key in account_keys:
account = Account.get_by_key_name(account_key)
if account == None:
self.error(404)
self.response.out.write("Account '%s' not found" %
self.request.get('account_name'))
return
try:
tenant = Tenant.get(self.request.get('tenant_key'))
if tenant == None:
raise db.BadKeyError
except db.BadKeyError:
self.error(404)
self.response.out.write("Tenant key '%s' not
found" % self.request.get('tenant_key'))
return
when = datetime.strptime(self.request.get('when'), "%Y/%m/
%d %H:%M:%S")
i = FlatItem(tenant=tenant, account=account,
amount=random.random()*400, when=when,
text="Flat %s blah blah blah blah..(~ 420
characters).. blah blah blah." % account.key())
key = i.put()
added += 1
end = datetime.now()
s = "Added %d Flat Item(s) in %d microseconds" % (added, (end-
start).microseconds,)
logging.info(s)
self.response.out.write("%s<br/><a href='/flatitems/add'>Add
more flat items</a>" % s)
Funny thing is I burned up the 12 hours I had to pay for FASTER than
the 6.5 hours I got for free.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---