ryot icon indicating copy to clipboard operation
ryot copied to clipboard

High CPU usage

Open ellsclytn opened this issue 3 years ago • 115 comments

I've noticed that my Ryot container enters a state of high CPU usage daily.

image

The above shows CPU usage over a 48h period. It seems to recover temporarily around 00:00, which leads me to believe it's something happening within one of the daily background jobs, but I'm just not sure which one as of yet.

The biggest spike seems to happen around 03:23-03:26.

image

I looked at the logs (where I've set RUST_LOG=ryot=trace,sea_orm=debug), but there doesn't seem to be much to look at beyond a lot of SQL queries.

2023-10-25T03:23:39.161607Z DEBUG sea_orm::driver::sqlx_postgres: SELECT "collection_to_entity"."id", "collection_to_entity"."last_updated_on", "collection_to_entity"."collection_id", "collection_to_entity"."metadata_id", "collection_to_entity"."person_id", "collection_to_entity"."metadata_group_id", "collection_to_entity"."exercise_id" FROM "collection_to_entity" WHERE "collection_to_entity"."collection_id" = 2 AND "collection_to_entity"."metadata_id" = 479 LIMIT 1
2023-10-25T03:23:39.161894Z DEBUG sea_orm::driver::sqlx_postgres: UPDATE "collection_to_entity" SET "last_updated_on" = '2023-10-25 03:23:39 +00:00' WHERE "collection_to_entity"."id" = 10 RETURNING "id", "last_updated_on", "collection_id", "metadata_id", "person_id", "metadata_group_id", "exercise_id"
2023-10-25T03:23:39.163085Z DEBUG sea_orm::driver::sqlx_postgres: SELECT "user_to_entity"."id", "user_to_entity"."last_updated_on", "user_to_entity"."user_id", "user_to_entity"."num_times_interacted", "user_to_entity"."metadata_id", "user_to_entity"."exercise_id", "user_to_entity"."metadata_monitored", "user_to_entity"."metadata_reminder", "user_to_entity"."exercise_extra_information" FROM "user_to_entity" WHERE "user_to_entity"."user_id" = 1 AND "user_to_entity"."metadata_id" = 479 LIMIT 1
2023-10-25T03:23:39.164215Z TRACE ryot::background: Job: "AfterMediaSeen", Time Taken: 28ms, Successful = true
2023-10-25T04:00:00.003823Z TRACE ryot::background: Getting data from yanked integrations for all users
2023-10-25T04:00:00.004961Z DEBUG sea_orm::driver::sqlx_postgres: SELECT "user"."id" FROM "user" WHERE "user"."yank_integrations" IS NOT NULL

This is the last few lines of logs between 2023-10-25T03:23:00 to 2023-10-25T04:26:00.

I'm wondering if anyone is/has experienced similar, or might have some further leads I could explore.

ellsclytn avatar Oct 25 '23 07:10 ellsclytn

How much memory is used?

IgnisDa avatar Oct 25 '23 07:10 IgnisDa

image

Not much at all. Highest point is 64.1 MB

ellsclytn avatar Oct 25 '23 08:10 ellsclytn

  • can you attach a screenshot of your summary
  • send me an export as described in the exporting documentation. You can find my email in my GH profile.
  • what are you system specs? Maybe run neofetch and show me the output

IgnisDa avatar Oct 25 '23 08:10 IgnisDa

Thanks for helping out, will send across an export soon.

Could you tell me what sort of summary you're after? I.e. just the same stuff as I opened the issue with, or some more things.

Neofetch:

OS: Ubuntu 22.04.3 LTS x86_64
Host: B550I AORUS PRO AX
Kernel: 5.15.0-86-generic
Uptime: 7 days, 6 hours, 4 mins
Packages: 1014 (dpkg)
Shell: bash 5.1.16
Terminal: /dev/pts/0
CPU: AMD Ryzen 5 5500 (12) @ 3.600GHz
GPU: NVIDIA GeForce GTX 1070
Memory: 13628MiB / 15830MiB

ellsclytn avatar Oct 25 '23 09:10 ellsclytn

what sort of summary you're after

Just the one on your Ryot dashboard

Also what is your architecture? I remember someone reporting high cpu usage on arm64.

IgnisDa avatar Oct 25 '23 09:10 IgnisDa

Oh, that dashboard. Of course :grinning:

image

I'm on amd64. I'll also mention I'm on v3.0.0 of Ryot, though this has been happening for me since at least v2.24.0 (possibly earlier, unfortunately I didn't keep track that far back).

ellsclytn avatar Oct 25 '23 09:10 ellsclytn

Try updating Ryot to latest and see it it improves (i doubt it).

What do you use to monitor your server? I don't have any monitoring on my server so I don't know what an ideal cpu footprint should look like.

IgnisDa avatar Oct 25 '23 09:10 IgnisDa

Will do. I'll give it a day at least after updating before making any judgement calls on it. Just emailed you the export, too.

I'm using Grafana with Cadvisor and Prometheus. And then this dashboard template, along with pretty similar config to what they have in the readme (might have tweaked it a little bit for my setup).

ellsclytn avatar Oct 25 '23 09:10 ellsclytn

Can you tell me the versions of the prometheus, node-exporter, cadvisor, grafana? I suspect the dashboard template is outdated. It uses latest tags.

IgnisDa avatar Oct 25 '23 09:10 IgnisDa

Grafana: grafana-oss:9.1.1 Cadvisor: 0.47.2 node-exporter: 1.6.1 Prometheus: 2.47.2

I've also put my version of the dashboard (admittedly I've deleted some of the panels I never used) into a gist.

ellsclytn avatar Oct 25 '23 10:10 ellsclytn

Thanks!

IgnisDa avatar Oct 25 '23 10:10 IgnisDa

Unfortunately the behavior hasn't changed since updating. I might be a bit slow to get back to this, but I'm thinking of spinning up a separate Ryot instance, importing specific sections at a time (e.g. movies, shows, books) and observing the results to see if I can narrow down further.

ellsclytn avatar Oct 27 '23 22:10 ellsclytn

I'm seeing the same issue with high CPU on v3.2.5. Last 2 days: image

Similarly low memory usage: image

image

Also seeing big CPU spikes on the DB every night for 2 hours image

I'm assuming some kind of scheduled tasks running, but 2 hours is a long time to be spiking like that.

thespad avatar Oct 28 '23 23:10 thespad

Can you set env variable RUST_LOG=ryot=trace and then go to miscellaneous settings and recalculate summary. A log should appear telling you how much time the calculation step took. Does it take 2 hours?

IgnisDa avatar Oct 29 '23 01:10 IgnisDa

Mine was super quick! 23 seconds.

2023-10-29T03:00:36.036545Z TRACE ryot::background: Started job: "RecalculateUserSummary"
2023-10-29T03:00:59.599454Z TRACE ryot::background: Job: "RecalculateUserSummary", Time Taken: 23562ms, Successful = true

ellsclytn avatar Oct 29 '23 03:10 ellsclytn

Then it is not the summary calculation that takes up CPU. I recommend you wait for another day and observe the logs around the time when the CPU spike happens and see which job is causing them.

You can also change the timezone (via TZ env var) if you want the job to happen sooner.

IgnisDa avatar Oct 29 '23 03:10 IgnisDa

Another possible cause: do you have a lot of media in the watchlist and in progress collections? Also do you have a lot of explicitly monitored stuff (there's a filter for it in the list page)?

IgnisDa avatar Oct 29 '23 04:10 IgnisDa

image

Not a huge number there. Similarly for Explicitly Monitored, where the only thing that came up was 7 TV Shows.

I've also imported my export into a separate, v2.0.0 instance of Ryot, just to see if it behaves the same. I'll keep an eye on it and slowly bump the version on that second instance until I start seeing the behavior.

ellsclytn avatar Oct 29 '23 05:10 ellsclytn

Cool thanks!

IgnisDa avatar Oct 29 '23 05:10 IgnisDa

I am also fairly certain this usage spike is localized to your instance. Here are the metric of the public demo instance (which has a lot more media than yours):

image

So there must be something different about your setup that's causing the spikes.

IgnisDa avatar Oct 29 '23 05:10 IgnisDa