crossplane / function-sdk-python

The Python SDK for composition functions
Apache License 2.0
7 stars 6 forks source link

Python functions shut down slowly #109

Open fernandezcuesta opened 1 week ago

fernandezcuesta commented 1 week ago

What happened?

I'm not fully sure where to report this, but the point is that after introducing a composition function developed with python, we noticed that:

This is negatively impacting both CI and DevEx since rendering a composition is quite a common use case.

How can we reproduce it?

I just tested this with a dummy function which does nothing:

    async def RunFunction(
        self, req: fnv1.RunFunctionRequest, _: grpc.aio.ServicerContext
    ) -> fnv1.RunFunctionResponse:
        """Run the function."""
        log = self.log.bind(tag=req.meta.tag)
        log.info("Running function and doing nothing")

        return response.to(req)

Running crossplane render on a composition that has this function as a dependency (not necessarily used in the pipeline, just declaring this as a dependency in crossplane.yaml is enough) adds an extra ~10s. A couple of experiments with simple compositions raise the amount of time for the render command from 1-2 seconds to 10-12 seconds.

I was suspecting that this could have something to do, and played by setting it to None but apparently didn't help :(

What environment did it happen in?

function-sdk-python version: 0.5.0 crank version v1.18.0

fernandezcuesta commented 1 week ago

Update: I verified that this doesn't happen with Crossplane <= v1.17.1, so both v1.17.2 and 1.18.0 are affected

negz commented 3 days ago

I can't imagine why the version of Crossplane would affect function startup/shutdown time. Given it's Python I wouldn't ever expect it to be as fast as a Go function, but 10s startup does seem like a lot.

Are your tests factoring in image pull time? xpkg.upbound.io/negz/function-auto-python:v0.1.0 and xpkg.upbound.io/crossplane-contrib/function-auto-ready:v0.3.0 do the same thing, but the Python function is roughly twice as large. They both use Distroless image bases, so I'm guessing the extra size is the Python interpreter and stdlib etc.