Hi Steven,

the finalize method in StreamTask acts as a safety net in case the services
of the StreamTask haven't been properly shut down. In the code, however, it
looks as if the TimerService, for example, is always being stopped in the
finally block of the invoke method. Thus, it might not be necessary to have
the finalize method as a safety net.

How did you kill the TaskManagers? I assume you didn't kill the JVM process
because otherwise you wouldn't see the finalizer objects piling up.

I think that you can create a JIRA issue for removing the finalizer method.

Cheers,
Till



On Thu, Sep 14, 2017 at 12:26 PM, Fabian Hueske <fhue...@gmail.com> wrote:

> Hi Steven,
>
> thanks for reporting this issue.
> Looping in Till who's more familiar with the task lifecycles.
>
> Thanks, Fabian
>
> 2017-09-12 7:08 GMT+02:00 Steven Wu <stevenz...@gmail.com>:
>
>> Hi ,
>>
>> I was using Chaos Monkey to test Flink's behavior against frequent
>> killing of task manager nodes. I found that stopped/disposed StreamTask got
>> retained by java finalizer. It is kind like a memory leak. Since each
>> StreamTask retains 2.6 MB memory. With 20 kills (and job restarts) for
>> 8-CPU container, there are 2.6 * 20 * 8 MB retained in heap.
>>
>> [image: Inline image 1]
>>
>> finalize() is generally not recommended for cleanup, because "*Finalizers
>> are unpredictable, often dangerous, and generally unnecessary*", quoted
>> from Joshua Bloch's book.
>> http://www.informit.com/articles/article.aspx?p=1216151&seqNum=7
>>
>> This code from StreamTask.java seems to be the cause. Is it necessary?
>> can it be removed? We are using flink-1.2 release branch. But I see the
>> same code in flink-1.3 and master branch
>>
>> /**
>> * The finalize method shuts down the timer. This is a fail-safe shutdown,
>> in case the original
>> * shutdown method was never called.
>> *
>> * <p>
>> * This should not be relied upon! It will cause shutdown to happen much
>> later than if manual
>> * shutdown is attempted, and cause threads to linger for longer than
>> needed.
>> */
>> @Override
>> protected void finalize() throws Throwable {
>> super.finalize();
>> if (timerService != null) {
>> if (!timerService.isTerminated()) {
>> LOG.info("Timer service is shutting down.");
>> timerService.shutdownService();
>> }
>> }
>>
>> cancelables.close();
>> }
>>
>> Thanks,
>> Steven
>>
>
>

Reply via email to