0

In my flask application , we are observing very high memory and cpu consumption almost 100% CPU and memory for one of the API call. We are using flask-rest-json api package . In our model we have many tables like

TABLE A - Parent Table B - Child of A ( table a id as FK) Table C - Child of B ( table C id as FK) ---> Very high Memory / CPU

In addition to above table we have many other related tables (parent - child ) also .

Table A is like recording session which contains many videos ( Table B) which contains many images ( Table C) . So for 30 min recording session we have 30 clips of videos and then 30 * 30 = 900 images.

We have created relationships between tables using db.relationship so that we can use filter operations as well.

Once we trigger the url having high cpu / memory usage , wsgi process kill itself and then restart .

Please let me know to debug this issue . WE suspect issue in db relationships .

nja
  • 67
  • 2
  • 13

1 Answers1

0

Are you storing video data directly in your database as a BLOB? don't. if so, just store the video as a separate file in a folder, and just the path to the video in the database.

Can't help more if you don't really say what the endpoint is doing. complex relationships may not be your issue.

LotB
  • 461
  • 4
  • 10
  • Thanks . As mentioned images or videos are not stored as blob but as url in db . I am using nginx to serve video or image file and may not be an issue. I have used multiple relationships in my models like below . videoclips = db.relationship('VideoClip', backref='images', lazy='joined') Is it related to using Joined parameter . I have used joined so to use filter on relationships using flask-rest-jsonapi package . – nja Oct 26 '19 at 07:46
  • hmm, you might want to look into some circular lookup issue maybe? like, maybe you're building a query based on relationships that interact with each-other in a catch-22 way, such that they can't resolve unless they're all resolved... – LotB Oct 26 '19 at 08:45