TheThingsNetwork / lorawan-stack

The Things Stack, an Open Source LoRaWAN Network Server
https://www.thethingsindustries.com/stack/
Apache License 2.0
980 stars 309 forks source link

Cache unwrapping keys to reduce load on key vault #36

Closed johanstokking closed 4 years ago

johanstokking commented 5 years ago

Summary:

Cache unwrapping keys to reduce load on key vault

What do you see now?

Unwrapping keys on-the-fly, also inside loops.

What do you want to see instead?

Keys should not be stored (long) in memory, but they can be cached briefly within the same function.


Original issue: https://github.com/TheThingsIndustries/lorawan-stack/issues/1218 by @johanstokking

johanstokking commented 4 years ago

Please coordinate

htdvisser commented 4 years ago

Please coordinate. I don't have time for this.

adriansmares commented 4 years ago

I'll pick this up.

adriansmares commented 4 years ago

I can see two possible implementations with this one:

I'm more in favor of 1, but any thoughts on this @johanstokking ?

johanstokking commented 4 years ago

A few things on the context;

That being said, I prefer option 1. Those units of work last typically in the order of seconds. With https://github.com/TheThingsNetwork/lorawan-stack/issues/2708, we might get a bulk of messages of a single device, so having a cache expiry of 5 to 10 seconds seems reasonable, but please add some Prometheus metrics on the cache (hit ratio, size). Having a fixed size, long (hour) TTL and an ARC cache (balancing LFU and LRU) can also be just fine.