At Google IO I believe it was mentioned that TextProperty's are fine
for anything that you don't want indexed; They are no less efficient
than strings for short data. You might want to look into trying that
out with mime and type if you don't filter/order by them.

Other than that, I'd suggest trying to memcache the images, something
to the effect of:

id = int(id)
cache_key = 'ImageThumb:%i' % id
image = memcache.get(cache_key)
if not image:
    image = ImageThumb.get_by_id(id)
    if image:
        memcache.set(cache_key, image, 3600)
if image:
    self.response.headers['Content-Type'] = str(image.mime)
    self.response.out.write(image.thumb)
else:
    self.error(404)

In addition to that, I'd recommend you generate cache headers, in
particular etag and expiration. A good idea would be to generate the
etag when the ImageThumb is created, and then compare against that
from cache, before you write out the image. As an added bonus you
could store the etag on it's own in the cache, separate from the
image, and only pull out the actual image in case the etags don't
match.

On Sep 25, 4:59 am, iceanfire <[EMAIL PROTECTED]> wrote:
> I'm still having trouble with high-cpu warnings for thumbnails. This
> time around I took some profiler data to see what's causing it. But
> before I get into that here is the model i'm using:
>
> class ImageThumb(db.Model):
>   binId = db.IntegerProperty()
>   thumb = db.BlobProperty(default=None)
>   building = db.ReferenceProperty(Buildings)
>   apartment = db.ReferenceProperty(Apartments)
>   mime = db.StringProperty()
>   type = db.StringProperty(choices=['Floor Plan','Picture'])
>   created_by =  db.UserProperty()
>
> So here's the Profiler cpu data:
> 2538 function calls (2472 primitive calls) in 0.028 CPU seconds (rest
> of the data:http://docs.google.com/Doc?id=dgfxff5_30hc9tjsgg)
>
> But here's the warning: This request used a high amount of CPU, and
> was roughly 1.3 times over the average request CPU limit. High CPU
> requests have a small quota, and if you exceed this quota, your app
> will be temporarily disabled.
>
> Here's the megacycle info from the new Admin console: 1339mcycles 7kb
>
> Here's the code that pulls up the data for thumbnails:
> class Apt_thumb (webapp.RequestHandler):
>     def get(self,id):
>                 image = ImageThumb.get_by_id(int(id))
>                 if image:
>                         self.response.headers['Content-Type'] = 
> str(image.mime)
>                         self.response.out.write(image.thumb)
>                 else:
>                         self.error(404)
>
> The images stored are 4kb each in the datastore. As I said, I had this
> problem earlier, so I had taken out the full image and put that in its
> own Model. Clearly that didn't help.
>
> Any idea what's causing this high-cpu error & how I can fix it?
>
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to