Skip to content

Major CPU performance decrease with ImageSharp.Web 3 #344

@marklagendijk

Description

@marklagendijk

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp.Web
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp.Web version

3.0.1

Other Six Labors packages and versions

None

Environment (Operating system, version and so on)

Azure App Service Windows

.NET version

7

Description

After upgrading to ImageSharp.Web 3 we noticed a major increase of CPU usage.
We then proceeded with steps to isolate the issue so we would be 100% sure that the version increase was indeed the cause:

  1. We isolated the usage of ImageSharp.Web to its own application + App Service.
  2. After a number of days we stepped down the version of ImageSharp.Web to version 2.
  3. After around half a day I took a screenshot of the CPU performance (see below). I could wait longer, but the difference is so clear that I don't think that will help.

Technical background

  • We run a multi-tenant web application that servers around 15 news websites.
  • ImageSharp.Web is used for image downsizing.
  • Azure FrontDoor is used as a pass-through CDN.
  • Azure FrontDoor is configured to cache all the image responses for 1 year.
  • Because Azure FrontDoor caches on the POP (point-of-presence) level, there are still numerous requests per image.
  • Azure App Service (Windows, .NET 7) is used for serving the web applications. At this point we separated the usage of ImageSharp.Web to its own App Service, although we still run it on the same VM (Azure App Service Plan).
  • We currently don't use caching on the ImageSharp.Web level, we configure a NullImageCache.
  • Before we switched to the NullImageCache we used the PhysicalFileSystemCache. It ended up breaking our App Service because we eventually ran out of disk space, because the cache does not remove old images (note: I now know that this is a non-trivial issue, I would propose making this more clear in the documentation).
  • The images are loaded with a custom RemoteImageProvider which uses HttpClient to load images from an url.
  • We use the PresetOnlyQueryCollectionRequestParser.

Background

A few weeks back I found out that version 3 of ImageSharp.Web was released. I also found out that the license had been changed.
After arranging the purchase of the license I upgraded.

Based on the release notes I expected to see a performance improvement, but unfortunately it quickly became clear that we instead had a performance decrease.

I explicitly waited with reporting the issue until I was 100% sure that it is caused by the ImageSharp.Web upgrade.
I checked the changelogs of ImageSharp.Web and ImageSharp, but I could not find any change that which might cause our issue.

I am willing to help with identifying the cause of the issue, but I would like some pointers with regards to how to proceed.

Steps to Reproduce

At this point the "Steps to Reproduce" are not clear beyond "Upgrade from ImageSharp.Web 2.0.2 to 3.0.1".
However, I can share all the relevant code that we use.

This is the library that contains all our ImageSharp.Web code.
PMP.ImageProcessing.zip

The PMP.ImageProcessing library is used in a minimal web application.
PMP.ImageProcessor.zip

Images

Screenshot-Metrics - Microsoft Azure — Mozilla Firefox-2023-11-03 09_17_21

The red arrow indicates the point where the version 2 of ImageSharp.Web was deployed.
The graph shows that with ImageSharp.Web 3 both average and maximum CPU usage are at least 2 times higher.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions