shelfio / libreoffice-lambda-base-image

MIT License
30 stars 19 forks source link

Improve Cold Start Performance (by adding a smoke start during image build) #4

Closed vladholubiev closed 1 month ago

vladholubiev commented 2 years ago

Empirically found, that a cold start could be reduced from ~30s to ~5s if we smoke start LO during the Docker image build time so it can pre-create some bootstrap files that it does create during the first start.

jpike88 commented 2 years ago

keen on speed up cold start, +1

patrikmolsson commented 2 years ago

@vladgolubev - can you please post some example code that we can add to our own Dockerfile's to do this smoke start?

I tried this:

RUN touch /tmp/test.txt
RUN cd /tmp \
    && libreoffice7.3 --headless --invisible --nodefault --view --nolockcheck --nologo --norestore \
        --convert-to pdf --outdir /tmp /tmp/test.txt
RUN rm /tmp/test.*

Which runs correctly, but I still occasionally (very seldom) get the long ~20-30s startup times, where the majority of the time is attributed to the "duration", not the "init duration".

I've only received these startup times the first time I run the lambda after a code update Now it seems like it occurred for a lambda that not had been executed for a couple of days.

I can't say I see a difference with the code I posted above.

patrikmolsson commented 2 years ago

Hi @vladgolubev - any updates on this issue?

Have been trying different approaches here, but still no success in reducing the cold start time.

Would be happy to create a PR if I can get a bit more info :)

vladholubiev commented 2 years ago

@patrikmolsson I've just pushed the potential fix. For me, it improved cold start locally by >1s

See https://github.com/shelfio/libreoffice-lambda-base-image/commit/f2a0d52232751090321877ffec7a081305610422

patrikmolsson commented 2 years ago

Curious, that is basically what I had... Have you tested this on AWS as well?

I'll give this a shot anyways! Thanks for the update.

Another note: Don't you need to have the ENV variable set prior to your run? I.e. put ENV HOME=/tmp above your RUN touch ...?

vladholubiev commented 2 years ago

Don't you need to have the ENV variable set prior to your run? I.e. put ENV HOME=/tmp above your RUN touch

Good catch! Thanks! I've just pushed such change!

https://github.com/shelfio/libreoffice-lambda-base-image/commit/5acefce4b0ecc4e60ab5351452e6119e5629f6ea

I haven't gotten around to testing on AWS just yet.