Today my live Python application on App Engine had about 100 requests within a ten minute period for which an exception was thrown when writing a new entity to the datastore, due to "too much contention on these datastore entities". My app only writes one entity per request. Not all requests in this period failed; the majority were successful.
For weeks now the app has processed approx. 30k requests a day without problems, and I haven't seen the QPS exceed 20. In fact, there are examples of failed writes when there are gaps larger than one second between requests. I'm using the db library, here's the model definition:
class SiteImpression(db.Model):
remoteIPAddr = db.StringProperty(required=True)
aPersonID = db.StringProperty(required=True)
requestURI = db.TextProperty(required=True)
serverEnvironment = db.StringProperty(required=True)
requestDateTime = db.DateTimeProperty(required=True)
userAgent = db.TextProperty(required=True)
and the code to write to the datastore:
dtDateTime = datetime.now()
e = myd.SiteImpression(remoteIPAddr=strRemoteAddr,
aPersonID=straID,
requestURI=strRequestURI,
serverEnvironment=strEnvironment,
requestDateTime=dtDateTime,
userAgent=strUserAgent)
e.put()
From reading answers to this SO question, I gather this has to do with my indexed datetime property causing hot tablets (which I have read about here). I have a default index for this datetime property, and two custom indexes:
- kind: SiteImpression
properties:
- name: aPersonID
- name: serverEnvironment
- name: requestDateTime
direction: asc
- kind: SiteImpression
properties:
- name: serverEnvironment
- name: requestDateTime
direction: asc
My question: am I doing something wrong to cause these contention issues, or was is likely just a temporary issue with the datastore?
Thanks.