Hi,
Only batch API is using managed memory. If you are using streaming API, you can do two things:
- estimate max cache size based on for example fraction of max heap size
- use WeakReference to implement your cache
In batch API, you could estimate max cache size based on:
- fraction of (heapSize - managedMemorySize)
managedMemorySize you can obtain from for example:
getContainingTask().getEnvironment().getMemoryManager().getMemorySize();
But keep in mind, that any heap memory allocations in your code will contest for the same memory and as mentioned before, except of batch API, memory allocations are not accounted anywhere (because it difficult to calculate memory usage of a operator :( )
Piotrek
> On 20 Oct 2017, at 06:04, Navneeth Krishnan <
[hidden email]> wrote:
>
> Hello All,
>
> I have an in-memory cache created inside a user function and I need to assign the max capacity for it. Since the program can be run on any hardware, I'm thinking if I cloud assign based on flink's allocated managed memory.
>
> Is there a way to get the flink managed memory size inside a user function? If not are there any other options?
>
> Thanks,
> Navneeth