Improve getEdit() performance a bit #2821

Closed
opened 2015-07-24 16:46:13 +00:00 by wjt · 4 comments

I (programmatically) made an static edit with 13k clips, and the request times out when I try to watch it :-) so I spent some quality time with a profiler. The vast majority of time is spent JSONifying all the annotations for each clip. I found a couple of easy fixes, patches attached.

With these patches, 98% of time is still spent in Edit.get_layers. Within that:

File: /srv/pandora/pandora/edit/models.py
Function: get_layers at line 503

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   503                                               def get_layers(self, user=None):
   ...
   525       648       111992    172.8     49.1              for a in qs.order_by('start').select_related('user'):
   526       632        86694    137.2     38.0                  ll.append(a.json(user=user))

That 38% in Annotation.json is mostly get_entity():

File: /srv/pandora/pandora/annotation/models.py
Function: json at line 216

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   216                                               def json(self, layer=False, keys=None, user=None):
   ...
   235        28        44561   1591.5     65.2                  entity = self.get_entity()
   ...
   274       632         6168      9.8      9.0          subtitles = get_by_key(settings.CONFIG['layers'], 'isSubtitles', True)

It's hard to see how to do much better without changing the Annotations schema to have a nullable reference to the entity. Maybe that's one for another time.

I (programmatically) made an static edit with 13k clips, and the request times out when I try to watch it :-) so I spent some quality time with a profiler. The *vast* majority of time is spent JSONifying all the annotations for each clip. I found a couple of easy fixes, patches attached. With these patches, 98% of time is still spent in Edit.get_layers. Within that: ``` File: /srv/pandora/pandora/edit/models.py Function: get_layers at line 503 Line # Hits Time Per Hit % Time Line Contents ============================================================== 503 def get_layers(self, user=None): ... 525 648 111992 172.8 49.1 for a in qs.order_by('start').select_related('user'): 526 632 86694 137.2 38.0 ll.append(a.json(user=user)) ``` That 38% in Annotation.json is mostly get_entity(): ``` File: /srv/pandora/pandora/annotation/models.py Function: json at line 216 Line # Hits Time Per Hit % Time Line Contents ============================================================== 216 def json(self, layer=False, keys=None, user=None): ... 235 28 44561 1591.5 65.2 entity = self.get_entity() ... 274 632 6168 9.8 9.0 subtitles = get_by_key(settings.CONFIG['layers'], 'isSubtitles', True) ``` It's hard to see how to do much better without changing the Annotations schema to have a nullable reference to the entity. Maybe that's one for another time.
j added the
backend
label 2015-07-24 16:46:13 +00:00
j added this to the 14.04 milestone 2015-07-24 16:46:13 +00:00
j self-assigned this 2015-07-24 16:46:13 +00:00
j added the
normal
enhancement
labels 2015-07-24 16:46:13 +00:00
Author

Attachment 0001-Edit.json-preload-annotation-users.patch (1600 bytes) added

**Attachment** 0001-Edit.json-preload-annotation-users.patch (1600 bytes) added
Author

Attachment 0002-Annotation.json-hard-code-some-field-name-mappings.patch (1549 bytes) added

**Attachment** 0002-Annotation.json-hard-code-some-field-name-mappings.patch (1549 bytes) added
Owner

To support edits that large we might need to introduce pagination in the same way we for lists/find queries.

To support edits that large we might need to introduce pagination in the same way we for lists/find queries.
Owner

applied first patch and slightly modified version of second.

applied first patch and slightly modified version of second.
j added the
fixed
label 2015-08-02 14:23:24 +00:00
j closed this issue 2015-08-02 14:23:24 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: 0x2620/pandora#2821
No description provided.