Flagsmith/flagsmith-python-client

`enable_local_evaluation` and AWS Lambda

Closed this issue · 3 comments

When using enable_local_evaluation in a Lambda, it doesn't work as expected.

I think that the sleep() inside the polling thread run() method is paused when the Lambda finish executing a call.
So, if we put environment_refresh_interval_seconds=60 and we have a lambda executed every minute with a duration of 100 ms, I think – I didn't confirm – that the environment would only be refreshed after 600 minutes instead of the expected 1 minute...

Maybe the run() should be implemented using a timestamp comparison with datetime.now() instead of sleep()?

Local evaluation mode isnt really designed for a platform like Lambda where you don't have control over threads and overall process lifecycle. I'm not sure we would ever plan to do this? Thoughts @matthewelwell ?

After thinking about it, I'm not sure it would be good to have it for serverless platforms.
If the Lambda has only one virtual core, the busy wait could be problematic and it's the only way that I could think of to keep the advantage of the local evaluation mode, i.e., having the environment always ready without latency added by the calls to the API.
The only alternative would probably be to cache it, and take the cost of refreshing the cache at times.

Maybe the documentation could indicate that the local evaluation mode is not recommended for serverless?