question

LodayaMonica-5922 avatar image
0 Votes"
LodayaMonica-5922 asked AnuragSharma-MSFT commented

Azure Redis Cache - How to release memory of deleted keys?

Questions:
1. FLUSHALL deletes all the keys but memory used still remains same? How do I release memory used by flushed/purged/deleted keys?
2. I have a key with memory usage of 120 bytes. How much more memory is taken by the TTL of 3600 seconds for this key?
3. Do expired keys also not release memory? Or is it only deleted keys?
4. Premium P1 of 6GB with 1 Shard (2 nodes primary/replica) - Does this mean we have 3GB for read/writes and 3GB is replica? Is this configurable?

azure-cache-redis
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AnuragSharma-MSFT avatar image
0 Votes"
AnuragSharma-MSFT answered AnuragSharma-MSFT commented

Hi @LodayaMonica-5922, welcome to Microsoft Q&A forum.

Please find the answers to your queries below:

  1. FLUSHALL deletes all the keys but memory used still remains same? How do I release memory used by flushed/purged/deleted keys?
    Response: FLUSHALL will delete all the keys as well as free up the memory. To check it you can go to Console on your Azure Redis Cache and issue 'INFO' command and check the Memory segment. I tried adding the 3000 keys to Azure Redis Cache and after flushing the keys it released the memory:

Before using FLUSHALL:
113364-image.png

After using FLUSHALL:
113334-image.png

You can observe the difference here.

  1. I have a key with memory usage of 120 bytes. How much more memory is taken by the TTL of 3600 seconds for this key?
    Response: TTL will not add consume more memory, it will just add the time after which the key will be removed automatically and freeing up the memory. So in your specific case, it is still going to consume 120 bytes irrespective of TTL until key is deleted.

  2. Do expired keys also not release memory? Or is it only deleted keys?
    Response: Expired keys and delete keys both release memory. Only difference between them is Key Expiration automatically removes the keys based on timeout while in Key Deletion we manually have to delete the keys.

  3. Premium P1 of 6GB with 1 Shard (2 nodes primary/replica) - Does this mean we have 3GB for read/writes and 3GB is replica? Is this configurable?
    Response: 6 GB will belong individually to Master and replica. That means both will have 4 GB memory.

Please let me know if this helps or else we can discuss further.


If answer helps, please mark it 'Accept Answer'

















image.png (2.7 KiB)
image.png (2.7 KiB)
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

tThanks @AnuragSharma-MSFT for your response. This does help.

On #4 - Premium P1 of 6GB with 1 Shard (2 nodes primary/replica) - Does this mean we have 3GB for read/writes and 3GB is replica? Is this configurable?
Response: 6 GB will belong individually to Master and replica. That means both will have 4 GB memory.
You meant 6GB here, right?

On #1 - Maybe I need more help in understanding those numbers.

Here is my case:
INFO command - Used memory 121MB with 90 keys (all with ttl of 1 hr)
MEMORY STATS command - Bytes per key - 1375925
MEMORY USAGE <key> command - 118-128 bytes

If you look at the stats, memory usage of individual keys is around 120-130 bytes. But bytes per key (used memory/number of keys) is ~1.3MB which is incorrect.

After a day, I have similar number of keys (because of ttl of 1 hr) but used memory is now 146MB.

We have in the past manually inserted and deleted keys from cache.
Also, with ttl set if the number of keys always remains around 90, why is used memory increasing?
I executed Flushall command but used memory is still the same.

Here is the output from Memory stats and Info Memory.

!113327-image.png
113433-image.png


0 Votes 0 ·
image.png (240.5 KiB)
image.png (248.0 KiB)

Thanks for replying back.

Yes you are right there was a typo in point 4. I actually meant 6 GB.

I am checking point 1 with the details provided by you and will get back at the earliest.

0 Votes 0 ·

Hi @LodayaMonica-5922, thanks for your patience.

When we create Azure Redis Cache, by default the server allocated the memory (close to 100 MB for P1 premium). Any key that we add, it gets added on top of it, so if we add 10 MB keys, used memory will show 110 MB but in real key memory size is just 10 MBs. Now the commands MEMORY STATS will show the memory of keys plus the default memory allocated. While we go with MEMORY USAGE for key it will show the correct memory allocated key-wise.

Also, as you mentioned the after 24 hours, the used memory grew to 146 MB. Can you please once check if there is any more keys added or what were the number of keys before and after this increase in memory?

0 Votes 0 ·
Show more comments