9

I'm seeing some usual goings on in my application. For no reason my server slows down when I have little or no traffic. After lots of trial and error I found my problems disappeared when I removed the ToOneField on my TastyPie resource!

What I found was for some unknown reason TastyPie is doing DB UPDATES on these ToOneFields for no good reason! What the... moment!

enter image description here

I found a possible bug filed here which claims to have fixed the update issue. I have installed the latest version from pip but still see this problem.

Can anyone help?

class IncentiveResource(ModelResource):
    product_introducer = fields.ToOneField(ProductResource, 'referrer_product', full=True)
    product_friend = fields.ToOneField(ProductResource, 'referee_product', full=True)

    class Meta:
        queryset = Incentive.objects.all().order_by('-date_created')
        resource_name = 'incentive'
        allowed_methods = ['get']
        authentication = MultiAuthentication(ClientAuthentication(), ApiKeyAuthentication())
        authorization = Authorization()
        filtering = {
            "active": ALL,
        }
        always_return_data = True
        cache = SimpleCache(cache_name='resources', timeout=10)

So little traffic here but becomes unusable. enter image description here enter image description here

2
  • The profiling output shown above...what tool made that?
    – 8one6
    Commented Apr 8, 2014 at 1:27
  • @8one6 it's New Relic
    – Prometheus
    Commented Apr 8, 2014 at 13:40

2 Answers 2

2

I don't know if this will help you, but I've seen a slight performance increase in an app I worked on while using select_related in the queryset and full=True in the resource field.

Try queryset = Incentive.objects.select_related('product_introducer', 'product_friend').all().order_by('-date_created')

1
  • 1
    Hi Farhan thanks for the reply. Yes I also read this and I think it would help, however, the fact that Tastypie is doing the DB UPDATES for no good reason is my main concern.
    – Prometheus
    Commented Apr 6, 2014 at 8:38
0

Can you reproduce the sql UPDATEs in a testing environment?

If yes, here is how I would debug it:

Modify the source where the sql command gets executed: insert an assert statement that no update gets done.

If the assert fails, you have the stacktrace of the strange UPDATE.

If this stacktrace does not help you, post it here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.