.NET 8 Has Low Performance When Using Aspose.Slides in Docker

I created a WEB program using .NET 8 MVC and adopted Aspose.Slides. Instead of the NuGet version, I used the release version from the official website. Currently, I’ve found that when using the AddClone function of Slides in Docker, the performance is extremely low. This operation takes about 10 seconds on the development machine, but in Docker, it may take 5-10 minutes. I’d like to know the cause of this issue.
My dockerfile:

# 构建阶段
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
USER root
WORKDIR /app


# 复制项目文件并还原依赖
COPY ["PPTWeb.csproj", "."]
RUN dotnet restore

# 复制源代码并构建
COPY . .
RUN dotnet build -c Release -o /app/build
RUN dotnet publish -c Release -o /app/publish /p:UseAppHost=false

# 运行阶段
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app

# 安装必要工具(如ping)和Python环境
ENV DEBIAN_FRONTEND=noninteractive
#RUN apt-get update && apt-get install -y --no-install-recommends \
    #python3 \
    #python3-pip \
    #libreoffice-core \
    #libffi-dev \
    #libssl-dev \
    #&& apt-get clean \
    #&& rm -rf /var/lib/apt/lists/*

# 使用阿里云的 APT 源替换默认源
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list


# 更新并安装基础工具
RUN apt -y update && \
    apt install vim -y && \
    apt install python3-all -y && \
    apt install python3-pip -y && \
    apt install libgdiplus -y && \
    apt install -y  libc6-dev && \         
    apt install -y  ttf-mscorefonts-installer 

RUN ln -s /usr/lib/libgdiplus.so /lib/x86_64-linux-gnu/libgdiplus.so
# 安装LibreOffice
RUN  apt install libreoffice -y && \
     rm -rf /var/lib/apt/lists/*
 

# 安装Python依赖(分开安装可以更好地排查问题)
RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --break-system-packages openai
RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --break-system-packages pymilvus
RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --break-system-packages pillow 
RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --break-system-packages python-pptx
RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --break-system-packages numpy 
RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --break-system-packages pymupdf
# 复制发布的应用
COPY --from=build /app/publish .

# 设置生产环境变量(重要!)
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS=http://+:8080


RUN mkdir -p /app/wwwroot/Template
RUN mkdir -p /app/wwwroot/temp
# 确保脚本目录存在并复制脚本
RUN mkdir -p /app/Script
COPY --from=build /app/Script/splitppt.py /app/Script/
COPY --from=build /app/Script/milvusQuery.py /app/Script/
COPY --from=build /app/Script/createPPT.py /app/Script/
COPY --from=build /app/wwwroot/Template /app/wwwroot/Template
# 确保模板目录存在
RUN chmod -R 777 /app/wwwroot/Template
RUN chmod -R 777 /app/wwwroot/temp
# 暴露端口
EXPOSE 8080

# 设置入口点
ENTRYPOINT ["dotnet", "PPTWeb.dll"]

@id2700

Cause

The performance issue you’re experiencing with Aspose.Slides in a Docker environment compared to your development machine can be attributed to several factors. Docker containers may have different resource allocations, and the environment might not be optimized for performance. Additionally, the libraries and dependencies used in your Docker image might not be fully compatible or optimized for the .NET 8 runtime.

Solution

To improve performance, follow these steps:

  1. Resource Allocation: Ensure that your Docker container has sufficient CPU and memory allocated. Adjust these settings in your Docker configuration.

  2. Use the Latest Version: Confirm that you are using the latest version of Aspose.Slides, as performance improvements and bug fixes are often included in newer releases.

  3. Optimize Dockerfile: Review your Dockerfile for unnecessary installations or configurations that could slow down the container. For example, if you don’t need LibreOffice or Python dependencies, consider removing them.

  4. Profile Your Application: Utilize profiling tools to identify bottlenecks in your application. This will help you determine whether the issue lies within the Aspose.Slides library or elsewhere in your code.

  5. Run in a Different Environment: If feasible, test your application outside of Docker to compare performance. This will help ascertain if the issue is specific to the Docker environment.

Code

Here’s a minimal example of how you might structure your Dockerfile to focus on performance:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
COPY ["PPTWeb.csproj", "."]
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/publish .
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080
ENTRYPOINT ["dotnet", "PPTWeb.dll"]

Next Steps

  1. Adjust the resource limits for your Docker container.
  2. Test performance with the latest version of Aspose.Slides.
  3. Profile your application to identify performance bottlenecks.
  4. Consider running your application outside of Docker for comparison.

Please implement these steps and let me know if you need further assistance!

Sources:
[1]: How to Run Aspose.Slides in Docker - Aspose Documentation

I have also conducted the same demo on a Windows server with identical configurations, and the result remains consistent with the development environment, demonstrating fast speed. I still suspect that the performance issue is related to the “.so” files in the release version.

for (int i = 0; i < list.Count; i++)
{
    if (i == 0 || currSort != list[i].Sort)
    {
        currSort = list[i].Sort;
        destPresentation.Slides.AddClone(templateSlides[currSort]);//目录
    }
    var data = list[i];
    var filedata = allFileData[data.FileID];
    var slides = filedata.Slides;
    **destPresentation.Slides.AddClone(slides[data.PageNum - 1]); **//This line of code is slow
}

@id2700,
Thank you for contacting free support. We are sorry that you encountered this problem. We need more details to investigate the case. Please share the following additional files and information:

  • The sample presentation file
  • The Aspose.Slides version you are using

Thank you for your help. I am using Aspose.Slides, Version=25.6.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56. However, I’m sorry that I cannot provide the presentation file due to confidential information. I can only confirm that all elements in the presentation are original without any plugins or additional components, consisting mainly of numerous images and text contents.

@id2700,
Thank you for the additional information. Unfortunately, we need the sample presentation file to investigate the case. It would be helpful if you could remove the confidential information from the presentation and share the file.

When there are an especially large number of page elements, such as a single PPT page containing dozens of different boxes with text in each, the copying speed in Docker will be very slow.

@id2700,
To properly examine this matter, we’ll need you to provide the sample presentation file.

@andrey.potapov hi
demo - 副本.zip (3.0 MB)
This file can be copied within 1-2 seconds under the Windows system, but it takes 10 seconds or more in Docker.

@id2700,
Thank you for the sample presentation file. Unfortunately, I was unable to use your code example and reproduce the issue you described. With Aspose.Slides for .NET 25.6, I used the following code example:

using var templateSlides = new Presentation("demo - copy.pptx");
var slide = templateSlides.Slides[0];

using var destPresentation = new Presentation();

Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();

destPresentation.Slides.AddClone(slide);

stopwatch.Stop();
var elapsedSeconds = stopwatch.ElapsedMilliseconds / 1000;
Console.WriteLine($"Clone time: {elapsedSeconds} seconds");

Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

WORKDIR /source
COPY *.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -o /app

FROM mcr.microsoft.com/dotnet/aspnet:8.0

RUN apt-get update && apt-get install -y \
 libfontconfig1 \
 libfreetype6

WORKDIR /app
COPY --from=build /app .

ENTRYPOINT ["./NetcoreApp"]

Output:

Clone time: 0 seconds

The method AddClone completed in less than a second. Please check the issue carefully again and isolate the problem.