Kong/kong-python-pdk

Increasing 60sec ttl on closing of plugin instance

abhisheksharma2805 opened this issue · 4 comments

I see there is 60 sec ttl on plugin instances, so if no requests are being send for 60 sec then supposedly the plugin instance will be closed. Is there a way to increase this ttl ?
My custom plugin is using some sort of internal lru cache which is being initialised in the plugin constructor. So if the plugin is closed that cache will also be reset and new instance will be created with empty cache.

self.cache = LRUCache(capacity=self.config['lru_cache_capacity'], max_age_seconds=self.config['lru_cache_max_age_seconds'])

Using the above cache in my access method before calling the database.

I understand this is not the best design and cache should be separated out from the plugin code. But currently I am stuck with this.

Hi @abhisheksharma2805 you can promote the cache to module layer, as Plugin instances are designed to be
volatile.

Hi @abhisheksharma2805 you can promote the cache to module layer, as Plugin instances are designed to be volatile.

@fffonion Can you please elaborate what do you mean by promoting the cache to module layer.

@fffonion For now I have figured out how to separate out cache from the plugin instances.
But I stumbled upon other issue related to 60 sec ttl condition.
I expected the plugin instance to be deleted after 60 sec of no usage (no requests being sent). But strangely this is not the case. Even after 10-15 mins I am seeing older instances only. No new instances were created.

@abhisheksharma2805 The 60s ttl behaviour is not currently used, it may change in the future though.