Adding metadata via API takes way too long with recent Plex server versions

Server Version#: 1.32.4.7195
Player Version#: 4.110.1

Using a tool such as plex-meta-manager, starting with recent Plex versions, the time it takes to add items to a collection, or add a label to an item, takes about 15-25 seconds per item. With server version 1.29.2.6364, the same action can do multiple items (10-20) per second.

That’s not a typo.

Version 1.29.2.6364 - 10-20 additions per second.
Version 1.32.4.7195 - 15-25 seconds per item added.

Both of these timings are performed using the same version of Plex-meta-manager, and using the same library. The only thing that has changed is the Plex server version.

Any ideas why the latest version of Plex takes so much longer?

30 Likes

Which endpoint are you hitting? Can you provide server logs?

4 Likes

Thanks for your reply. PMM uses the PlexAPI Python library, but I’m not sure about specific endpoints.

I’m currently setting up a test server on 1.29.2.6364 where I will import a single library. Then I’ll do a run of PMM on that library, and grab the logs. After that I will update to 1.32.4.7195 and do the same run of PMM, and grab a new set of logs. That way you should have a good comparison between the two.

2 Likes

@drzoidberg33 Hi again, ok I’ve got some files for you.

Here’s what I did. First I created a brand new docker container to spin up a test Plex server using PMS 1.32.4.7195. I created a single library and pointed it to a folder containing 3051 movies, and I let Plex scan and import all the movies in that folder.

After that, I ran a Plex Meta Manager run that creates a bunch of different collections on that library. Some of the collections involve adding labels to movies, others are smart collections, and others still are simply a list of movies that are added to the collection.

Once that was done, I removed all the collections and labels, and downgraded PMS to 1.29.2.6364, and then ran the same Plex Meta Manager process to create the same collections.

1.32.4.7195 finished in 0:40:08
1.29.2.6364 finished in 0:08:41

Let me stress that the only thing that changed between these two runs was the Plex version. I can also observe that adding labels, deleting labels, deleting collections, etc. all take considerably longer in 1.32 than in 1.29.

I’m including two logs, one for the 1.29 run and another for the 1.32 run. I appended the Plex version numbers to the ends of the filenames of the zip files.

Please let me know if I can provide anything else, or run any other specific tests. I’m happy to do so. Thank you!

Plex Media Server Logs_2023-07-11_16-23-55 1.32.4.7195.zip (3.1 MB)
Plex Media Server Logs_2023-07-11_16-51-42 1.29.2.6364.zip (3.6 MB)

4 Likes

Thanks for the logs.

I haven’t been able to track down exactly what could have changed as there is just so much happening in the logs which is making it difficult.

One thing I can say is that Plex Meta Manager is making some very inefficient api calls and I’m not surprised these operations are slow. It seems to be making separate requests for each item where it could just do a single request and pass all the applicable ids.

If you could provide me with exactly which operation is causing the issue that would be useful as I don’t have enough time to trawl through the logs to try and figure that out.

3 Likes

If you are running PMM locally rather than via docker, you can prefix the command with something like this: PLEXAPI_CONFIG_PATH="/tmp/plexapi.ini" python3 .... with the contents of plexapi.ini being this:

[log]
backup_count = 10
format = %(asctime)s %(module)12s:%(lineno)-4s %(levelname)-9s %(message)s
level = DEBUG
path = /tmp/plex-api.log
rotate_bytes = 104857600
secrets = true
timeout = 600

This will create /tmp/plex-api.log with the appropriate API calls and their timestamps. That should make it much easier to track down the exact API calls which are running slowly.

It should also be possible to do this even if you run PMM via docker but that depends on exactly how you are calling it.

2 Likes

Hi, an example API call that is causing the issue is something like http://127.0.0.1:34400 "PUT /library/sections/1/all?id=12019&label.locked=1&label%5B0%5D.tag.tag=Prime%20Video%20Movies&type=1 HTTP/1.1" 200 0. This is the call that is made when a label is added to an item.

I know you said the API calls are inefficient, but the point remains that the slowdown is only happening with PMS 1.32. When using 1.29, the calls happen extremely fast and there is no issue with the slowdown.

1 Like

I am using Docker for both PMM and Plex. I’m currently calling PMM with docker run --rm --net=host --name=pmm --memory=40g -v ... (followed by whatever commands or flags are happening for that particular run.

I’ll try your method to get the plex-api.log file, but if you have any further info about how I can do this with docker, that would be great.

1 Like

You can add environment variables to the docker run command
like this: docker run | Docker Documentation

Make sure to mount the plexapi.ini file within the container as you do for the PMM config and specify the same path in the environment variable.

1 Like

im happy to make changes to make calls more efficiently. I’m currently just using the plexapi python module to make calls and as far as I was aware there wasnt a single call i could make to add the same collection tag / label to multiple items. if there is that would be wonderful and it could make things much more efficient

2 Likes

Here are some new files to hopefully help you narrow down the issue.

Also, as I was watching this run, I took note of a few timestamps where the API calls were taking a long time.

2023-07-12 15:16:14,588
2023-07-12 15:17:09,664
2023-07-12 15:19:34,994
2023-07-12 15:21:13,912
2023-07-12 15:28:48,558

There are several other times as well, but I think they should all point to the same issue.

Included is a log from PMM using the environment variable, along with a new Plex log from the same time.
Plex Media Server Logs_2023-07-12_11-55-00.zip (3.2 MB)
plex-api.log (1.1 MB)

Please let me know if I can provide anything else.

2 Likes
7 Likes

Can confirm my problems with the database hanging up have been fixed by downgrading to this version: 1.29.2.6364

Also, the speed of initial play from clients is a lot faster in this version. I think I’ll be staying in this version for a while. I realized a few weeks ago that the initial play was much longer than it used to take. I just thought it was something I did.

2 Likes

Same. I didn’t want to downgrade either but all pmm related issues involving api/metadata is now gone, pmm doesn’t take near as long to run now ( a difference of like 5 hours which is huge considering my runs were taking nearly 18 hours ) and I also notice all my clients start playing things much faster, about 1 to 2 seconds now (with media that is rcloned and mergerfs’d onto the server and not on the drive itself), when before it was at least 10 to 15 seconds before things would start playing

2 Likes

@drzoidberg33 I was wondering if you had a chance to look at those latest logs with timestamps. Regardless of the update in Python PlexAPI, the fact still remains that these API calls take much much longer with PMS 1.32 compared to 1.29. So I feel like it’s still worthwhile trying to figure out what’s going on.

1 Like

I can confirm that PMS 1.31.2.6810 in Windows 64 bit also performs well with PMM. My runs take on average the same amount of time as they did with 1.29. Hopefully this helps narrow the issue.

2 Likes

I’ve done some more digging and lots of testing, and I’ve determined that the problem exists between PMS versions 1.31.2.6810 and 1.31.3.6868.

Using Plex Meta Manager, I have a config file that deletes all collections, then deletes labels, and then adds back the collections and labels.

With PMS 1.31.2.6810 installed, this run takes around 11 minutes.

The very next version according to Dockerhub is 1.31.3.6868. Using this version of PMS, the same exact run takes around 40 minutes.

I should also point out that by watching the output as it’s running, I can confirm that deleting the collections and adding labels are what typically take a longer time with 1.31.3. On the older versions of PMS, those go by super fast. On 1.31.3 and later, each one of those actions takes long enough to notice the slowdown

I have repeated this test several times, with the same results. So there must be something that changed between these two versions, with regards to the API.

@drzoidberg33, please look into this further, now that we know the exact version affected. If there is any other info I can provide, please let me know and I’ll be happy to do what I can.

4 Likes

I, for one, will not be upgrading until this is resolved. Because of my large library, running PMM always causes the dreaded database lock sleeping for 200ms. The only resolution is to restart Plex to break free from the lock.

2 Likes

Has any progress been made on this? I’m tempted to roll-back my Plex version as I’m regularly coming up against the DB lock issue.

1 Like

I am using the very last plexpass version, and after initial scan having a lot of issue with waiting over 10seconds messages, when i run pmm i don’t seem to get it (or way less at least) but it’s very very slow, more than 10 times slower than version 1.29
I had to abord my initial PMM run after 48 hours, it didn’t even do half of what it’s supposed to do…
On version 1.29 it runs in like 2-4 hours.

EDIT : well in fact, when pmm do filters like “Gathering Items for airing_shows Overlay” i get the 10seconds issues … ==> Waited over 10 seconds for a busy database; giving up.
every few seconds…

1 Like