Kong / kong-python-pdk

Write Kong plugins in Python (Experimental)
Apache License 2.0
45 stars 14 forks source link

Increasing 60sec ttl on closing of plugin instance #29

Open abhisheksharma2805 opened 2 years ago

abhisheksharma2805 commented 2 years ago

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.

fffonion commented 2 years ago

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

abhisheksharma2805 commented 2 years ago

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.

abhisheksharma2805 commented 2 years ago

@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.

fffonion commented 2 years ago

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